User:DannyS712 test/MEA clerk bot.js
Appearance
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:DannyS712 test/MEA clerk bot. |
//<nowiki>
$(function (){
var MEA_bot_config = {
name: '[[User:DannyS712/Missing encyclopedic articles bot|Missing encyclopedic articles bot]]',
testing: true,
disclaimer: "Bot in trial ([[Wikipedia:Bots/Requests for approval/DannyS712 bot 50|BRFA]])",
version: "1.1.1",
debug: false
};
var MEA_bot_summary = 'Task 50: Clerking with ' + MEA_bot_config.name + ' (version ' + MEA_bot_config.version + ')';
if (MEA_bot_config.testing){
MEA_bot_summary = MEA_bot_config.disclaimer + ": " + MEA_bot_summary;
}
var all_blue_links = [];
$.when(
mw.loader.using( 'mediawiki.util'),
mw.loader.getScript( '/w/index.php?title=User:DannyS712 test/page.js&action=raw&ctype=text/javascript' )
).then( function () {
$(document).ready( function () {
if ( mw.config.get('wgPageName').indexOf( 'Wikipedia:WikiProject_Missing_encyclopedic_articles/') > -1 || mw.config.get('wgPageName').indexOf( 'User:DannyS712 test/') > -1 ){
$('.mw-redirect').css( {"border": "5px solid yellow", "color": "#006600" } );
mw.util.addPortletLink ( 'p-tb', 'javascript:void(0)', 'Missing encyclopedic articles', 'ca-MEA-clerk', 'TOOLTIP');
$('#ca-MEA-clerk').on('click', function() {
MEA();
} );
}
} );
} );
function get_links(){
var blue_links = [];
var link_class = "";
var a = $('a').filter( function() {
return !(this.className.indexOf('mw-redirect') > -1 ||
this.className.indexOf('new') > -1 ||
this.className.indexOf('mw-disambig') > -1 ||
this.className.indexOf('mw-echo') > -1 ||
this.className.indexOf('mw-wiki') > -1 ||
this.className.indexOf('external text') > -1 ||
this.className.indexOf('mw-jump-link') > -1 ||
this.title.indexOf(':') > -1 ||
this.id === 'top');
} );
console.log( a );
$(a).each( function( index, value ) {
blue_links.push( value.text);
});
console.log( blue_links );
all_blue_links = blue_links;
}
function MEA(){
get_links();
console.log( all_blue_links );
var page_name = mw.config.get( 'wgPageName' );
var page_content = get_page( page_name );
console.log( page_content );
var new_content = page_content;
if (page_name.indexOf('Wikipedia:WikiProject_Missing_encyclopedic_articles/List_of_US_Newspapers/') > -1 ) {
new_content = page_content.replace(/#\s*\[\[(.*?)\]\]\s*\[\[(?:.*?)\]\].*\n?/g, check_line );
} else if (page_name === 'Wikipedia:WikiProject_Missing_encyclopedic_articles/Dsp13_List/24' ) {
new_content = page_content.replace(/#\s*\[\[(.*?)\]\]\s*\|\s*\[(?:.*?) DAH\]\s*\|\n?/g, check_line );
} else if (page_name === 'Wikipedia:WikiProject_Missing_encyclopedic_articles/Dsp13_List/23' ||
page_name === 'Wikipedia:WikiProject_Missing_encyclopedic_articles/Dsp13_List/25' ||
page_name === 'Wikipedia:WikiProject_Missing_encyclopedic_articles/Dsp13_List/26' ||
page_name === 'Wikipedia:WikiProject_Missing_encyclopedic_articles/Dsp13_List/22' ||
/^Wikipedia:WikiProject_Missing_encyclopedic_articles\/Hotlist_of_/.test( page_name ) ) {
new_content = page_content.replace(/#\s*\[\[(.*?)\]\].*\n?/g, check_line );
}
if (page_content === new_content){
console.log( "No change, skip");
} else{
console.log( "Will edit, setting new content to:", new_content );
if ( mw.config.get('wgUserName') === 'DannyS712 bot') {
set_new( page_name, new_content );
}
}
}
function check_line ( match, p1, offset, string ){
//console.log( match, p1 );
for (var iii = 0; iii < all_blue_links.length; iii++){
if (p1 === all_blue_links[iii]){
console.log( match, p1 );
return '';
}
}
return match;
}
function set_new ( page, new_content ){
if( MEA_bot_config.debug) console.log( page, new_content );
var to_send = {
action: 'edit',
title: page,
//pageid: mw.config.get( 'wgArticleId' ),
text: new_content,
notminor: true,
bot: true,
summary: MEA_bot_summary,
token: mw.user.tokens.get( 'csrfToken' )
};
console.log( to_send );
$.when(
$.post( scriptUrl, to_send, function(){ } )
).done( function() {
location.reload();
} );
}
});
//</nowiki>