|
// ==UserScript== |
|
// @name USOS timetable day date adder + format fixer |
|
// @description A script that adds dates to individual days in the USOS timetable + fixes formatting of the 2 dates on top. |
|
// @version 1.2.0 |
|
// @author Eryk Darnowski (GH: ErykDarnowski TW: @erykdarnowski) |
|
// @match *://usosweb.ansb.pl/kontroler.php?_action=home/plan* |
|
// @match *://usosweb.ansb.pl/kontroler.php?_action=katalog2/przedmioty/* |
|
// @match *://usosweb.ansb.pl/kontroler.php?_action=katalog2%2Fprzedmioty* |
|
// @run-at document-idle |
|
// @grant none |
|
// @namespace https://gist.github.com/ErykDarnowski/a0566eaa2ed6aab400a6b6ec7355fde0 |
|
// @supportURL https://gist.github.com/ErykDarnowski/a0566eaa2ed6aab400a6b6ec7355fde0 |
|
// @updateURL https://gist.githubusercontent.com/ErykDarnowski/a0566eaa2ed6aab400a6b6ec7355fde0/raw/b8f8d22c7ac6b404a7281223a532771e5bb726b6/script.js |
|
// @downloadURL https://gist.githubusercontent.com/ErykDarnowski/a0566eaa2ed6aab400a6b6ec7355fde0/raw/b8f8d22c7ac6b404a7281223a532771e5bb726b6/script.js |
|
// ==/UserScript== |
|
|
|
/* Releases |
|
- 1.0.0 Initial |
|
- 1.0.1 Fix lack of `@match` for the universal timetable page |
|
- 1.1.0 Add current day highlight |
|
- 1.1.1 Fix curr day highlight not working when date starts with `0` (e.g. `05.12.2023`) |
|
- 1.2.0 Update to work with updated UI (20.02.2024) |
|
*/ |
|
|
|
(() => { |
|
"use strict"; |
|
|
|
const headers = document.querySelectorAll('#layout-c22 > div > div.timetable-wrapper > div.autoscroll > table > tbody > tr:nth-child(1) > th'); |
|
const datesEl = document.querySelector('div.flex.gap05.selected_week > b'); |
|
const dateStrs = datesEl.textContent.split(' - '); |
|
const startDate = new Date(dateStrs[0]); |
|
const localeConfig = { |
|
day: '2-digit', |
|
month: '2-digit', |
|
year: 'numeric', |
|
}; |
|
|
|
// <https://stackoverflow.com/questions/563406/how-to-add-days-to-date> |
|
Date.prototype.addDays = function(days) { |
|
const date = new Date(this.valueOf()); |
|
date.setDate(date.getDate() + days); |
|
return date; |
|
}; |
|
|
|
|
|
// fix top dates formatting |
|
datesEl.textContent = dateStrs.map(x => new Date(x).toLocaleDateString(undefined, localeConfig)).join(' - '); |
|
|
|
// add dates to headers (individual days) |
|
for (let i = 0; i < headers.length; i++) { |
|
const header = headers[i]; |
|
const dayDate = startDate.addDays(i).toLocaleDateString(undefined, localeConfig); |
|
|
|
header.innerHTML = header.textContent + `<br><span style="color: var(--font-color-reverse); font-weight: 800;">(${dayDate})</span>`; |
|
|
|
// adding border to curr day |
|
(new Date().toLocaleDateString(undefined, localeConfig) === dayDate) && (headers[i].style.border = '3px solid red'); |
|
}; |
|
})(); |