Misplaced Pages

User:Δ/Spam.js: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:Δ Browse history interactively← Previous editContent deleted Content added
Revision as of 23:40, 10 July 2010 view sourceBetacommand (talk | contribs)86,927 editsNo edit summary← Previous edit Latest revision as of 08:12, 29 November 2021 view source Ladsgroup (talk | contribs)Extended confirmed users, IP block exemptions, Pending changes reviewers, Rollbackers20,548 editsm Maintenance: Replacing addPortletLink() with mw.util.addPortletLink() (mw:ResourceLoader/Migration_guide_(users)#addPortletLink
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
//<nowiki>
//Written by ], thanks to ] and ] for help with this! //Written by ], thanks to ] and ] for help with this!
//Modified by ] //Modified by ]




if(mw.config.get('wgNamespaceNumber') == -1) {
//<pre><nowiki>
if(wgNamespaceNumber == -1) {
addOnloadHook(function() { addOnloadHook(function() {
var tbs = document.getElementById('p-cactions').getElementsByTagName('ul'); var tbs = document.getElementById('p-cactions').getElementsByTagName('ul');
Line 91: Line 91:
}; };


if(wgPageName == 'Special:LinkSearch') { if(mw.config.get('wgPageName') == 'Special:LinkSearch') {
addOnloadHook(function() { addOnloadHook(function() {
var tbs = document.getElementById('p-cactions').getElementsByTagName('ul'); var tbs = document.getElementById('p-cactions').getElementsByTagName('ul');
Line 97: Line 97:
}); });
}; };
//</nowiki></pre>


function substNRD() { function substNRD() {
Line 105: Line 104:
document.editform.submit(); document.editform.submit();
} else } else
document.location = wgServer + wgScript + "?title=" + wgPageName + "&action=edit&substNRD=1"; document.location = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + mw.config.get('wgPageName') + "&action=edit&substNRD=1";
}; };
function addSubstNRD(){ function addSubstNRD(){
if (wgCanonicalNamespace == "File") if (mw.config.get('wgCanonicalNamespace') == "File")
addPortletLink("p-cactions", "javascript:substNRD()", "{{" + "dfu}}", ""); mw.util.addPortletLink("p-cactions", "javascript:substNRD()", "{{" + "dfu}}", "");
if (document.location.href.indexOf("substNRD=1") > 0) if (document.location.href.indexOf("substNRD=1") > 0)
substNRD(); substNRD();
}; };
addOnloadHook(addSubstNRD); $(addSubstNRD);
//</nowiki>

Latest revision as of 08:12, 29 November 2021

//<nowiki>
//Written by ], thanks to ] and ] for help with this!
//Modified by ]


if(mw.config.get('wgNamespaceNumber') == -1) {
 addOnloadHook(function() {
 var tbs = document.getElementById('p-cactions').getElementsByTagName('ul');
 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*\\*.*?\\?.*?$', 'igm'), '');
 newtext = newtext.replace(new RegExp('(?:<ref(?:\\s*name=.*?)?>\\s*)?\\{\\{\\s*citeweb\\s*\\|(?:.*?\\|)*\\s*url\\s*=\\s*https?\\://'+reg+'/?.*?\\s*(?:\\|.*?)?\\}\\}(?:\\s*<\/ref>)?', 'ig'), '');
 newtext = newtext.replace(new RegExp('(?:<ref(?:\\s*name=.*?)?>\\s*)?\\?(?:\\s*<\/ref>)?', 'ig'), '$1');
 box.value = newtext;
 document.getElementById('wpSummary').value = 'Removing external link: '+tag+' -- per ]';
 document.getElementById('wpMinoredit').checked = true;
 document.getElementById('wpWatchthis').checked = true;
 document.getElementById('wpDiff').click();
 });
}

function rem_spam() {
 var targ = query_get('target') || unescape(location.href).split('/').reverse().split('?').split('#');
 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;
 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 = '';
 addTab(tbs, "javascript:void(filter_main())", "filter", 'ca-filter', 'Filter all pages on here to only be for mainspace');
};

function unrem_spam() {
 var links = document.getElementById('bodyContent').getElementsByTagName('a');
 for(var i=0; i<links.length; i++) {
 var link = links;
 link.href = link.href.split('linkmodified=yes');
 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);
    } catch (someError) {}
  }
  return null;
};


function filter_main() {
 var lis = document.getElementById('bodyContent').getElementsByTagName('li'); 
 var len = lis.length;
 for(var i=0; i<len; i++) { 
 var li = lis; 
 if(li.getElementsByTagName('a').innerHTML.indexOf(':') != -1) { 
 //li.parentNode.removeChild(li);
 li.style.display = 'none';
 }
 }
};

if(mw.config.get('wgPageName') == 'Special:LinkSearch') {
 addOnloadHook(function() {
 var tbs = document.getElementById('p-cactions').getElementsByTagName('ul');
 addlilink(tbs, "javascript:filter_main();", "filter", 'ca-filter', 'Filter all pages on here to only be for mainspace');
 });
};

function substNRD() {
  if (document.editform) {
    document.editform.wpTextbox1.value = "\n{{" + "db-f8}}\n"+document.editform.wpTextbox1.value;
    document.editform.wpSummary.value = "commons dupe";
    document.editform.submit();
  } else
    document.location = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + mw.config.get('wgPageName') + "&action=edit&substNRD=1";
};
function addSubstNRD(){
  if (mw.config.get('wgCanonicalNamespace') == "File")
    mw.util.addPortletLink("p-cactions", "javascript:substNRD()", "{{" + "dfu}}", "");
  if (document.location.href.indexOf("substNRD=1") > 0)
    substNRD();
};
$(addSubstNRD);
//</nowiki>
User:Δ/Spam.js: Difference between revisions Add topic