MediaWiki talk:Common.js
How[edit]
How do you use ImportScript and ImportStyleSheet? Stupid evil Phantom! 14:00, 6 February 2009 (EST)
Removed[edit]
Herr FüzzyCätPötätö (talk/stalk) 14:28, 6 July 2017 (UTC)
Random CP Page[edit]
/* Random CP page [[User:Nx]] 01:24, 9 April 2009 (EDT) */ //Toggle indentation randomcpindent = false; function randomCP() { if (n_randompage = document.getElementById('n-randompage')) { if (wgNamespaceNumber == 100 || wgNamespaceNumber == 101) { n_randomcp = document.createElement('li'); n_randomcp.id = "n-randomcp"; n_randomcp.innerHTML = "<a"+' href="/wiki/Special:Random/Conservapedia" title="Load a random page from Conservapedia namespace">Random CP page</a>'; if (randomcpindent) { n_randomcpul = document.createElement('ul'); n_randomcpul.appendChild(n_randomcp); n_randomcp = n_randomcpul; } n_randompage.parentNode.insertBefore(n_randomcp,n_randompage.nextSibling); } } } $(document).ready(randomCP)
Sir ℱ℧ℤℤϒℂᗩℑᑭƠℑᗩℑƠ (talk/stalk) 14:28, 6 July 2017 (UTC)
Random block reasons[edit]
/* Inserts random block reasons from RationalWiki:Random_Block_Reasons and per-user block reasons from user's CustomBlockReasons subpage */ function insertAdditionalBlockReasons() { var blockReasonList = document.getElementById("wpBlockReasonList"); if (null != blockReasonList) { // attempt to get a XmlHTTPRequest object var req = false; if (window.XMLHttpRequest) { // for sane browsers req = new XMLHttpRequest(); } else if (window.ActiveXObject) { // oh dear, here's a nickel kid, get yourself a better browser. req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req) { var reasonsArray; var reasonOption; req.open("GET", "http://rationalwiki.org/wiki/index.php?title=RationalWiki:Random_Block_Reasons&action=raw&ctype=text/javascript", false); req.send(null); if (req.status == 200 && req.responseText != "/* Empty */" ) { // split lines in to an array reasonsArray = req.responseText.split("\n"); reason = reasonsArray[Math.floor(Math.random() * reasonsArray.length)]; var randomOptGroup = document.createElement('optgroup'); randomOptGroup.label = "Random block reason"; reasonOption = document.createElement("option"); reasonOption.value = reason; if (typeof(reasonOption.innerText) != "undefined") { reasonOption.innerText = reason; } else { reasonOption.text = reason; } randomOptGroup.appendChild(reasonOption); blockReasonList.appendChild(randomOptGroup); } req.open("GET", "http://rationalwiki.org/wiki/index.php?title=User:" +wgUserName+ "/CustomBlockReasons&action=raw&ctype=text/javascript", false); req.send(null); if (req.status == 200 && req.responseText != "/* Empty */") { // split lines in to an array reasonsArray = req.responseText.split("\n"); var customOptGroup = document.createElement('optgroup'); customOptGroup.label = "Custom block reasons"; var i; for (i=0;i<reasonsArray.length;++i) { reason = reasonsArray[i]; reasonOption = document.createElement("option"); reasonOption.value = reason; if (typeof(reasonOption.innerText) != "undefined") { reasonOption.innerText = reason; } else { reasonOption.text = reason; } customOptGroup.appendChild(reasonOption); } blockReasonList.appendChild(customOptGroup); } } } } $(document).ready(insertAdditionalBlockReasons);
FuzzyCatPotato of the Fucked Fluorescent lights (talk/stalk) 14:28, 6 July 2017 (UTC)
Add section bottom (already commented out)[edit]
/* addsectionbottom Add a new section link to the bottom of discussion pages function addsectionbottom() { if (!wgIsArticle) return; if ((document.URL.indexOf('?')>=0) && (document.URL.indexOf('action=delete')>=0)) return; var caplus; if (!(caplus = document.getElementById("ca-addsection"))) return; var addsection = document.createElement("span"); addsection.innerHTML = "<h3> <a " + "href=\"" + caplus.childNodes[0].getAttribute("href") + "\" title=\"" + caplus.childNodes[0].getAttribute("title") + "\" accesskey=\"" + caplus.childNodes[0].getAttribute("accesskey") + "\" >" + (skin == "vector" ? "<span> Add topic</span>" : "<span> Add section</span>" ) + "</a> </h3>" addsection.className = "noprint"; addsection.id = "addsectionbottom"; var content; if (!(content = document.getElementById("bodyContent"))) return; var catlinks = document.getElementById("catlinks"); if (catlinks == null) { content.appendChild(addsection); } else { content.insertBefore(addsection, catlinks); } } $(document).ready(addsectionbottom); */
FᴜᴢᴢʏCᴀᴛPᴏᴛᴀᴛᴏ, Esϙᴜɪʀᴇ (talk/stalk) 14:28, 6 July 2017 (UTC)
"Use of [variable] is deprecated. Use mw.config instead."[edit]
See MediaWiki Developer's Handbook/Add JavaScript/Predefined variables:
Use of these variables is deprecated. Use mw.config instead. So instead of "var wgCanonicalNamespace", we use "var mw.config.get( 'wgCanonicalNamespace' )".
FuzzyCatPotato!™ (talk/stalk) 14:52, 6 July 2017 (UTC)
Lack of anonymous functions[edit]
Any particular reason there's so much of
function foo() {
//bar
}
$(document).ready(foo);
rather than
$(document).ready(function () {
//bar
});
?
Then they could even all be merged into one function, if that were important.—Kazitor, pending 07:14, 27 May 2018 (UTC)