Last active
June 27, 2023 14:32
-
-
Save Gaspadlo/9f283e7e63362901ce7207fe8675b88f to your computer and use it in GitHub Desktop.
Toggle Track week overview logs ceiling rounder - rounds dangling seconds to full minutes (JS bookmarklet script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: window.sleepFn = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
window.processingLog = false; | |
window.processedLogs = 0; | |
clearInterval(window.roundingInterval); | |
window.visibleTogglEvents = Array.from(document.querySelectorAll(".rbc-event")); | |
window.visibleTogglEventsCount = window.visibleTogglEvents.length; | |
window.roundingInterval = setInterval(async () => { | |
if (window.processingLog) { | |
return; | |
} | |
if (!window.visibleTogglEvents?.length) { | |
clearInterval(window.roundingInterval); | |
alert(`Processed ${window.visibleTogglEventsCount} logs. Altered: ${window.processedLogs} logs.`); | |
return; | |
} | |
window.processingLog = true; | |
const currentEvent = window.visibleTogglEvents.pop(); | |
const timeString = String(currentEvent?.querySelector?.("[class*=\"-Duration\"] ")?.innerText); | |
if (timeString.split(":")?.[2] !== "00") { | |
currentEvent?.click?.(); | |
await window.sleepFn(5); | |
const popup = document.querySelector("[data-popper-placement][tabindex=\"-1\"] "); | |
const durationInput = popup.querySelector("[name=\"duration\"] "); | |
const timeLog = durationInput.value.split(":"); | |
if (timeLog?.length === 3 && timeLog[2] !== "00") { | |
const addHour = String(timeLog[1]) === "59" ? 1 : 0; | |
await window.sleepFn(10); | |
durationInput.focus(); | |
durationInput.value = `${Number(timeLog[0]) + addHour}:${addHour ? "00" : String(Number(timeLog[1]) + 1).padStart(2, "0")}:00`; | |
await window.sleepFn(5); | |
durationInput.blur(); | |
await window.sleepFn(5); | |
popup?.querySelector?.("button[class*=\"PrimaryButton\"] ")?.click?.(); | |
window.processedLogs += 1; | |
await window.sleepFn(100); | |
} else { | |
popup?.querySelector("[class*=\"CloseButton\"] ")?.click?.(); | |
} | |
} | |
window.processingLog = false; | |
}, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment