User:Dusti/global.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.
//modrollback.js
//By GeorgeMoney
function modrollback() {
var ds = document.getElementsByTagName('td');
for(var i=0; i<ds.length; i++) {
var a = ds[i];
if(a.className == 'diff-ntitle') {
var fs = a.getElementsByTagName('a');
for(var j=0; j<fs.length; j++) {
var b = fs[j];
if(b.firstChild.data == 'rollback') {
var oldhref = ''+b.href;
var usr = decodeURIComponent(b.href.split('from=')[1].split('&')[0])
var user = usr.replace(/\+/g,'_');
var cont = wgServer + '/wiki/' + 'Special:Contributions/' + user;
b.href = 'javascript:void(0)';
b.onclick = function() {
var http = new XMLHttpRequest();
http.open('GET', oldhref, true);
http.setRequestHeader("Connection", "close");
http.send(null);
http.onreadystatechange= function() {
window.location.href = (cont);
}
}
}
}
}
}
}
$(modrollback);
// Outline for an automatic delete link generator.
// Not highly tested. Started by Splarka @ test.wikipedia
// Written for & maintained by Mike_lifeguard @ en.wikibooks
//GO IF contribs, RC, whatlinkshere, log, prefixindex, newpages, (article and not special and [submit or view or purge])
if( wgCanonicalSpecialPageName == "Contributions"
|| wgCanonicalSpecialPageName == "Recentchanges"
|| wgCanonicalSpecialPageName == "Whatlinkshere"
|| wgCanonicalSpecialPageName == "Log"
|| wgCanonicalSpecialPageName == "Prefixindex"
|| wgCanonicalSpecialPageName == "Newpages"
|| (wgIsArticle == true
&& wgCanonicalNamespace != "Special"
&& ( wgAction == "submit" || wgAction == "view" || wgAction == "purge" )
)
) addOnloadHook(function(){
mw.util.addPortletLink('p-cactions','javascript:deleteLinkify()','autodelete','ca-dellink','generate deletion links');
})
function deleteLinkify() {
var reason = prompt('Enter default delete reason','per speedy deletion policy');
if(!reason) return;
var links = document.getElementById('bodyContent').getElementsByTagName('a');
var arp = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace(/\$1/,'');
if(links.length == 0) return
for(var i=0;i<links.length;i++) {
if(links[i].href.indexOf(arp)==0 && links[i].href.indexOf('action=delete') == -1 && links[i].href.indexOf('/Special:') == -1 ) {
links[i].href += '?action=delete&submitdelete=true&deletetalkalso=true&wpReason=' + encodeURIComponent(reason);
links[i].innerHTML += ' (delete)';
}
}
}
if(queryString('submitdelete') == 'true') addOnloadHook(function() {
if(document.getElementById('ca-talk').className.indexOf('new')==-1 && queryString('deletetalkalso')=='true' && ( wgNamespaceNumber % 2 == 0 ) ) {//if the talk tab is redlinked and this is the first time 'round AND this is not a talk page then:
document.getElementById('deleteconfirm').action += '&deletetalk=true&wpReason=' + queryString('wpReason');
}
var sub = (document.getElementById('wpConfirmB')) ? document.getElementById('wpConfirmB') : document.getElementById('mw-filedelete-submit')
sub.click();
})
if(wgAction == 'delete' && queryString('deletetalk') == 'true') addOnloadHook(function() {
var url = document.getElementById('ca-talk').getElementsByTagName('a')[0].href + '?action=delete&submitdelete=true&wpReason=' + queryString('wpReason');
document.location.href = url;
})
function queryString(p) {
var re = RegExp('[&?]' + p + '=([^&]*)');
var matches;
if (matches = re.exec(document.location)) {
try {
return decodeURI(matches[1]);
}
catch (e) {
}
}
return null;
}
//removespam.js
var remSpamSummary = {
'bs' : 'Uklonjen vanjski link: __LINK__ -- po osnovi __REPORT__.',
'ca' : 'Llevant l\'enllaç extern: __LINK__ -- per __REPORT__.',
'cs' : 'Odstranění externího odkazu __LINK__ -- na základě __REPORT__.',
'da' : 'Fjerner ekstern henvisning __LINK__ jf. __REPORT__.',
'de' : 'Externer Link __LINK_ gemäß __REPORT__ entfernt.',
'el' : 'Αφαίρεση εξ. συνδ.: __LINK__ -- κατά το __REPORT__.',
'en' : 'Removing external link: __LINK__ -- per __REPORT__.',
'es' : 'Eliminando enlace externo __LINK__ por __REPORT__.',
'eu' : '__LINK__ kanpo lotura kendu da arrazoi honegatik: __REPORT__.',
'fa' : 'حذف پیوند به بیرون: __LINK__ بر طبق __REPORT__.',
'fr' : 'Lien externe __LINK__ enlevé par __REPORT__.',
'fy' : 'Keppeling om utens __LINK__ fuorthelle oerienkomstich __REPORT__.',
'he' : 'מסיר קישור חיצוני: __LINK__ -- לפי __REPORT__.',
'id' : 'Membuang pranala luar: __LINK__ -- per __REPORT__.',
'it' : 'Rimuovo collegamento esterno: __LINK__ -- vedi __REPORT__.',
'ja' : '不適切な外部リンクの除去: __LINK__ (関連ページ: __REPORT__)',
'ms' : 'Mengeluarkan pautan luar: __LINK__ -- per __REPORT__.',
'nb' : 'Fjerner ekstern lenke __LINK__ per __REPORT__.',
'nl' : 'Link naar __LINK__ verwijderd per __REPORT__.',
'nn' : 'Fjernar utlenkja __LINK__ per __REPORT__.',
'no' : 'Fjerner ekstern lenke __LINK__ per __REPORT__.',
'pt' : 'Removendo ligação externa __LINK__ por __REPORT__.',
'ru' : 'Удалена внешняя ссылка __LINK__ согласно __REPORT__.',
'sk' : 'Odstránenie externého odkazu __LINK__ -- na základe __REPORT__.',
'uk' : 'Вилучена зовнішня посилання __LINK__ згідно __REPORT__.'
};
function dorem_spam() {
var tag = query_get('remspam');
var box = document.getElementById('wpTextbox1');
var txt = box.value;
var reg = tag.replace('http://', '').replace(/\./g, '\\.').replace(/\*\\?\./g, '(?:.*?\\.)?');
var newtext = ''+txt;
// var elreg = /.*\s*={1,6}external\s*links?={1,6}\s*.*/ig;
// var elreg2 = /(\s*={1,6}external\s*links?={1,6}.*)$/
// if(elreg.test(newtext)) {
// alert('MATCHED');
// var elsect = newtext.replace(elreg, '$1');
// document.getElementById('content').appendChild(document.createTextNode(elreg));
// document.getElementById('content').appendChild(document.createElement('br'));
// document.getElementById('content').appendChild(document.createTextNode(elsect));
// fuu();
// elsect = elsect.replace(new RegExp('^\\s*\\*.*?\\[?https?\\://'+reg+'/?.+?(?:\\s+(.+?)\\]|(\\s)).*?$', 'igm'), '');
// newtext = newtext.replace(elreg, elsect);
// }
if(!query_get('options') || (',' + query_get('options') + ',').indexOf(',lines,') != -1) newtext = newtext.replace(new RegExp('^\\s*\\*.*?\\[?https?\\://'+reg+'/?.+?(?:\\s+(.+?)\\]|.*?)$', 'igm'), '');
if(!query_get('options') || (',' + query_get('options') + ',').indexOf(',citeweb,') != -1) newtext = newtext.replace(new RegExp('(?:<ref(?:\\s*name=["\'].*?["\'])?>\\s*)?\\{\\{\\s*cite[_ ]web\\s*\\|(?:.*?\\|)*\\s*url\\s*=\\s*https?\\://'+reg+'/?.*?\\s*(?:\\|.*?)?\\}\\}(?:\\s*<\/ref>)?', 'ig'), '');
if(!query_get('options') || (',' + query_get('options') + ',').indexOf(',inline,') != -1) newtext = newtext.replace(new RegExp('(?:<ref(?:\\s*name=["\'].*?["\'])?>\\s*)?\\[?https?\\://'+reg+'/?.+?(?:\\s+(.+?)\\]|(\\s))(?:\\s*<\/ref>)?', 'ig'), '$1');
box.value = newtext;
if (query_get('usesummary')) {
summary = query_get('usesummary').replace(/__LINK__/g, tag);
} else if (query_get('remspam') && query_get('report')) {
summary = remSpamSummary[wgContentLanguage] || 'Removing external link: __LINK__ -- per __REPORT__. [[:m:RemSpam|Translate this summary]].';
summary = summary.replace(/__LINK__/g, tag)
summary = summary.replace(/__REPORT__/g, '[[:m:' + query_get('report') + ']]');
} else {
summary = 'Removing external link: '+tag+' per [[m:Talk:Spam_blacklist]]';
}
document.getElementById('wpSummary').value = summary;
document.getElementById('wpMinoredit').checked = true;
document.getElementById('wpWatchthis').checked = false;
document.getElementById('wpDiff').click();
}
function rem_spam() {
var targ = query_get('target') || unescape(location.href).split('/').reverse()[0].split('?')[0].split('#')[0];
var tag = prompt('Please insert a link (without http://) to remove from\nall pages listed here. Example (and default if textbox is blank):\n'+targ);
if(tag == null) { alert('Action canceled.'); return; }
if(tag == "") tag = targ;
var options = prompt('Please enter the option modes you would want.\nEnter each one in the textbox (without any seperation marker)\ne=Remove lines of External Links that contain the link\ni=Remove links inline in text\nc=Remove Cite_web templates using the link\nExample: ci\nLeave the box blank for all modes');
if(options == null) { alert('Action canceled.'); return; }
if(options == "") options = 'eic';
options = options.split(new RegExp(''));
var opt = '';
for(var x in options) {
var y = options[x];
if(y == 'c') opt += ',citeweb';
if(y == 'i') opt += ',inline';
if(y == 'e') opt += ',lines';
}
opt = opt.substring(1);
options = opt;
var usesummary = prompt('Please enter a summary to use\nDefault: Removing external link: __LINK__ per [[m:Talk:Spam blacklist]]');
if(usesummary == null) { alert('Action canceled.'); return; }
if(usesummary == '') usesummary = 'Removing external link: __LINK__ -- per [[m:Talk:Spam blacklist]]';
var links = document.getElementById('bodyContent').getElementsByTagName('a');
for(var i=0; i<links.length; i++) {
var link = links[i];
var cha = (link.href.indexOf('?') != -1) ? '&' : '?';
link.href += cha + 'linkmodified=yes&action=edit&remspam='+escape(tag)+'&options='+escape(options)+'&usesummary='+escape(usesummary);
link.style.color = "green";
link.onmouseup = function() { this.style.color = 'orange'; };
link.innerHTML = link.innerHTML.replace(/(<([^>]+)>)/g, '');
}
var btn = document.getElementById('ca-remspam').firstChild;
btn.href = 'javascript:unrem_spam();';
btn.innerHTML = 'un-highlight links';
btn.title = '';
}
function unrem_spam() {
var links = document.getElementById('bodyContent').getElementsByTagName('a');
for(var i=0; i<links.length; i++) {
var link = links[i];
link.href = link.href.split('linkmodified=yes')[0];
link.style.color = "";
}
alert('All links will now be safe to click...');
var btn = document.getElementById('ca-remspam').firstChild;
btn.href = 'javascript:rem_spam();';
btn.innerHTML = 'remove external links';
btn.title = '';
}
function filter_main() {
var lis = document.getElementById('bodyContent').getElementsByTagName('li');
var len = lis.length;
for(var i=0; i<len; i++) {
var li = lis[i];
if(li.getElementsByTagName('a')[1].innerHTML.indexOf(':') != -1) {
//li.parentNode.removeChild(li);
li.style.display = 'none';
}
}
}
function addfilter_main() {
mw.util.addPortletLink('p-cactions', "javascript:filter_main()", "filter links", 'ca-filter', 'Filter all pages on here to only be for mainspace');
}
function addrem_spam() {
mw.util.addPortletLink('p-cactions', "javascript:rem_spam()", "remove external links", 'ca-remspam', 'Alter all the links on this page to autorem the external link on the page when clicked');
}
if(location.href.indexOf('action=edit') != -1 && location.href.indexOf('remspam=') != -1) addOnloadHook(dorem_spam);
if(wgCanonicalSpecialPageName == "LinkSearch") {
addOnloadHook(addrem_spam);
addOnloadHook(addfilter_main);
}
//parse paramName out of query string
//stolen from Lupin's popups
function query_get(paramName) {
var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
var h=document.location;
var m;
if (m=cmdRe.exec(h)) {
try {
return unescape(m[1]);
}
catch (someError) {}
}
return null;
}
/**
* xwikirollback
* Allows for tools to make rollbacklinks by adding
* "&xwikirollback" to the query string of a link to
* a diff page.
*
*/
$( function ()
{
//Check if we're comparing revisions and we want to rollback the edit
if (document.location.href.indexOf('diff=') != -1 && document.location.href.indexOf('&xwikirollback') != -1) {
//The rollback link is in a span with the "mw-rollback-link" class
var s = getElementsByClassName(document, 'span', 'mw-rollback-link');
//If there's no such span or more than one don't do anything
if (s.length != 1 ) {
return false;
} else {
//There should only be one link in this span, i.e. the rollback link
var a = s[0].getElementsByTagName('a');
if (a.length != 1 ) {
return false;
} else {
//Check if it's indeed a rollback link
if (a[0].href.indexOf('action=rollback') != -1) {
window.location = a[0].href;
}
}
}
}
}
)