Last active
February 1, 2021 08:55
-
-
Save chhoumann/4f8a6c56838b04789060042d11e651de to your computer and use it in GitHub Desktop.
Makes the Moodle schedule bearable.
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 MoodleSchedule++ | |
// @namespace https://gist.github.com/chhoumann/4f8a6c56838b04789060042d11e651de | |
// @version 0.1 | |
// @description Automatically goes to semester page and removes past weeks. | |
// @author Christian B. B. Houmann | |
// @match www.moodle.aau.dk/local/planning/calendar.php?fid=* | |
// @grant none | |
// ==/UserScript== | |
window.addEventListener('load', function() { | |
ClickSemesterButton(); | |
TogglePastWeeks(Toggle.hide); | |
AddShowPastWeeksButton(); | |
}, false); | |
let pastWeeks; | |
let pastWeeksShown; | |
const Toggle = { | |
show: true, | |
hide: false | |
} | |
function ClickSemesterButton() { | |
document.querySelector(".fc-dayGridSemester-button").click(); | |
} | |
function TogglePastWeeks(bToggle) { | |
const WEEK_CLASS = ".fc-week"; | |
let allWeeks = document.querySelectorAll(WEEK_CLASS); | |
pastWeeks = FindPastWeeks(allWeeks); | |
pastWeeks.forEach(week => bToggle ? week.classList.remove("hidden") : week.classList.add("hidden")); | |
pastWeeksShown = bToggle; | |
} | |
function FindPastWeeks(allWeeks) { | |
const DAYS_IN_WEEK = 5; | |
const PAST_CLASS_NAME = "fc-past"; | |
let pastWeeks = []; | |
allWeeks.forEach(week => { | |
// Traversing from week div -> div -> table -> tbody -> tr to get array of td | |
let days = week.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes; | |
let pastDayCounter = 0; | |
days.forEach(day => { | |
if (day.classList.contains(PAST_CLASS_NAME)) { | |
pastDayCounter++; | |
} | |
}); | |
if (pastDayCounter >= DAYS_IN_WEEK) { | |
pastWeeks.push(week); | |
} | |
}); | |
return pastWeeks; | |
} | |
function AddShowPastWeeksButton() { | |
const fcRight = document.querySelector(".fc-right"); | |
const MOODLE_BUTTON_CLASSES = "fc-today-button fc-button fc-button-primary"; | |
const showPastWeeksButton = document.createElement("button"); | |
showPastWeeksButton.classList = MOODLE_BUTTON_CLASSES; | |
showPastWeeksButton.innerText = "Toggle past weeks"; | |
showPastWeeksButton.addEventListener("click", () => { | |
TogglePastWeeks(pastWeeksShown ? Toggle.hide : Toggle.show); | |
}) | |
fcRight.appendChild(showPastWeeksButton); | |
} |
Added a toggle button to show or hide past weeks.
Updated code for 1. refactoring and 2. more persistence in hiding columns.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
This is how you use this userscript.
First, you'll have to get an extension to handle it. I personally use Tampermonkey.
Once you've installed an extension that handles userscripts, simply add a new script and paste in the code in the Gist.
FEATURES