Difference between revisions of "User:Moussekateer/vector.js"
Moussekateer (talk | contribs) m (can no longer hotlink javascript from github) |
Moussekateer (talk | contribs) m (blockdelete rewrite) |
||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
//// START SPAMBOT KILLER /// | //// START SPAMBOT KILLER /// | ||
− | // create | + | // create mw API object for wiki queries |
− | var | + | var api = new mw.Api(); |
− | function deletePage(title){ | + | function deletePage(title) { |
// query to get deletetoken | // 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); | console.log('LOG: deletetokenres=' + res); | ||
− | for (var key in | + | var pages = res.query.pages; |
− | var deletetoken = | + | |
+ | for (var key in pages) { | ||
+ | var deletetoken = pages[key].deletetoken; | ||
+ | |||
// use deletetoken in POST request to delete page | // use deletetoken in POST request to delete page | ||
− | + | api.get({ action: 'delete', title: title, reason: 'Spam', token: deletetoken }).then(function (res) { | |
console.log('LOG: deleted=' + title); | console.log('LOG: deleted=' + title); | ||
}); | }); | ||
Line 364: | Line 24: | ||
} | } | ||
− | function | + | function killContributions(contribs) { |
console.log('LOG: usercontribs=' + contribs); | console.log('LOG: usercontribs=' + contribs); | ||
− | for(var edit in contribs){ | + | |
+ | for (var edit in contribs) { | ||
// only delete contribution if new page | // only delete contribution if new page | ||
− | if ('new' in contribs[edit]){ | + | |
+ | if ('new' in contribs[edit]) { | ||
console.log('LOG: usercontribtodelete=' + contribs[edit]); | console.log('LOG: usercontribtodelete=' + contribs[edit]); | ||
+ | |||
deletePage(contribs[edit].title); | deletePage(contribs[edit].title); | ||
} | } | ||
Line 375: | Line 38: | ||
} | } | ||
− | function blockUser(user){ | + | function blockUser(user) { |
// query to get blocktoken | // 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); | console.log('LOG: blocktokenres=' + res); | ||
− | for (key in | + | var pages = res.query.pages; |
+ | |||
+ | for (key in pages){ | ||
// use blocktoken in POST request to block user | // use blocktoken in POST request to block user | ||
− | var blocktoken = | + | var blocktoken = pages[key].blocktoken; |
console.log('LOG: blocktoken=' + blocktoken); | console.log('LOG: blocktoken=' + blocktoken); | ||
− | + | ||
+ | api.get({ 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); | ||
}); | }); | ||
Line 390: | Line 58: | ||
} | } | ||
− | function | + | function killUser(user) { |
// query user details | // 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(){ | + | function pootSecretSauce() { |
// insert blockdelete link in new page revision details | // insert blockdelete link in new page revision details | ||
− | $('.mw-usertoollinks a:last-child').after(" | <a href=# id='blockdelete'>blockdelete</a>") | + | $('.mw-usertoollinks a:last-child').after(" | <a href=# id='blockdelete'>blockdelete</a>"); |
− | $( | + | |
+ | $('a#blockdelete').click(function() { | ||
// grab username from revision details | // grab username from revision details | ||
var user = $('.diff-ntitle .mw-userlink').text(); | var user = $('.diff-ntitle .mw-userlink').text(); | ||
console.log('LOG: User=' + user); | console.log('LOG: User=' + user); | ||
− | + | killUser(user); | |
}); | }); | ||
} | } | ||
− | + | ||
+ | $(pootSecretSauce); | ||
+ | |||
/// END SPAMBOT KILLER /// | /// END SPAMBOT KILLER /// |
Revision as of 23:24, 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.get({ 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.get({ 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 ///