MyKCL Enhancement Suite

Enhancement Suite for the MyKCL website

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         MyKCL Enhancement Suite
// @namespace    http://com.marsharbour.modulehider
// @version      1.0
// @license MIT
// @description  Enhancement Suite for the MyKCL website
// @match        https://mykcl.kcl.ac.uk/urd/sits.urd/run/*
// @match        https://mykcl.kcl.ac.uk/urd/sits.urd/run/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Check if the current page has the title "Results Page"
    function isResultsPage() {
        return document.title.includes('View Module Results');
    }

    function addModuleHider() {
        // CSS Stylesheet
        const cssStyles = `
            table.gridtext.collapsed:not(.alignleft) tr:not(.modulerow) {
                display: none;
            }
        `;

        // Create the style element
        const styleElement = document.createElement('style');
        styleElement.innerHTML = cssStyles;
        document.head.appendChild(styleElement);
        styleElement.disabled = true;

        // Create the toggle button
        const toggleButton = document.createElement('button');
        toggleButton.textContent = 'Toggle Module Rows';

        // Find the <p> element with the ID "title"
        const titleElement = document.getElementById('title');

        if (titleElement) {
            // Append the toggle button to the after the title
            if (titleElement.nextElementSibling) {
                titleElement.parentNode.insertBefore(toggleButton, titleElement.nextElementSibling);
            } else {
                titleElement.parentNode.appendChild(toggleButton);
            }
        } else {
            // If the <p> element with the ID "title" is not found, append the toggle button to the body
            document.body.appendChild(toggleButton);
        }

        // Toggle the style element on button click
        toggleButton.addEventListener('click', function() {
            styleElement.disabled = !styleElement.disabled;
        });
    }

    // Add the style element and toggle button if on the results page
    function resultsPage() {
        addModuleHider()
    }

    function applyTweaks() {
        if (isResultsPage()) {
            resultsPage();
        }
    }

    applyTweaks()
})();