30 lines
1.4 KiB
JavaScript
30 lines
1.4 KiB
JavaScript
(() => {
|
|
const start = document.querySelector('[data-author-start-date]');
|
|
const now = new Date();
|
|
const date = [now.getFullYear(), now.getMonth() + 1, now.getDate()]
|
|
.map(part => String(part).padStart(2, '0')).join('-');
|
|
const today = document.querySelector('[data-writer-today]');
|
|
const allocation = document.querySelector(`[data-writer-allocation-date="${date}"]`);
|
|
if (today && allocation) {
|
|
today.textContent = `${allocation.dataset.writerAllocationMinutes} minutes planned for today.`;
|
|
const suggestedWords = Number(allocation.dataset.writerSuggestedWords);
|
|
if (suggestedWords > 0) today.textContent += ` About ${suggestedWords.toLocaleString()} draft words at your target pace.`;
|
|
today.hidden = false;
|
|
}
|
|
|
|
if (!start) return;
|
|
const offset = start.form.querySelector('[data-author-utc-offset]');
|
|
if (offset) {
|
|
offset.value = -now.getTimezoneOffset();
|
|
start.min = date;
|
|
}
|
|
if (!start.value || start.dataset.defaultLocal === 'true') start.value = date;
|
|
|
|
const deadline = start.form.querySelector('[data-author-target-date]');
|
|
if (deadline?.dataset.defaultLocal === 'true') {
|
|
now.setMonth(now.getMonth() + 1);
|
|
deadline.value = [now.getFullYear(), now.getMonth() + 1, now.getDate()]
|
|
.map(part => String(part).padStart(2, '0')).join('-');
|
|
}
|
|
})();
|