Difference between revisions of "User:Jacky720/common.js"
(Oh hey, the local nobody.) |
|||
Line 31: | Line 31: | ||
const arr = data.query.usercontribs; | const arr = data.query.usercontribs; | ||
console.log(arr); | console.log(arr); | ||
− | const interval = setInterval(function() { | + | if (arr.length > 100) { |
− | + | const interval = setInterval(function() { | |
− | + | const rev = arr.shift(); | |
− | + | if (!rev) { | |
− | + | clearInterval(interval); | |
− | + | window.location.reload(); | |
− | } | + | return; |
− | this.getRevisionIdAndContent(rev.title, rev.user); | + | } |
− | + | this.getRevisionIdAndContent(rev.title, rev.user); | |
− | + | console.log(arr.length); | |
+ | }.bind(this), 50); | ||
+ | } else { | ||
+ | const interval = setInterval(function() { | ||
+ | const rev = arr.shift(); | ||
+ | if (!rev) { | ||
+ | clearInterval(interval); | ||
+ | //window.location.reload(); | ||
+ | return; | ||
+ | } | ||
+ | this.getRevisionIdAndContent(rev.title, rev.user); | ||
+ | console.log(arr.length); | ||
+ | }.bind(this), 50); | ||
+ | } | ||
}.bind(this)); | }.bind(this)); | ||
}, | }, |
Revision as of 21:17, 4 May 2022
console.log("your JS loaded it didn't do anything"); /** * Rollback * @description Perform rollbacks without needing to be in the usergroup * @author Ozank */ (function() { 'use strict'; // Exit if normal rollback links are present or the wiki disabled the script if ($('.mw-rollback-link').length || window.RollbackWikiDisable) { return; } var Rollback = $.extend(window.Rollback, { config: mw.config.get([ 'wgAction', 'wgCanonicalSpecialPageName', 'wgPageName' ]), user: 'Ex Kay Cee Dee', _preload: 1, preload: function() { if (--this._preload === 0) { this.init(); } }, init: function() { this.api = new mw.Api(); this.performRollbackCallback = this.performRollbackCallback .bind(this); this.getTop().then(function(data) { const arr = data.query.usercontribs; console.log(arr); if (arr.length > 100) { const interval = setInterval(function() { const rev = arr.shift(); if (!rev) { clearInterval(interval); window.location.reload(); return; } this.getRevisionIdAndContent(rev.title, rev.user); console.log(arr.length); }.bind(this), 50); } else { const interval = setInterval(function() { const rev = arr.shift(); if (!rev) { clearInterval(interval); //window.location.reload(); return; } this.getRevisionIdAndContent(rev.title, rev.user); console.log(arr.length); }.bind(this), 50); } }.bind(this)); }, getTop: function() { return this.api.get({ action: 'query', list: 'usercontribs', ucuser: this.user, uctoponly: 1, uclimit: 'max' }); }, getRevisionIdAndContent: function(title, target) { this.api.get({ action: 'query', cb: Date.now(), indexpageids: 1, prop: 'revisions', rvlimit: 'max', rvprop: 'user|ids', titles: title }).done(this.getRevisionIdCallback.bind(this, target)).fail( this.outputError.bind(this, 'revisionFail') ); }, getRevisionIdCallback: function(target, data) { if (data.error) { this.outputError('revisionFail', data.error.code); return; } var revisions = data.query.pages[data.query.pageids[0]].revisions; // Don't rollback if the page has been edited by somebody else if (target !== revisions[0].user) { console.log('edit conflict'); // this.outputError('editConflict'); return; } var lastUser, revId; for (var i in revisions) { if (revisions[i].user !== target) { // Remember last author lastUser = revisions[i].user; // Get revision to revert to revId = revisions[i].revid; break; } } if (!lastUser) { this.outputError('singleEditor'); return; } this.api.get({ action: 'query', cb: Date.now(), indexpageids: 1, prop: 'revisions', revids: revId, rvprop: 'content' }).done( this.getRevisionContentCallback.bind(this, target, lastUser) ).fail( this.outputError.bind(this, 'contentFail', undefined) ); }, getRevisionContentCallback: function(target, lastUser, data) { if (data.error) { this.outputError('contentFail', data.error.code); return; } // Can be no content on page var page = data.query.pages[data.query.pageids[0]], content = page.revisions ? page.revisions[0]['*'] : ''; this.performRollback(page.title, content, target, lastUser); }, performRollback: function(page, text, user, user2) { this.api.post({ action: 'edit', bot: true, minor: true, summary: 'rv', text: text, title: page, token: mw.user.tokens.get('editToken') }).done(this.performRollbackCallback).fail( this.outputError.bind(this, 'editFail') ); }, performRollbackCallback: function(data) { if (data.error) { this.outputError('editFail', data.error.code); } else { // mw.notify('Reverted successfully'); } }, outputError: function(message, code) { mw.notify('error: ' + message + ' ' + code, { type: 'error' }); } }); mw.loader.using([ 'mediawiki.api', 'mediawiki.user', 'mediawiki.util', 'mediawiki.notification' ], Rollback.preload.bind(Rollback)); })(); console.log("no of course it did something");