BotB: Show full dates when hovering over countdowns

Show full dates when hovering over countdowns

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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.

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

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

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.

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

// ==UserScript==
// @name         BotB: Show full dates when hovering over countdowns
// @namespace    https://battleofthebits.com/barracks/Profile/uart/
// @version      2024-08-30
// @description  Show full dates when hovering over countdowns
// @author       uart @ botb
// @license      CC0
// @match        *://battleofthebits.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=battleofthebits.com
// @grant        none
// @run-at       document-body
// ==/UserScript==

(function() {
    'use strict';

    /* LOCALE: override locale to use for date formatting. Leave empty for system locale. */
    const LOCALE = "pl-PL";

    function handleCountdownDates(root) {
        const now = new Date();

        const countdowns = root.getElementsByClassName("countdown");
        var countdownHTML, countdownSeconds, countdownDate;

        for (var i = 0; i < countdowns.length; i++) {
            countdownHTML = countdowns[i];
            countdownSeconds = countdownHTML.getAttribute("data-countdown");
            countdownDate = new Date(now.getTime() + (countdownSeconds * 1000));
            if (LOCALE) {
                countdownHTML.setAttribute("title", countdownDate.toLocaleString(LOCALE));
            } else {
                countdownHTML.setAttribute("title", countdownDate.toLocaleString());
            }
        }
    }

    handleCountdownDates(document);

    /* Set up a MutationObserver on ajaxContent in case it gets updated with new countdowns
     * (see e.g. user buttons on homepage). */
    const observer = new MutationObserver(function(mutationList, observer) {
        var done = new Array();
        for (const mutation of mutationList) {
            if (!done.includes(mutation.target)) {
                handleCountdownDates(mutation.target);
                done.push(mutation.target);
            }
        };
    });

    const ajaxContents = document.getElementsByClassName("ajaxContent");

    for (var i = 0; i < ajaxContents.length; i++) {
        observer.observe(ajaxContents[i], { childList: true, subtree: true });
    }
})();