Jump to content

User:Δ/Spam.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Betacommand (talk | contribs) at 18:49, 19 January 2007 (+ Link removal tools). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//Written by [[User:GeorgeMoney]], thanks to [[User:Where]] and [[User:Eagle_101]] for help with this!
//Modified by [[User:Betacommand]]
// BEGIN MYSPACE LINK REMOVAL CODE
//check if we are editing and we want to myspace
if (window.location.href.indexOf('action=edit') != -1 && window.location.href.indexOf('myspace=1') != -1) {
  function myspace() {
    document.getElementById('wpSummary').value = "Removing Myspace link as unverifiable and against policy [[WP:EL]]";
        var contents = document.getElementById('wpTextbox1').value;
        var newcontents = contents.replace(/(\*\s*?)?\[http\:\/\/\w*?myspace\.com.*?\]/g, "");
        document.getElementById('wpTextbox1').value = newcontents;
        document.getElementById('wpDiff').click();
        document.getElementById('wpWatchthis').checked = "";
}
    addOnloadHook(function(){ myspace(); });
}
//Check if it's article to add the tab
if(wgCanonicalNamespace == "") {
  addOnloadHook(function(){ 
   var taburl = "http://en.wikipedia.org/w/index.php?title="+wgPageName+"&action=edit&myspace=1";
   addTab(taburl, "Remove Myspace!", "ca-myspace", "This is to kill Myspace Links"); 
  });
}
//END MYSPACE LINK REMOVAL CODE
////////////////////////////////////////////////
//Written by [[User:GeorgeMoney]], thanks to [[User:Where]] and [[User:Eagle_101]] for help with this!
//Modified by [[User:Betacommand]]
// BEGIN google LINK REMOVAL CODE
//check if we are editing and we want to google
if (window.location.href.indexOf('action=edit') != -1 && window.location.href.indexOf('google=1') != -1) {
  function google() {
    document.getElementById('wpSummary').value = "Removing google link against policy to link to Search Engines";
        var contents = document.getElementById('wpTextbox1').value;
        var newcontents = contents.replace(/(\*\s*?)?\[http\:\/\/\w*?google\.com.*?\]/g, "");
        document.getElementById('wpTextbox1').value = newcontents;
        document.getElementById('wpDiff').click();
        document.getElementById('wpWatchthis').checked = "";
}
    addOnloadHook(function(){ google(); });
}
//Check if it's article to add the tab
if(wgCanonicalNamespace == "") {
  addOnloadHook(function(){ 
   var taburl = "http://en.wikipedia.org/w/index.php?title="+wgPageName+"&action=edit&google=1";
   addTab(taburl, "Remove google!", "ca-google", "This is to kill google Links"); 
  });
}
//END google LINK REMOVAL CODE

//<pre><nowiki>
if(wgNamespaceNumber == -1) {
	addOnloadHook(function() {
		var tbs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
		addlilink(tbs, "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(function() {
		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;
		newtext = newtext.replace(new RegExp('^\\s*\\*.*?\\[?https?://'+reg+'/?(\\s*.*?)?\\]?.*?$', 'igm'), '');
		newtext = newtext.replace(new RegExp('(?:<ref(?:\\s*name=["\'].*?["\'])?>\\s*)?\\{\\{\\s*cite[_ ]web\\s*\\|(?:.*?\\|)*\\s*url\\s*=\\s*https?\\://'+reg+'/?.*?\\s*(?:\\|.*?)?\\}\\}(?:\\s*<\/ref>)?', 'ig'), '');
		newtext = newtext.replace(new RegExp('(?:<ref(?:\\s*name=["\'].*?["\'])?>\\s*)?\\[?https?\\://'+reg+'/?.*?(\\s+.+?)\\]?(?:\\s*<\/ref>)?', 'ig'), '$1');
		box.value = newtext;
		document.getElementById('wpSummary').value = 'Removing external link: '+tag+' -- per [[WP:EL|external link guidelines]]';
		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 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);
		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 = '';
}

//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;
};
//</nowiki></pre>
//<pre><nowiki>
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';
		}
	}
}

if(wgPageName == 'Special:Linksearch') {
	addOnloadHook(function() {
		var tbs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
		addlilink(tbs, "javascript:void(filter_main())", "filter", 'ca-filter', 'Filter all pages on here to only be for mainspace');
	});
}
//</nowiki></pre>

<!--BEGIN GEORGEMONEY'S INTERFACE TO Wiz's IP LOOKUP SCRIPT --> 
document.write('<script type="text/javascript" src="'  
     + 'http://en.wikipedia.org/w/index.php?title=User:GeorgeMoney/UserScripts/LoadIpInfo'  
     + '&action=raw&ctype=text/javascript&dontcountme=s"></s'+'cript>'); 
<!--END GEORGEMONEY'S INTERFACE TO Wiz's IP LOOKUP SCRIPT -->