RWTH Online Colorcoded Calendar

Fix RWTH Online Calendar Date Coloring

2019/04/06のページです。最新版はこちら。

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         RWTH Online Colorcoded Calendar
// @namespace    https://github.com/Seneral/
// @version      1.oo D
// @description  Fix RWTH Online Calendar Date Coloring
// @author       Me
// @match        https://online.rwth-aachen.de/RWTHonline/*
// @grant        none
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    if(!window.location.href.includes ("wbKalender.wbPerson")) return;

    var showOnlyCalendar = true;
    var markUnmodifiedEvents = true;

    // "col" : color applied to matching events
    // "opc" : opacity of WHOLE event
    // "in" : included in description
    // "ex" : excluded from description
    // "name" : included in name
    // "days" : List of days included - "1,2,4,5" for all but Wednesday, none for all days
    // All colors from the settings / css are valid - red, blue, green, yellow, aquamarine, etc.

    var colorMap = [

        // FoSAP
        { "opc": 1.0, "col" : "red",        "in" : "Abhaltung; Übung;",     "name" : "Formale Systeme", "days" : "4" },    // FoSAP Lecture Thursday
        { "opc": 1.0, "col" : "red",        "in" : "Abhaltung; Vorlesung;", "name" : "Formale Systeme", "days" : "1" },    // FoSAP Lecture Monday
        { "opc": 1.0, "col" : "orange",     "in" : "Abhaltung; Vorlesung;", "name" : "Formale Systeme", "days" : "3" },    // FoSAP Global Wednesday
        { "opc": 0.8, "col" : "aquamarine", "in" : "Abhaltung; Tutorium;",  "name" : "Formale Systeme" },                  // FoSAP Tutorium

        // DsAl
        { "opc": 1.0, "col" : "red",        "in" : "Abhaltung; Vorlesung;", "name" : "Datenstrukturen" },                  // DsAl Lectures
        { "opc": 1.0, "col" : "orange",     "in" : "Abhaltung; Übung;"    , "name" : "Datenstrukturen" },                  // DsAL Global
        { "opc": 0.8, "col" : "wheat",      "in" : "Abhaltung; Tutorium;",  "name" : "Datenstrukturen" },                  // DsAL Tutorium

        // BuS
        { "opc": 1.0, "col" : "red",        "in" : "Abhaltung; Vorlesung;", "name" : "Betriebssysteme" },                  // BuS Lectures
        { "opc": 1.0, "col" : "orange",     "in" : "Abhaltung; Übung;",     "name" : "Betriebssysteme" },                  // BuS Global
        { "opc": 0.8, "col" : "orchid",     "in" : "Abhaltung; Tutorium;",  "name" : "Betriebssysteme" },                  // Bus Tutorium

        // LA
        { "opc": 1.0, "col" : "red",        "in" : "Abhaltung; Vorlesung;", "name" : "Lineare Algebra" },                  // LA Lectures
        { "opc": 1.0, "col" : "orange",     "in" : "Abhaltung; Tutorium;",  "name" : "Lineare Algebra" },                  // LA Global
        { "opc": 0.8, "col" : "gray",       "in" : "Abhaltung; Übung;",     "name" : "Lineare Algebra" },                  // LA Tutorium

        // Stochastik
        { "opc": 1.0, "col" : "red",        "in" : "Abhaltung; Vorlesung;", "name" : "Stochastik" },                       // Stochastik Lecture
        { "opc": 1.0, "col" : "orange",     "in" : "Abhaltung; Übung;",     "name" : "Stochastik" },                       // Stochastik Global
    ]

    function handleEventColor(event){
        var weekContainer = event.parentNode.parentNode.parentNode.parentNode;
        var dayContainer = event.parentNode.parentNode.parentNode;
        var dayOfWeek = Array.prototype.slice.call(weekContainer.children).indexOf(dayContainer); // 1 Mon

        var colorBar = event.children[0];
        var colorBox = event.children[1];
        var name = event.children[1].children[0].children[2].innerText;
        var desc = event.children[1].children[1].children[0].innerText;

        var color = undefined;
        var opacity = 1;
        for (var i = 0; i < colorMap.length; i++)
        {
            var rules = colorMap[i];
            var inc  = !rules.in   ||  desc.includes (rules.in);
            var exc  = !rules.ex   || !desc.includes (rules.ex);
            var nm   = !rules.name ||  name.includes (rules.name);
            var day  = !rules.days ||  rules.days.includes (dayOfWeek.toString());
            if (inc && exc && nm && day)
            {
                color = rules.col;
                opacity = rules.opc;
                break;
            }
        }

        if (color)
        {
            event.style.opacity = opacity;
            colorBox.className = colorBox.className.replace(/\b(cocal\-skin\-)([a-zA-Z-]+)\b/g, "") + "cocal-skin-" + color;
        }
        else if (markUnmodifiedEvents)
        {
            event.style.border = "3px solid black";
            event.style.boxSizing = "border-box";
            event.style.MozBoxSizing = "border-box";
        }
    }

    function updateCalendar(){
        if (showOnlyCalendar)
        { // Only execute when not yet successful once
            var header = document.getElementsByTagName("ca-header");
            var footer = document.getElementsByTagName("ca-footer");
            if (header.length != 0 && footer.length != 0)
            {
                header[0].style.display = "none";
                footer[0].style.display = "none";
                showOnlyCalendar = false;
            }
        }

        var calendarFrame = document.getElementById("idIframe");
        if (!calendarFrame) return;
        var events = calendarFrame.contentWindow.document.body.querySelectorAll("[id^='idTermin_']");
        for(var i=0 ; i < events.length ; i++)
        {
            handleEventColor(events[i]);
        }
    }

    // Execute every seconds in case new content has been added to the page
    setInterval(updateCalendar, 200);
})();