User:Anpang/ChocBeta.js
Appearance
(Redirected from User:Anpang01/ChocBeta.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Anpang/ChocBeta. This user script seems to have an accompanying .css page at User:Anpang/ChocBeta.css. |
// Chocolate, a utility user script
// v1.1.0 (12 December 2023)
// Objects to Chocolate are prefixed with "choc".
// variables
const chocPath = "https://en.wikipedia.org/w/index.php?title=User:Anpang01/Chocolate";
const chocVersion = "1.1.0";
let chocEnabled = [
"Wiktionary", "Wikidata", "ExtraSandbox",
"NoSiteSub", "NoCopyWarn", "WhatWiki"
];
// will make cool Special:ChocolatePreferences page later
// functions
function chocCapitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// load css
importStylesheet("User:Anpang01/Chocolate.css");
// add icon
$("body").append(`
<div id="choc-icon-div">
<img id="choc-icon" src="https://upload.wikimedia.org/wikipedia/commons/1/1c/Twemoji_1f36b.svg" />
<span id="choc-icon-text">${chocVersion}</span>
</div>
`);
// Special:ChocolatePreferences
if(mw.config.get("wgPageName") == "Special:ChocolatePreferences") {
$("#firstHeading").text("Chocolate preferences");
$("#mw-content-text").text("Chocolate preferences are coming soon.");
}
// link-related modules
if (chocEnabled.includes("Wiktionary")) {
$("#p-cactions > div > ul").append(`
<li id="choc-ca-wiktionary" class="mw-list-item">
<a href="https://en.wiktionary.org/wiki/${mw.config.get("wgPageName")}" title="Corresponding Wiktionary page">
<span>Wiktionary</span>
</a>
</li>
`);
}
if (chocEnabled.includes("Wikidata")) {
$("#p-cactions > div > ul").append(`
<li id="choc-ca-wikidata" class="mw-list-item">
<a href="https://wikidata.org/wiki/Special:Search/${mw.config.get("wgPageName")}" title="Corresponding Wikidata page">
<span>Wikidata</span>
</a>
</li>
`);
}
if (chocEnabled.includes("ExtraSandbox")) {
$("#pt-sandbox").append(`
<a id="choc-sandbox2" href="/wiki/User:${mw.config.get("wgUserName")}/sandbox2" title="Your extra sandbox">
<span>(2)</span>
</a>
`);
}
// "no" modules
if (chocEnabled.includes("NoSiteSub")) {
$("#siteSub").remove();
}
if (chocEnabled.includes("NoCopyWarn")) {
$("#editpage-copywarn").remove();
}
// other
if (chocEnabled.includes("WhatWiki")) {
const subdomain = window.location.host.split(".")[0];
const after = window.location.host.split(".")[1];
$(`
<span id="choc-whatwiki">
[${subdomain.toUpperCase()} ${chocCapitalize(after)}]
</span>
`).appendTo('#firstHeading');
}