Difference between revisions of "User:Moussekateer/vector.js"
Moussekateer (talk | contribs) m (blockdelete rewrite) |
Moussekateer (talk | contribs) m (fix POST requests) |
||
Line 17: | Line 17: | ||
// use deletetoken in POST request to delete page | // use deletetoken in POST request to delete page | ||
− | api. | + | api.post({ action: 'delete', title: title, reason: 'Spam', token: deletetoken }).then(function (res) { |
console.log('LOG: deleted=' + title); | console.log('LOG: deleted=' + title); | ||
}); | }); | ||
Line 51: | Line 51: | ||
console.log('LOG: blocktoken=' + blocktoken); | console.log('LOG: blocktoken=' + blocktoken); | ||
− | api. | + | api.post({ action: 'block', user: user, expiry: 'never', nocreate: '', autoblock: '', reason: 'Spamming links to external sites', token: blocktoken }).then(function (res) { |
console.log('LOG: blocked=' + user); | console.log('LOG: blocked=' + user); | ||
}); | }); |
Latest revision as of 23:37, 3 July 2016
//// START SPAMBOT KILLER /// // create mw API object for wiki queries var api = new mw.Api(); function deletePage(title) { // query to get deletetoken var promise = api.get({ action: 'query', prop: 'info', intoken: 'delete', titles: title }); promise.then(function (res) { console.log('LOG: deletetokenres=' + res); var pages = res.query.pages; for (var key in pages) { var deletetoken = pages[key].deletetoken; // use deletetoken in POST request to delete page api.post({ action: 'delete', title: title, reason: 'Spam', token: deletetoken }).then(function (res) { console.log('LOG: deleted=' + title); }); } }); } function killContributions(contribs) { console.log('LOG: usercontribs=' + contribs); for (var edit in contribs) { // only delete contribution if new page if ('new' in contribs[edit]) { console.log('LOG: usercontribtodelete=' + contribs[edit]); deletePage(contribs[edit].title); } } } function blockUser(user) { // query to get blocktoken var promise = api.get({ action: 'query', prop: 'info', intoken: 'block', titles: 'User:' + user }); promise.then(function (res) { console.log('LOG: blocktokenres=' + res); var pages = res.query.pages; for (key in pages){ // use blocktoken in POST request to block user var blocktoken = pages[key].blocktoken; console.log('LOG: blocktoken=' + blocktoken); api.post({ action: 'block', user: user, expiry: 'never', nocreate: '', autoblock: '', reason: 'Spamming links to external sites', token: blocktoken }).then(function (res) { console.log('LOG: blocked=' + user); }); } }); } function killUser(user) { // query user details var promise = api.get({ action: 'query', list: 'usercontribs', ucuser: user }); promise.then(function (res) { var userContributions = res.query.usercontribs; if (userContributions.length > 5){ alert('User:' + user + ' has more than 5 edits'); } else { // hit it doc blockUser(user); killContributions(userContributions); // vas gud alert('User:' + user + ' has been terminated. Good day'); } }); } function pootSecretSauce() { // insert blockdelete link in new page revision details $('.mw-usertoollinks a:last-child').after(" | <a href=# id='blockdelete'>blockdelete</a>"); $('a#blockdelete').click(function() { // grab username from revision details var user = $('.diff-ntitle .mw-userlink').text(); console.log('LOG: User=' + user); killUser(user); }); } $(pootSecretSauce); /// END SPAMBOT KILLER ///