MediaWiki:TimeanddateClock.js

/********************* this comment is 80 characters long *********************/

(function {

"use strict"; if (window.andrewds1021 && window.andrewds1021.timeanddate_clock   && window.andrewds1021.timeanddate_clock.has_run) return; if (!window.andrewds1021) { window.andrewds1021 = { timeanddate_clock: { defaults: {} }   }; } else if (!window.andrewds1021.timeanddate_clock) { window.andrewds1021.timeanddate_clock = { defaults: {} }; } else if (!window.andrewds1021.timeanddate_clock.defaults) { window.andrewds1021.timeanddate_clock.defaults = {}; } window.andrewds1021.timeanddate_clock.has_run = true;

/* retrieve/set default values */ var defaults = window.andrewds1021.timeanddate_clock.defaults; if (!defaults.source) defaults.source = "i71tro3z/tt0/th1/tb2";

/* get elements to replace */ var clocks = document.getElementsByClassName("TimeanddateClock");

/* setup variables */ var url = "https://free.timeanddate.com/"; var style = "border-style: none;"; var plchld, iframe;

/* construct and insert iframe tags */ while (clocks.length > 0) { plchld = clocks[0]; iframe = document.createElement("iframe"); if (plchld.hasAttribute("data-timeanddateclock-iscountdown")       || defaults.is_countdown) { url = url + "countdown/"; } else { url = url + "clock/"; }   if (plchld.hasAttribute("data-timeanddateclock-source")) { url = url + plchld.getAttribute("data-timeanddateclock-source"); } else { url = url + defaults.source; }   iframe.setAttribute("src", url); if (plchld.hasAttribute("data-timeanddateclock-allowtransparency")       || defaults.allow_transparency) iframe.setAttribute("allowtransparency", ""); if (plchld.hasAttribute("data-timeanddateclock-width")) { style = style + " width: " + plchld.getAttribute("data-timeanddateclock-width") + ";"; } else if (defaults.width) { style = style + " width: " + defaults.width + ";"; }   if (plchld.hasAttribute("data-timeanddateclock-height")) { style = style + " height: " + plchld.getAttribute("data-timeanddateclock-height") + ";"; } else if (defaults.height) { style = style + " height: " + defaults.height + ";"; }   if (defaults.style) style = style + defaults.style; if (plchld.hasAttribute("data-timeanddateclock-style")) style = style + plchld.getAttribute("data-timeanddateclock-style"); iframe.setAttribute("style", style); plchld.parentElement.replaceChild(iframe, plchld); url = "https://free.timeanddate.com/"; style = "border-style: none;"; }

});