User:ערן/plagiabot.js
Appearance
< User:ערן
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:ערן/plagiabot. |
//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<entryTags.length;i++){ currentTags[entryTags[i]] = 1; }
});
var tagList = [];
for(var tag in currentTags) { tagList.push(tag); }
tagList = tagList.sort();
var $tagSelection = $('<div></div>').css({'max-height':'400px', 'overflow':'auto', 'width': '80%', 'margin': 'auto'});
for (var tagIndex=0;tagIndex<tagList.length;tagIndex++){
var tagCheckbox = $('<input type="checkbox" class="plagiabot-tag-checkbox" name="plagiabot-tag'+tagIndex+'" id="plagiabot-tag'+tagIndex+'" checked>').click(updateTagsView).val(tagList[tagIndex]);
var tagLabel = $('<label for="plagiabot-tag'+tagIndex+'"></label>').text(tagList[tagIndex]);
$tagSelection.append($('<div class="mw-ui-checkbox"></div>').append(tagCheckbox).append(tagLabel).wrap('li'));
}
$('.plagiabot-entry:first').before($tagSelection);
$tagSelection.makeCollapsible({collapsed:true});
$tagSelection.before($('<div class="mw-ui-button">Select all</div>').click(function(){ $('.plagiabot-tag-checkbox').prop('checked', true);updateTagsView(); }));
$tagSelection.before($('<div class="mw-ui-button">Unselect all</div>').click(function(){ $('.plagiabot-tag-checkbox').prop('checked', false);updateTagsView(); }));
}
actionButtons = $('<div></div>').css('float','right');
reportOk = $('<div>FP<br><small>No copyvio</small></div>').addClass('mw-ui-button mw-ui-constructive').click(function(){
reportStatus('FP', $(this));
});
reportCopyright = $('<div>TP<br><small>Copyvio</small></div>').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);
})();