User:Piperium/common.js
(async () => {
await new Promise(resolve => setTimeout(resolve, 10));
// Non-monobook warning
if("monobook" != mw.user.options.values.skin) {
if(!confirm(`This script is designed for MonoBook—you're using ${mw.user.options.values.skin}. Load script anyway?`)) return;
}
(() => { // Purge button
const pp_purge_cfg = {
"btnTitle": "Purge the page cache",
"btnClass": "mw-list-item",
"btnId": "pp-purge",
"linkText": "purge",
"activeClass": "selected"
};
if(document.getElementsByClassName("pBody")) {
let parent = document.getElementsByClassName("pBody")[0].querySelector("ul");
if(parent) {
// Set up the element
let newBtn = document.createElement("li");
newBtn.className = pp_purge_cfg.btnClass;
newBtn.id = pp_purge_cfg.btnId;
// Add the <a>
let newA = document.createElement("a");
newA.title = pp_purge_cfg.btnTitle;
newA.innerHTML = pp_purge_cfg.linkText;
newA.className = "pp-purge-link";
// Figure out the URL
let pageData = window.location;
if(pageData.pathname.startsWith("/w/")) {
let targetPage = pageData.href.split("&")[0]; // Complex URL (<leading data> + &<trailing data>)
newA.href = targetPage.split("#")[0] + "&action=purge";
} else if(pageData.pathname.startsWith("/wiki/")) {
let targetPage = pageData.href.split("?")[0]; // Standard URL (+ ?<data>)
newA.href = targetPage.split("#")[0] + "?action=purge";
}
// Are we on the purge page?
newBtn.className += activeCheck(pageData);
newA.style.fontWeight = "bold";
// Add everything
newBtn.appendChild(newA);
parent.appendChild(newBtn);
} // if(parent)
} // if(document.getElementsByClassName("pBody"))
// Are we already on the purge page?
// If so, we'll update the button class to reflect it
function activeCheck(pageData) {
return pageData.search.includes("action=purge") ? (" " + pp_purge_cfg.activeClass) : "";
}
})(); // End of purge button
(() => { // Last modified below title
let siteSub = document.getElementById("siteSub");
let lastmod = document.getElementById("lastmod");
if(!(siteSub && lastmod)) return;
siteSub.innerHTML = lastmod.innerHTML;
})(); // End of last modified below title
(() => { // Quick define button
const pp_qdef_cfg = {
"btnTitle": "Define an unknown English word (DictionaryAPI)",
"btnClass": "mw-list-item",
"btnId": "pp-qdef",
"linkText": "quick define"
};
if(document.getElementsByClassName("pBody")) {
let parent = document.getElementsByClassName("pBody")[0].querySelector("ul");
if(parent) {
// Set up the element
let newBtn = document.createElement("li");
newBtn.className = pp_qdef_cfg.btnClass;
newBtn.id = pp_qdef_cfg.btnId;
// Add the <a>
let newA = document.createElement("a");
newA.title = pp_qdef_cfg.btnTitle;
newA.innerHTML = pp_qdef_cfg.linkText;
newA.className = "pp-qdef";
newA.style.fontWeight = "bold";
newBtn.addEventListener("click", async () => {
let lemma = prompt("Type or paste in a word to define");
if(lemma) {
try {
let result = await(await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${lemma}`)).json();
alert(`${result[0].word} (${result[0].meanings[0].partOfSpeech}): ${result[0].meanings[0].definitions[0].definition}`);
} catch(e) {
alert(`No definition found for ${lemma.toUpperCase()}`)
}
}
return;
});
newBtn.appendChild(newA);
parent.appendChild(newBtn);
}
}
})(); // End quick define button
})();
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.