Manaba Time Modifier

Replace 0:00 times with previous day 24:00 and make them bold on manaba.tsukuba.ac.jp

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

// ==UserScript==
// @name         Manaba Time Modifier
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Replace 0:00 times with previous day 24:00 and make them bold on manaba.tsukuba.ac.jp
// @author       You
// @match        https://manaba.tsukuba.ac.jp/ct/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function modifyTimes() {
        // Get all text nodes in the document
        const walker = document.createTreeWalker(
            document.body,
            NodeFilter.SHOW_TEXT,
            null,
            false
        );

        const textNodes = [];
        let node;
        while (node = walker.nextNode()) {
            textNodes.push(node);
        }

        // Regex to match dates with times of 0:00
        const timeRegex = /(\d{4})-(\d{2})-(\d{2})\s+0:00/g;

        textNodes.forEach(textNode => {
            if (timeRegex.test(textNode.textContent)) {
                const parent = textNode.parentNode;
                const content = textNode.textContent;
                
                // Replace 0:00 with previous day 24:00
                const newContent = content.replace(timeRegex, (match, year, month, day) => {
                    // Create date object and subtract one day
                    const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
                    date.setDate(date.getDate() - 1);
                    
                    // Format previous day
                    const prevYear = date.getFullYear();
                    const prevMonth = String(date.getMonth() + 1).padStart(2, '0');
                    const prevDay = String(date.getDate()).padStart(2, '0');
                    
                    return `${prevYear}-${prevMonth}-${prevDay} 24:00`;
                });

                if (newContent !== content) {
                    // Create a span element to hold the modified content
                    const span = document.createElement('span');
                    
                    // Split content and make the time part bold
                    const modifiedHTML = newContent.replace(/(\d{4}-\d{2}-\d{2}\s+24:00)/g, '<strong>$1</strong>');
                    span.innerHTML = modifiedHTML;
                    
                    // Replace the text node with the new span
                    parent.replaceChild(span, textNode);
                }
            }
        });
    }

    // Run the modification when the page loads
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', modifyTimes);
    } else {
        modifyTimes();
    }

    // Also run when new content is dynamically loaded
    const observer = new MutationObserver((mutations) => {
        let shouldCheck = false;
        mutations.forEach((mutation) => {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                shouldCheck = true;
            }
        });
        if (shouldCheck) {
            setTimeout(modifyTimes, 100);
        }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();