User:Holly Cheng/monobook.js
Appearance
(Redirected from User:Howcheng/monobook.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. |
The accompanying .css page for this skin is at User:Holly Cheng/monobook.css. |
// <pre>
// [[Wikipedia:WikiProject User scripts/Scripts/addLink]]
function addLink(where, url, name, id, title, key, after) {
// addLink() accepts either an id or a DOM node, mw.util.addPortletLink() only takes a node
if (after && !after.cloneNode)
after = document.getElementById(after);
return mw.util.addPortletLink(where, url, name, id, title, key, after);
}
function addTab(url, name, id, title, key){
return addLink('p-cactions', url, name, id, title, key);
}
//If you are not editing a page, a tab will appear allowing you to edit the 0th section of a page (the top area usually used as an introduction.
$(document).ready(function () {
var x;
if (!(x = document.getElementById('ca-edit') )) return;
var url;
if (!(url = x.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
var y = addLink('p-cactions', url+"§ion=0", '0', 'ca-edit-0',
'Edit the lead section of this page', '0', x.nextSibling);
y.className = x.className; // steal classes from the the edit tab...
x.className = 'istalk'; // ...and make the edit tab have no right margin
// exception: don't steal the "selected" class unless actually editing section 0:
if (/(^| )selected( |$)/.test(y.className)) {
if (!document.editform || !document.editform.wpSection
|| document.editform.wpSection.value != "0") {
y.className = y.className.replace(/(^| )selected( |$)/g, "$1");
x.className += ' selected';
}
}
});
function addLastDiff() {
var l=addTab("//en.wikipedia.org/w/index.php?title=" + mw.config.get('wgPageName') + "&diff=cur&oldid=prev", 'last', '');
l.lastChild.title="Show most recent diff";
}
if (mw.config.get('wgCanonicalNamespace') != "Special") {
if (window.addEventListener) window.addEventListener("load", addLastDiff, false);
else if (window.attachEvent) window.attachEvent("onload", addLastDiff);
}
function addPurge() {
var t = addTab("//en.wikipedia.org/w/index.php?title=" + mw.config.get('wgPageName') + "&action=purge", 'purge', '');
t.lastChild.title = "Purge the server cache";
}
if (mw.config.get('wgCanonicalNamespace') != "Special") {
if (window.addEventListener) window.addEventListener("load", addPurge, false);
else if (window.attachEvent) window.attachEvent("onload", addPurge);
}
// <nowiki>If you are editing a page, click the wikify button on your tab bar to add "{{Wikify-date|{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}" to the top, set "Marked for wikification." as the edit summary, mark it as a minor edit, and submit.</nowiki>
function add_link2(url, name)
{
var na = document.createElement('a');
na.setAttribute('href', url);
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.appendChild(na);
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
tabs.appendChild(li);
}
function strip_namespace(target)
{
var colon = target.indexOf(':');
if (colon != -1)
{
var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category');
var ns = target.substring(0, colon);
if (ns == '' || ns == 'Talk')
return target.substring(colon + 1);
else
for (var i = 0; i < spaces.length; ++i)
{
if (ns == spaces[i]
|| ns == spaces[i] + '_talk')
return target.substring(colon + 1);
}
}
return target;
}
importScript('User:Holly Cheng/quickimgdelete.js');
function replace() {
var s = prompt("Search regexp?");
if(s) {
var r = prompt("Replace regexp?");
if(!r && r != '') return;
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(new RegExp(s, "g"), r);
}
}
$(document).ready(function () {
if(document.forms.editform) {
addLink('p-cactions', 'javascript:replace()', 'replace', 'ca-replace', 'Regexp replace for the edit window', '', 'ca-history');
}
addLastDiff();
addPurge();
});
importScript("User:Ais523/topcontrib.js");
importScript("User:Anomie/linkclassifier.js");
// </pre>