Changes

Jump to: navigation, search

User:BecaBot/common.js

471 bytes added, 6 years ago
Cleanup. Use custom array method to iterate over the pages.
// <nowiki>
/**
* Redirect script.
* @description:
* Redirect {{Template:Set list}} card numbers to the respective page.
* @author:
* [[User:Becasita]]
*/
// </nowiki>(function(window, $, mw, log, delayconsole) {
"use strict";
*/
var DELAYTIME;
const LAST_LOG = '00:00, 13 March 2018 (UTC)';
const conf = mw.config.get([
'wgNamespaceNumber',
]);
conf.API = function(query, callbacks, method) {
return new mw.Api()[method || 'get'](query) .done(callbacks[0] || callbacks.done) .fail(callbacks[1] || callbacks.fail) .always(callbacks[2] || callbacks.always);
};
const $rightNavUl = $('#right-navigation').find('#p-views').find('ul');
 
/** Extend Array prototype: */
Array.prototype.delayedEach = function ( delay, callback, thisArg ) {
if ( typeof delay === 'function' ) {
[ delay, callback, thisArg ] = [ 10, delay, callback ];
}
const self = this.slice();
let remaining = self.length;
let index = 0;
const execute = function( item, interval ) {
if ( remaining-- ) {
callback.call( thisArg, item, index++, this );
} else {
clearInterval(interval);
}
};
execute( self[index] );
const interval = window.setInterval( function() {
execute( self[index], interval );
}, delay );
};
/**
const description = 'Redirected page to [[' + redirectTo + ']].';
const text = '#REDIRECT [[' + redirectTo + ']] {{R from card number}}';
console.log('%cEdit start!', 'color: blue;'); console.log('\tEditing:', pageName);
const query = {
action: 'edit',
const callbacks = {
done: function() {
console.log('%cEdit success!', 'color: green;'); console.log('\tDescription:', description); console.log('\tContent:', text);
},
fail: function(message, errorObject) {
console.log('%cEdit error!', 'color: red;', '(message, errorObject)'); console.log(message); console.log(errorObject);
},
always: function() {
console.log('%cEdit finished!', 'color: blue;'); console.log('\tEdited:', pageName); console.log('%c--------------', 'color: blue;');
}
};
// Create the redirects:
function createRedirects(redirectsMap) {
const pagesToRedirect = Object.keys(redirectsMap); (function editLoopWithDelay(pagesToRedirect) { delay.delayedEach(DELAYTIME, function(page) { const page = pagesToRedirect console.shift(); log('%c--------------', 'color: blue;'); edit(page, redirectsMap[page]); if (pagesToRedirect.length) { editLoopWithDelay(pagesToRedirect); } }); })(pagesToRedirect);
}
// Get content function:
},
fail: function(message, errorObject) {
console.log('%cContent fetch error!', 'color: red;', '(message, errorObject)'); console.log(message); console.log(errorObject);
},
always: function() {
console.log('Content fetched!');
}
};
function init() {
DELAYTIME = prompt('Delay time between edits:') || 2000;
console.log('----------------------------'); console.log('Starting creating redirects!');
getContent();
}
});
return /** * Return. */ console.log('Redirect %cRedirect script loaded.: '+ LAST_LOG, '(00color:57, 11 February 2018 (UTC))blue;') || true;
})(thiswindow, thiswindow.jQuery, thiswindow.mediaWiki, thiswindow.console.log, function(n, f) { this.setTimeout(f, n);});
Bureaucrats, System administrator, Administrators
57,479
edits

Navigation menu