User:ערן/plagiabot.js

//For easier tagging in User:EranBot/Copyright/rc (function{ if (!mw.config.get('wgPageName').startsWith(mw.config.get('plagiabotPage') || 'User:EranBot/Copyright/rc')) return;	function reportStatus( status, $context ){		var reportDiv = $context.parents('.plagiabot-entry');		var diffHref = reportDiv.find('a[href^="//'+location.host+'/w/index.php?title="]:first').prop('href');		var diffId = /diff=([0-9]+)/.exec(diffHref)[1];		var api = new mw.Api;		api.get({ action:'query', prop:'revisions', titles: mw.config.get('wgPageName'), rvprop:'content', }).then(function(data){ var rv; for(rv in data.query.pages) {				var statusParam = 'status ='; var origText = data.query.pages[rv].revisions[0]['*']; var diffIndex = origText.indexOf('diff = '+diffId); var statusLine = origText.indexOf(statusParam, diffIndex) var newText = origText.substr(0, statusLine+statusParam.length)+status+origText.substr(origText.indexOf('\n',statusLine)); reportDiv.animate({opacity: 0.25}, 1000); api.postWithToken('edit', {					action: 'edit', 					title: mw.config.get('wgPageName'),					summary: status,					text: newText				}).done(function{					reportDiv.hide; //hide already reported					mw.notify('New status saved.');				}); }		});	}	function updateTagsView	{		var selectedTags = $('.plagiabot-tag-checkbox:checked').map(function{return this.value}).toArray;		var selectedEntries = [], nonSelectedEntries = [];		$('.plagiabot-entry').each(function{ var tags = $(this).find('.plagiabot-tag').text.split(';'); var isSelected = false; for(var i=0; i < tags.length && !isSelected;i++) { isSelected = selectedTags.indexOf(tags[i]) != -1; } if (isSelected) selectedEntries.push(this); else nonSelectedEntries.push(this); });		$(selectedEntries).show		$('.plagiabot-entry:visible').prev('h2').show;		$(nonSelectedEntries).hide;		$('.plagiabot-entry:hidden').prev('h2').hide;	}

function addTagSelectors { var currentTags = {} $('.plagiabot-tag').each(function{			var entryTags = $(this).text.split(';');			for(var i=0;i').click(updateTagsView).val(tagList[tagIndex]); var tagLabel = $(' ').text(tagList[tagIndex]); $tagSelection.append($(' ').append(tagCheckbox).append(tagLabel).wrap('li')); }		$('.plagiabot-entry:first').before($tagSelection); $tagSelection.makeCollapsible({collapsed:true}); $tagSelection.before($(' Select all ').click(function{ $('.plagiabot-tag-checkbox').prop('checked', true);updateTagsView; })); $tagSelection.before($(' Unselect all ').click(function{ $('.plagiabot-tag-checkbox').prop('checked', false);updateTagsView; })); } actionButtons = $(' ').css('float','right');

reportOk = $(' FP No copyvio ').addClass('mw-ui-button mw-ui-constructive').click(function{	reportStatus('FP', $(this)); }); reportCopyright = $(' TP Copyvio ').addClass('mw-ui-button mw-ui-destructive').click(function{	reportStatus('TP', $(this)); }) actionButtons.append(reportOk) actionButtons.append(reportCopyright) $('.plagiabot-details').prepend(actionButtons); mw.loader.using(['mediawiki.ui.checkbox', 'jquery.makeCollapsible'], addTagSelectors); });