Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers
Created March 19, 2019 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PieterScheffers/aef9d310bf59583fa834df50263f964b to your computer and use it in GitHub Desktop.
Save PieterScheffers/aef9d310bf59583fa834df50263f964b to your computer and use it in GitHub Desktop.
Trello add a list for each weekday
// Trello
// Add a List for each weekday
// Pass throught https://skalman.github.io/UglifyJS-online/
// Then add 'javascript:' before the code
// and add 'void(0);' after the code
// Add a bookmark in Chrome and put this as the url
(function () {
function getLastDate (lastDate = null) {
if (lastDate) return lastDate;
const headers = document.getElementsByClassName('list-header-name-assist');
const lastHeader = headers.length ? headers[headers.length - 1] : null;
if (lastHeader) {
const lastHeaderParts = lastHeader.textContent.split(' ')
const dateRegexp = /^([0-9]{2})-([0-9]{2})-([0-9]{4})$/;
if (lastHeaderParts.length >= 2 && dateRegexp.test(lastHeaderParts[1])) {
const [ , day, month, year ] = dateRegexp.exec(lastHeaderParts[1]);
return new Date(year, month - 1, day);
}
}
return new Date();
}
const isWeekend = date => [ 0, 6 ].includes(date.getDay());
const getNextDay = date => new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
const padZero2 = n => (n + '').padStart(2, 0);
function addDate (lastDate = null) {
lastDate = getLastDate(lastDate);
const date = getNextDay(lastDate);
if (!isWeekend(date)) {
const weekdays = [
'Zondag',
'Maandag',
'Dinsdag',
'Woensdag',
'Donderdag',
'Vrijdag',
'Zaterdag'
];
const input = document.getElementsByClassName('list-name-input')[0];
input.value = `${weekdays[date.getDay()]} ${padZero2(date.getDate())}-${padZero2(date.getMonth() + 1)}-${date.getFullYear()}`;
const button = document.getElementsByClassName('mod-list-add-button')[0];
button.click();
}
return date;
}
const addWeek = () => {
let date = null;
for (let i = 0; i < 7; i++) {
date = addDate(date);
}
}
addWeek();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment