MediaWiki:EthTime.js: Difference between revisions

From Thorildsby Wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
Undo revision 1311 by Kat (talk)
Tag: Undo
 
Line 1: Line 1:
//These code comments are not from AI, they are just result of my procrastination
$(function () {
//Use dollar sign to invoke jQueury
     var ethTimeDiv = document.getElementById('eth-time');
$(function () { //Anonymous function that gets executed on every page load
     var ethTimeLinkedDiv = document.getElementById('eth-time-linked');
     var ethTimeDiv = document.getElementById('eth-time'); //Get the HTML element with the id 'eth-time' and store it’s reference in ethTimeDive. This might not exist though.
     const now = new Date();
     var ethTimeLinkedDiv = document.getElementById('eth-time-linked'); //Get the HTML element with the id 'eth-time-linked' and store it’s reference in ethTimeLinkedDiv. This one might not exist aswell.
     const year = now.getUTCFullYear();
     const now = new Date(); //Acquire the current time and store it in now
     const year = now.getUTCFullYear(); //Get the current year in UTC time as a number


     var result = year - 2000; //Subtract 2000 from the current year and store it in result
     var result = year - 2000;
     var decimal = Math.ceil((now - new Date(year,0,1)) / 86400000); //Use some black magic I found on https://www.epochconverter.com/daynumbers to generate the current day of the year and store it in decimal
     var decimal = Math.ceil((now - new Date(year,0,1)) / 86400000);


     decimal = decimal/((year % 4 == 0 && year % 100 != 0) || year % 400 == 0? 366 : 365); //Divide the current day of the year by the number of days in a year and store it back into decimal. A ternary operation with some division and modulo operations within is used to determine wether the current year is a leap year or not.
     decimal = decimal/((year % 4 == 0 && year % 100 != 0) || year % 400 == 0? 366 : 365);


     result += decimal; //Add the new decimal to the result
     result += decimal;
     result *= 100; //Multiply the result by one hundred
     result *= 100;
     result = Math.round(result); //Round the result
     result = Math.round(result);
     result /= 100; //Divide the result by one hundred. We have thus rounded by two decimal places.
     result /= 100;


     try { //try statement for the existence of an HTML element with the id 'eth-time'
     try {
         if (ethTimeDiv.innerHTML != null) ethTimeDiv.innerHTML = result + "Ð"; //Replace the inside of the HTML element with the id 'eth-time' with the calculated result followed by the character Ð.
         if (ethTimeDiv.innerHTML != null) ethTimeDiv.innerHTML = result + "Ð";
     }  
     }  
     catch (error) { //Catch if an HTML element with the id 'eth-time' does not exist
     catch (error) {
       //lol  
       //lol  
     }
     }
     try { //try statement for the existence of an HTML element with the id 'eth-time-linked'
     try {
         if (ethTimeLinkedDiv.innerHTML != null) ethTimeLinkedDiv.innerHTML = result +
         if (ethTimeLinkedDiv.innerHTML != null) ethTimeLinkedDiv.innerHTML = result +  
             "<a href=\"https://thorildsby.com/index.php?title=%C4%90-Time\">Ð</a>"; //replace the inside of the HTML element with the id 'eth-time-linked' with the calculated result followed by a hyperlink reference to the Thorildsby wiki article for Ð-Time which contains the letter Ð
             "<a href=\"https://thorildsby.com/index.php?title=%C4%90-Time\">Ð</a>";
     }
     }
     catch (error) { //Catch if an HTML element with the id 'eth-time-linked' doesn’t exist
     catch (error) {
         //lol again
         //lol again
     }
     }
}()); //End the anonymous function and immediately call it
}());

Latest revision as of 09:32, 15 October 2025

$(function () {
    var ethTimeDiv = document.getElementById('eth-time');
    var ethTimeLinkedDiv = document.getElementById('eth-time-linked');
    const now = new Date();
    const year = now.getUTCFullYear();

    var result = year - 2000;
    var decimal = Math.ceil((now - new Date(year,0,1)) / 86400000);

    decimal = decimal/((year % 4 == 0 && year % 100 != 0) || year % 400 == 0? 366 : 365);

    result += decimal;
    result *= 100;
    result = Math.round(result);
    result /= 100;

    try {
        if (ethTimeDiv.innerHTML != null) ethTimeDiv.innerHTML = result + "Ð";
    } 
    catch (error) {
       //lol 
    }
    try {
        if (ethTimeLinkedDiv.innerHTML != null) ethTimeLinkedDiv.innerHTML = result + 
            "<a href=\"https://thorildsby.com/index.php?title=%C4%90-Time\">Ð</a>";
    }
    catch (error) {
        //lol again
    }
}());