Jump to content

User:Technical 13/Scripts/CVD.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 01:32, 20 June 2014 (a single expression with multiple conditions...). 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.
/* Get links from page */
var externalLinks = [];
$('a.external').each(function(){
	externalLinks[externalLinks.length] = $(this).attr('href');
});
/* Clean out the duplicates */
externalLinks.sort();
var uniqueLinks = [];
$.each( externalLinks, function( i, el ){
	if($.inArray(el, uniqueLinks) === -1) uniqueLinks.push(el);
});
/* Filter out the enwp and ones with relational prefixes as they're also likely local */
var uniqueURLs = [];
$.each( uniqueLinks, function( i, el ){
	if(el.search(/https?/i) !== -1 && el.search(/\/\/en(wp|\.wikipedia)\.org\/(.*)?/i) === -1){
		uniqueURLs.push(el);
	}
});

/* TRON report */
function lpad(n, e, d) {
  var o = '';
  if(typeof(d) === 'undefined'){ d='0'; }
  if(typeof(e) === 'undefined'){ e=2; }
  if(n.length < e){
    for(var r=0; r < e - n.length; r++){
      o += d;
    }
    o += n
  } else { o=n; }
  return o;
}
var loadTS = new Date;
loadTS = lpad(loadTS.getUTCFullYear().toString(), 4) + lpad((loadTS.getUTCMonth()+1).toString(), 2) + lpad(loadTS.getUTCDate().toString(), 2) + lpad(loadTS.getUTCHours().toString(), 2) + lpad(loadTS.getUTCMinutes().toString(), 2) + lpad(loadTS.getUTCSeconds().toString(), 2);
var task = '== Report for ' + mw.config.get('wgPageName') + ' by ' +  mw.config.get('wgUserName') + ' ==\n';
task += '{{User8|' + mw.config.get('wgUserName') + '}} <sup>(' + mw.config.get('wgUserGroups').join(', ') + ')</sup> loaded ' + mw.config.get('wgPageName') + ' at {{#time: H:i:s, F j, Y|' + loadTS + '}} (UTC).\n';
task += 'The script found the following ' + externalLinks.length.toString() + ' link(s) and filtered out ' + (externalLinks.length - uniqueLinks.length).toString() + ' duplicate(s) and ' + (uniqueLinks.length - uniqueURLs.length).toString() + ' mislabled internal link(s).  This left the ' + uniqueURLs.length + ' URL(s) listed below.';
console.log('\n%s\n=== Links ===\n{{Div col start|2}}\n# %s\n{{Div col end}}\n=== URLs ===\n{{Div col start|2}}\n# %s\n{{Div col end}}\n', task, externalLinks.join('\n# '), uniqueURLs.join('\n# '));
/* TROFF */

var scanCV = mw.util.addPortletLink(
	"p-tb",
	"#",
	"CVDetector",
	"p-cv-detector",
	"Scan for copyright violations with Earwig's CopyVios & Derrick Coetzee's Duplication Detector tools"
);

$( scanCV ).click( function ( e ) {
	e.preventDefault();
	window.open('http://toolserver.org/~earwig/copyvios?lang=' + wgContentLanguage + '&project=' + wgSiteName.toLowerCase() + '&title=' + encodeURIComponent(mw.config.get('wgPageName')), '_blank');
	for(var i=0; i < uniqueURLs.length; i++){
		window.open('http://toolserver.org/~earwig/copyvios?lang=' + wgContentLanguage + '&project=' + wgSiteName.toLowerCase() + '&title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&url=' + encodeURIComponent(uniqueURLs[i]), '_blank');
	}
	
});

/* DupDet
'//tools.wmflabs.org/dupdet/compare.php?url1=' + encodeURIComponent('https:' + wgServer + wgScriptPath + '/index.php?title=' + wgPageName) + '&url2=' + encodeURIComponent(foundURL)
*/