MediaWiki:Gadget-DatingSystem.js

/* _____________________________________________________________________________ * |                                                                             | * |                    === WARNING: GLOBAL GADGET FILE ===                      | * |                 Changes to this page affect many users. | * | Please discuss changes on the talk page or on WT:Gadget before editing. | * |_____________________________________________________________________________| * * Imported from version 1 as of 30 November 2017 from User:Erutuon/scripts/datingSystem.js * SHORT_DESCRIPTION, see SCRIPT_HOME_PAGE */ // // Switches the year-numbering system from BCE/CE to BC/AD /* globals addOnloadHook */ "use strict";

function yearFormatSwitch { if (!document.querySelectorAll) return; // This code supports date labels formatted using the following wikitext. (See and .) BCE can be replaced by CE: //  BCE var datetags = document.querySelectorAll('.ce-date'); for (var i = 0; i < datetags.length; i++) { var datetag = datetags[i]; if (datetag.firstChild && datetag.firstChild.firstChild && datetag.firstChild.firstChild.firstChild) { if (datetag.firstChild.firstChild.firstChild.nodeValue === "CE") { if (typeof datetag.firstChild.setAttribute === "function") { datetag.firstChild.setAttribute("href", "/wiki/Appendix:Glossary#AD"); }				datetag.firstChild.firstChild.innerHTML = "AD"; if (datetag.previousSibling) { var patt = /((?:\d{1,4} ?(?:-|–|to) ?)?\d{1,4}) ?$/g; // first if hyphen-minus, then en-dash var val = datetag.previousSibling.nodeValue; var matches = val.match(patt); if (matches !== null) { var lastMatch = matches[matches.length - 1]; datetag.previousSibling.nodeValue = datetag.previousSibling.nodeValue.substr(0, datetag.previousSibling.nodeValue.length - lastMatch.length); if(!datetag.nextSibling) datetag.parentElement.appendChild(document.createTextNode(" " + lastMatch)); else datetag.nextSibling.nodeValue = " " + lastMatch + datetag.nextSibling.nodeValue; }				}			}			else { if (typeof datetag.firstChild.setAttribute === "function") { datetag.firstChild.setAttribute("href", "/wiki/Appendix:Glossary#BC"); }				datetag.firstChild.firstChild.innerHTML = "BC"; }		}	}	// This code supports dates formatted in the following fashion: // CE // The tag can be replaced with or something else. var datetags2 = document.querySelectorAll(".ce-date2"); for (i = 0; i < datetags2.length; ++i ) { var datetag2 = datetags2[i]; var convert = { "BCE": "BC", "CE": "AD" }; datetag2.innerHTML = convert[datetag2.innerHTML]; } }

$(yearFormatSwitch);

//