Last active
May 26, 2022 12:26
-
-
Save JanPlazovnik/62ecfb9a248520ea88e7ec524f112753 to your computer and use it in GitHub Desktop.
A Tampermonkey script that removes any blacklisted courses from the page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Remove old classes from eŠtudij | |
// @author Jan Plazovnik | |
// @include https://estudij.um.si/ | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const allowedCourses = [ | |
"ALGORITMI V RAČUNALNIŠKI PRAKSI", | |
"OSNOVE RAČUNALNIŠKEGA VIDA", | |
"PROGRAMSKI JEZIKI", | |
"RAZVOJ APLIKACIJ ZA INTERNET", | |
"RAZVOJ PROGRAMSKIH SISTEMOV", | |
"SISTEMSKA ADMINISTRACIJA", | |
"MATEMATIKA I VS", | |
"DISKRETNA MATEMATIKA VS" | |
] | |
const getNodes = (className) => Array.from(document.getElementsByClassName(className)) | |
// Remove any courses that we don't want, in this case all courses that aren't whitelisted. | |
getNodes("aalink") | |
.filter(it => !allowedCourses.includes(it.textContent)) | |
.forEach(it => logAndDelete(it)) | |
// The site uses odd/even classes to make it more readable, this fixes that for the new list. | |
getNodes("coursebox") | |
.forEach((it, index) => { | |
if (index % 2 == 0) { | |
it.classList.remove("odd") | |
it.classList.add("even") | |
} else { | |
it.classList.remove("even") | |
it.classList.add("odd") | |
} | |
}) | |
function logAndDelete(item) { | |
const wrapper = item.closest(".coursebox") | |
const css = (color) => `display: inline-block; background-color: ${color}; color: #ffffff; font-weight: bold; padding: 3px 7px; border-radius: 4px;` | |
if (wrapper) { | |
console.log( | |
`%cCourseCleaner%c Removed course %c${item.textContent}`, | |
css("#e0005a"), | |
"display: inline-block; font-weight: bold; padding: 3px 7px;", | |
css("#ae39ff") | |
) | |
wrapper.remove() | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment