MediaWiki:EthTime.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//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