MediaWiki:EthTime.js: Difference between revisions

From Thorildsby Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
$(function () {
//These code comments are not from AI, they are just result of my procrastination
     var ethTimeDiv = document.getElementById('eth-time');
//Use dollar sign to invoke jQueury
     var ethTimeLinkedDiv = document.getElementById('eth-time-linked');
$(function () { //Anonymous function that gets executed on every page load
     const now = new Date();
     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 year = now.getUTCFullYear();
     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 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;
     var result = year - 2000; //Subtract 2000 from the current year and store it in result
     var decimal = Math.ceil((now - new Date(year,0,1)) / 86400000);
     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


     decimal = decimal/((year % 4 == 0 && year % 100 != 0) || year % 400 == 0? 366 : 365);
     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.


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


     try {
     try { //try statement for the existence of an HTML element with the id 'eth-time'
         if (ethTimeDiv.innerHTML != null) ethTimeDiv.innerHTML = result + "Ð";
         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 Ð.
     }  
     }  
     catch (error) {
     catch (error) { //Catch if an HTML element with the id 'eth-time' does not exist
       //lol  
       //lol  
     }
     }
     try {
     try { //try statement for the existence of an HTML element with the id 'eth-time-linked'
         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>";
             "<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 Ð
     }
     }
     catch (error) {
     catch (error) { //Catch if an HTML element with the id 'eth-time-linked' doesn’t exist
         //lol again
         //lol again
     }
     }
}());
}()); //End the anonymous function and immediately call it

Revision as of 10:35, 14 October 2025

//These code comments are not from AI, they are just result of my procrastination
//Use dollar sign to invoke jQueury
$(function () { //Anonymous function that gets executed on every page load
    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.
    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 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 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

    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.

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

    try { //try statement for the existence of an HTML element with the id 'eth-time'
        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 Ð.
    } 
    catch (error) { //Catch if an HTML element with the id 'eth-time' does not exist
       //lol 
    }
    try { //try statement for the existence of an HTML element with the id 'eth-time-linked'
        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 Ð
    }
    catch (error) { //Catch if an HTML element with the id 'eth-time-linked' doesn’t exist
        //lol again
    }
}()); //End the anonymous function and immediately call it