User:Moussekateer/vector.js

From Team Fortress Wiki
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
//// 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 ///