MediaWiki:Common.js
E J.Fla Garden (◕‿◕✿)
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)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
var urlLanguages = document.getElementById("url-languages");
if (urlLanguages!=null) {
const sel = document.createElement("select");
const opt1 = document.createElement("option");
const opt2 = document.createElement("option");
sel.id = "selectLanguages";
sel.className = "country-flags";
sel.setAttribute("onchange", "document.location.href=document.getElementById('selectLanguages').value");
index = 0;
languageItems = document.getElementsByClassName("language-item");
for (var i=0; i<languageItems.length; i++) {
opt = document.createElement("option");
opt.value = languageItems[i].firstChild.href;
opt.text = document.getElementById(languageItems[i].id).firstChild.innerHTML;
sel.add(opt, null);
if (document.documentElement.lang==languageItems[i].id.substring(4))
sel.selectedIndex = index;
index++;
}
document.getElementById("user-tools").append(sel);
document.getElementById("user-tools").style.display = "flex";
urlLanguages.outerHTML = "";
}
if (document.getElementById("personal").firstChild.firstChild.innerHTML=="Anonymous"
|| document.getElementById("personal").firstChild.firstChild.innerHTML=="익명 사용자"
|| document.getElementById("personal").firstChild.firstChild.innerHTML=="Anonyme"
) {
allLinkElements = document.getElementsByTagName("a");
for (var i=0; i<allLinkElements.length; i++) {
if (allLinkElements[i].className=="new") {
allLinkElements[i].outerHTML = allLinkElements[i].innerHTML;
i--;
}
}
userLinkElements = document.getElementsByClassName("mw-userlink");
for (var i=0; i<userLinkElements.length; i++) {
userLinkElements[i].outerHTML = "";
i--;
}
userLinkElements = document.getElementsByClassName("mw-usertoollinks");
for (var i=0; i<userLinkElements.length; i++) {
userLinkElements[i].outerHTML = "";
i--;
}
} else {
document.getElementById("mw-page-header-links").style.display = "block";
document.getElementById("site-tools").style.display = "block";
document.getElementById("page-tools").style.display = "block";
document.getElementById("personal").style.display = "block";
userLinkElements = document.getElementsByClassName("mw-userlink");
for (var i=0; i<userLinkElements.length; i++) {
userLinkElements[i].style.display = "block";
}
userLinkElements = document.getElementsByClassName("mw-usertoollinks");
for (var i=0; i<userLinkElements.length; i++) {
userLinkElements[i].style.display = "block";
}
if ((document.body.innerHTML.indexOf('"/wiki/')>-1) && (window.location.pathname!="/index.php") && (window.location.pathname!="/MediaWiki:Common.js")) {
alert("Page to purge");
window.location.href = document.getElementById("ca-edit").firstChild.href.replace("&action=edit", "&action=purge");
}
}
/********************/
/* Clickable button */
/********************/
function clickButton() {
window.open(event.srcElement.getAttribute("data-link"), "_blank");
};
clickableButtons = document.getElementsByClassName("button-clickable");
for (i=0; i<clickableButtons.length; i++) {
linksElements = clickableButtons[i].getElementsByTagName("a");
if (linksElements.length>0) {
clickableButtons[i].setAttribute("data-link", linksElements[0].href);
linksElements[0].outerHTML = linksElements[0].innerHTML;
}
clickableButtons[i].addEventListener('click', clickButton);
}
function clickDiv() {
if (event.srcElement.getAttribute("data-link")!=null)
document.location.href = event.srcElement.getAttribute("data-link");
else if (event.srcElement.parentNode.getAttribute("data-link")!=null)
document.location.href = event.srcElement.parentNode.getAttribute("data-link");
};
clickableDivs = document.getElementsByClassName("div-clickable");
for (i=0; i<clickableDivs.length; i++) {
linksElements = clickableDivs[i].getElementsByTagName("a");
if (linksElements.length>0) {
clickableDivs[i].setAttribute("data-link", linksElements[0].href);
}
clickableDivs[i].addEventListener('click', clickDiv);
}
/***************/
/* Redirection */
/***************/
var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname.split('/')[window.location.pathname.split('/').length-1] + window.location.search
if (newURL!=window.location.href) {
//alert("Redirection to new url");
window.location.href = newURL;
}
