User:Melancholie/monobook.js
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.
// addLink function ([[:en:Wikipedia:WikiProject User scripts/Scripts/addLink|origin]])
function addLink(where, url, name, id, title, key, after) {
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if (id) li.id = id;
li.appendChild(na);
var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
if (after) {
tabs.insertBefore(li,document.getElementById(after));
} else {
tabs.appendChild(li);
}
if (id) {
if (key && title) {ta[id] = [key, title];}
else if (key) {ta[id] = [key, ''];}
else if (title) {ta[id] = ['', title];}
}
akeytt();
return li;
}
// HTML replace function for history overview import ([[:en:Wikipedia:WikiProject User scripts/Scripts/Replace|partial source]]; [[:en:Wikipedia:WikiProject User scripts/Scripts|*]])<pre>
function replaceHistory() {
var editForm = document.editform.wpTextbox1;
editForm.value = editForm.value.replace(/([\r\n])/g, "");
editForm.value = editForm.value.replace(/\&\;/g, "&");
editForm.value = editForm.value.replace(/(\<\/?(input|span)[^\>]*\>|\([^\)]+\) |\&action\=edit| class\=\"new\")/g, "");
editForm.value = editForm.value.replace(/.*\<ul id\=\"pagehistory\"\>/, "== Former article versions at [[m:Test-wp|Meta.wikimedia.org]] ==\r\n\n:Article revision date – User at Meta <sup>(Local user contributions)</sup> – ''(Summary)''\r\n\n<div style=\"background-color: #F8F8FF; border: 1px solid #AAAAAA; padding: 5px;\">\r\n\n");
editForm.value = editForm.value.replace(/\<li\>/g, "*");
editForm.value = editForm.value.replace(/\<a href\=\"/g, "[http://meta.wikimedia.org");
editForm.value = editForm.value.replace(/\" title\=\"[^\"]+\"\>/g, " ");
editForm.value = editForm.value.replace(/\<\/a\>/g, "] – ");
editForm.value = editForm.value.replace(/\[http(\S+)(User\:|target\=)(\S+) ([^\]]+)\]/g, "[http$1$2$3 $4] <sup> ([[Special:Contributions/$3|$3]])</sup>");
editForm.value = editForm.value.replace(/\<\/li\>/g, "\r\n");
editForm.value = editForm.value.replace(/sup\> \ \;\&ndash\;\ \;([\r\n])/g, "sup>");
editForm.value = editForm.value.replace(/→\] \ \;\&ndash\;\ \;/g, "→] ");
editForm.value = editForm.value.replace(/ \((.+)\)([\r\n])/g, " ''($1)''");
editForm.value = editForm.value.replace(/\<\/ul\>.*/, "\r\n</div>\r\n\n:Article revision date – User at Meta <sup>(Local user contributions)</sup> – ''(Summary)''");
document.editform.wpSummary.value = "[[m:Test-wp|Article history from Meta.wikimedia.org!]]";
}
function linkFix() {
var editForm = document.editform.wpTextbox1;
editForm.value = editForm.value.replace(/\[\[(t|T)est-WP\/bar\//g, "[[");
editForm.value = editForm.value.replace(/\[\[(w|W)ikipedia\/bar\//g, "[[");
editForm.value = editForm.value.replace(/\[\[([^\:\]]+)\]\]/g, "[[Wikipedia/bar/$1]]");
editForm.value = editForm.value.replace(/\[\[Wikipedia\/bar\/([^\|\]]+)\]\]/g, "[[Wikipedia/bar/$1|$1]]");
document.editform.wpSummary.value = "links fixed";
}
function setSummary() {
document.editform.wpSummary.value = "Current version from Meta.wikimedia.org!";
}
addOnloadHook(function () {
var title;
if (!(title = document.getElementById('t-whatlinkshere') )) return;
if (!(title = title.getElementsByTagName('a')[0] )) return;
if (!(title = title.href )) return;
if (!(title = title.replace(/^.*\/wiki\/Spe(c|z)ial:Whatlinkshere\//, '') )) return;
addLink('p-navigation', 'http://meta.wikimedia.org/w/index.php?title='+title,
'Meta', 't-meta', 'Meta', '', null);
if (document.forms.editform) {
addLink('p-cactions', 'javascript:linkFix()', 'Fix',
'ca-linkfix', 'Linkfix', '', 'ca-watch');
addLink('p-cactions', 'javascript:setSummary()', 'Sum',
'ca-setsummary', 'Summary', '', 'ca-linkfix');
addLink('p-cactions', 'javascript:replaceHistory()', 'HTML',
'ca-replacehistory', 'HTML replace', '', 'ca-setsummary');
}
}); // End of script</pre>