Skip to content

Instantly share code, notes, and snippets.

@ErykDarnowski
Last active October 28, 2024 20:21
Show Gist options
  • Save ErykDarnowski/280ec2bedbeed7a19325e7627838b851 to your computer and use it in GitHub Desktop.
Save ErykDarnowski/280ec2bedbeed7a19325e7627838b851 to your computer and use it in GitHub Desktop.
USOS timetable block time calculator

USOS timetable block time calculator [Userscript]

A script that adds time of block next to it's start / end times in the timetable.

Instructions

  1. Install a Userscript browser extension

*It should work fine with most extensions (if not, write a comment)
2. Add the script

Tampermonkey
  1. Click on the extension icon (in the top right corner of the browser - you may have to click the puzzle icon first to see it)
  2. Click Control panel
  3. Click Utilities
  4. At the bottom in to Import from URL paste in this URL: https://gist.githubusercontent.com/ErykDarnowski/470bbbb14f6beb8de1b2c8ec18b9c906/raw/3f58dbf12dcf9e7caa42161f782c8d939eba52fe/script.js
  5. Click Install
  6. Click Install again
Violentmonkey
  1. Click on the extension icon (in the top right corner of the browser - you may have to click the puzzle icon first to see it)
  2. Click the cog icon
  3. Click +
  4. Click Install from URL
  5. Paste in this URL: <>
  6. Click Confirm
  7. Click Close

*The script should auto update!
*Remember, you can turn the script ON / OFF whenever you like by just flipping the switch next to it's name

// ==UserScript==
// @name USOS timetable block time calculator
// @description A script that adds time of block next to it's start / end times in the timetable.
// @version 1.0.1
// @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/280ec2bedbeed7a19325e7627838b851
// @supportURL https://gist.github.com/ErykDarnowski/280ec2bedbeed7a19325e7627838b851
// @updateURL https://gist.githubusercontent.com/ErykDarnowski/280ec2bedbeed7a19325e7627838b851/raw/a0d99c943e319aca41c9c352f58a9aa0db5f9cf5/script.js
// @downloadURL https://gist.githubusercontent.com/ErykDarnowski/280ec2bedbeed7a19325e7627838b851/raw/a0d99c943e319aca41c9c352f58a9aa0db5f9cf5/script.js
// ==/UserScript==
/* Releases
- 1.0.0 Initial
- 1.0.1 Add `use strict`
*/
(() => {
"use strict";
const elArr = [...document.querySelectorAll("table > tbody > tr > td > span")];
const timeStrToMins = (timeStr) => {
let hours, minutes;
[hours, minutes] = timeStr.split(':');
return +hours * 60 + +minutes;
};
elArr.map(x => {
const timeStr = x.textContent;
if (timeStr.includes('-')) {
const timeStrArr = timeStr.split(', ')[0].split('-');
const mins = timeStrToMins(timeStrArr[1]) - timeStrToMins(timeStrArr[0]);
x.innerHTML = x.textContent.replace(", ", ` <span style="font-weight: 900; color: darkviolet;">(${new Date(mins * 60 * 1000).toISOString().substr(12, 4)})</span>, `);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment