Skip to content

Instantly share code, notes, and snippets.

@DannyFeliz
Last active February 8, 2024 05:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannyFeliz/579081367fc73a6c6fee814eea676cd9 to your computer and use it in GitHub Desktop.
Save DannyFeliz/579081367fc73a6c6fee814eea676cd9 to your computer and use it in GitHub Desktop.
function getCards() {
const currentDate = new Date();
const month = currentDate.getMonth() + 1;
const formattedMonth = month < 10 ? `0${month}` : month;
const thisMonth = `${currentDate.getFullYear()}-${formattedMonth}`;
const cards = document.querySelectorAll(
`[name="tempoAllocationCard"][data-date^="${thisMonth}"]`
);
return cards;
}
const TOTAL_CARDS_PER_WEEK = 5;
const description = () => document.querySelector('#commentField');
const whatWillYouDoTomorrow = () => document.querySelector(
'#_Whatwillyoudotomorrow_'
);
const blokers = () => document.querySelector('#_Blockers_');
const logTimeBtn = () => document.querySelector('#logTimeBtn');
const nextBtn = () => document.querySelector("[data-testid='navigateForward']");
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function setText(element, value) {
const { set: valueSetter } =
Object.getOwnPropertyDescriptor(element, 'value') || {};
const prototype = Object.getPrototypeOf(element);
const { set: prototypeValueSetter } =
Object.getOwnPropertyDescriptor(prototype, 'value') || {};
if (prototypeValueSetter && valueSetter !== prototypeValueSetter) {
prototypeValueSetter.call(element, value);
} else if (valueSetter) {
valueSetter.call(element, value);
} else {
throw new Error('The given element does not have a value setter');
}
element.dispatchEvent(new Event('input', { bubbles: true }));
}
async function fillHours (goToNextPage = true) {
for (const card of getCards()) {
await fillCard(card);
}
if (!goToNextPage) {
return;
}
nextBtn().click();
await delay(1000);
const shouldGoToNextPage = getCards().length === TOTAL_CARDS_PER_WEEK;
fillHours(shouldGoToNextPage);
}
function fillCard(card) {
return new Promise((resolve, reject) => {
setTimeout(async () => {
card.click();
await delay(400);
setText(description(), "TBD");
setText(whatWillYouDoTomorrow(), "TBD");
setText(blokers(), "No");
logTimeBtn().click();
await delay(1000);
resolve();
}, 1000);
});
}
fillHours()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment