Difference between revisions of "User:Moussekateer/vector.js"

From Team Fortress Wiki
Jump to: navigation, search
(test)
m (fix POST requests)
 
(39 intermediate revisions by the same user not shown)
Line 1: Line 1:
importStylesheet('User:WindPower/vector.css')
+
//// START SPAMBOT KILLER ///
var viewer3d = {
 
  
dragging: null,
+
// create mw API object for wiki queries
 +
var api = new mw.Api();
  
draggingFrameX: 0,
+
function deletePage(title) {
 +
    // query to get deletetoken
  
draggingFrameY: 0,
+
    var promise = api.get({ action: 'query', prop: 'info', intoken: 'delete', titles: title });
  
viewers: [],
+
    promise.then(function (res) {
 +
        console.log('LOG: deletetokenres=' + res);
 +
        var pages = res.query.pages;
  
frameThresholdX: 10,
+
        for (var key in pages) {
 +
            var deletetoken = pages[key].deletetoken;
  
frameThresholdY: 128,
+
            // 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);
 +
            });
 +
        }
 +
    });
 +
}
  
realMod: function(x, y) {
+
function killContributions(contribs) {
 +
    console.log('LOG: usercontribs=' + contribs);
  
return ((x % y) + y) % y;
+
    for (var edit in contribs) {
 +
        // only delete contribution if new page
  
},
+
        if ('new' in contribs[edit]) {
 +
            console.log('LOG: usercontribtodelete=' + contribs[edit]);
  
init: function() {
+
            deletePage(contribs[edit].title);
 +
        }
 +
    }
 +
}
  
$('.viewer-3d').each(viewer3d.bind);
+
function blockUser(user) {
 +
    // query to get blocktoken
 +
    var promise = api.get({ action: 'query', prop: 'info', intoken: 'block', titles: 'User:' + user });
  
$(document).mouseup(viewer3d.release);
+
    promise.then(function (res) {
 +
        console.log('LOG: blocktokenres=' + res);
 +
        var pages = res.query.pages;
  
$(document).mousemove(viewer3d.move);
+
        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);
 +
            });
 +
        }
 +
    });
 +
}
  
bind: function() {
+
function killUser(user) {
 +
    // query user details
 +
    var promise = api.get({ action: 'query', list: 'usercontribs', ucuser: user });
  
var v = $(this);
+
    promise.then(function (res) {
 +
        var userContributions = res.query.usercontribs;
  
var num = viewer3d.viewers.length;
+
        if (userContributions.length > 5){
 +
            alert('User:' + user + ' has more than 5 edits');
 +
        } else {
 +
            // hit it doc
 +
            blockUser(user);
 +
            killContributions(userContributions);
  
var framesS = v.find('.viewer-3d-framemap').text().split(/,/g);
+
            // vas gud
 +
            alert('User:' + user + ' has been terminated. Good day');
 +
        }
 +
    });
 +
}
  
var frameMap = [];
+
function pootSecretSauce() {
 +
    // insert blockdelete link in new page revision details
 +
    $('.mw-usertoollinks a:last-child').after(" | <a href=# id='blockdelete'>blockdelete</a>");
  
var heightMap = [];
+
    $('a#blockdelete').click(function() {
 +
        // grab username from revision details
 +
        var user = $('.diff-ntitle .mw-userlink').text();
 +
        console.log('LOG: User=' + user);
  
var leftCropMap = [];
+
        killUser(user);
 
+
    });
var totalW = parseInt(framesS[0]);
+
}
 
 
var maxFrameW = parseInt(framesS[1]);
 
 
 
var totalH = parseInt(framesS[2]);
 
 
 
var verticalSteps = parseInt(framesS[3]);
 
 
 
var midVertical = Math.floor(verticalSteps / 2);
 
 
 
for(var f = 4; f < framesS.length; f += 3) {
 
 
 
frameMap.push(parseInt(framesS[f]));
 
 
 
heightMap.push(parseInt(framesS[f + 1]));
 
 
 
leftCropMap.push(parseInt(framesS[f + 2]));
 
 
 
}
 
 
 
var url = v.find('.viewer-3d-url').text();
 
 
 
var frameN = v.find('.viewer-3d-frame');
 
 
 
v.find('img').detach();
 
 
 
var klasses = v.attr('class').split(/ /g);
 
 
 
var startFrame = 0;
 
 
 
for(var k in klasses) {
 
 
 
if(klasses[k].substr(0, 11) == 'startframe-') {
 
 
 
startFrame = Math.min(frameMap.length - 1, Math.max(0, parseInt(klasses[k].substr(11))));
 
 
 
}
 
 
 
}
 
 
 
var viewer = {
 
 
 
node: v,
 
 
 
frameNode: frameN,
 
 
 
frameX: startFrame,
 
 
 
frameY: midVertical,
 
 
 
map: frameMap,
 
 
 
cropMap: leftCropMap,
 
 
 
width: v.width(),
 
 
 
height: v.height(),
 
 
 
totalWidth: totalW,
 
 
 
totalHeight: totalH,
 
 
 
maxFrameWidth: maxFrameW,
 
 
 
mouseX: 0,
 
 
 
mouseY: 0,
 
 
 
xStep: verticalSteps
 
 
 
};
 
 
 
viewer3d.viewers.push(viewer);
 
 
 
v.mousedown(viewer3d.drag).attr('data-id', num);
 
 
 
frameN.mousedown(viewer3d.drag).attr('data-id', num).css({
 
 
 
background: 'url(' + url + ') no-repeat top left',
 
 
 
top: Math.round((viewer.height - viewer.totalHeight) / 2) + 'px',
 
 
 
height: viewer.totalHeight + 'px'
 
 
 
});
 
 
 
viewer3d.display(viewer, viewer.frameX, viewer.frameY);
 
 
 
},
 
 
 
drag: function(e) {
 
 
 
var v = viewer3d.getViewer(this);
 
 
 
v.mouseX = e.pageX;
 
 
 
v.mouseY = e.pageY;
 
 
 
viewer3d.dragging = v;
 
 
 
draggingFrameX = v.frameX;
 
 
 
draggingFrameY = v.frameY;
 
 
 
return false;
 
 
 
},
 
 
 
release: function() {
 
 
 
var v = viewer3d.dragging;
 
 
 
viewer3d.dragging = null;
 
 
 
if(v != null) {
 
 
 
v.frameX = viewer3d.draggingFrameX;
 
 
 
v.frameY = viewer3d.draggingFrameY;
 
 
 
}
 
 
 
viewer3d.draggingFrameX = 0;
 
 
 
viewer3d.draggingFrameY = 0;
 
 
 
},
 
 
 
getViewer: function(node) {
 
 
 
return viewer3d.viewers[parseInt($(node).attr('data-id'))];
 
 
 
},
 
 
 
display: function(v, frameX, frameY) {
 
 
 
var frameID = viewer3d.realMod(frameX * v.xStep + frameY, v.map.length);
 
 
 
var frameOffset = v.map[frameID];
 
 
 
var frameWidth = 0;
 
 
 
if(frameID == v.map.length - 1) {
 
 
 
frameWidth = v.totalWidth - frameOffset;
 
  
} else {
+
$(pootSecretSauce);
  
frameWidth = v.map[frameID + 1] - frameOffset;
+
/// END SPAMBOT KILLER ///
 
 
}
 
 
 
v.frameNode.css({
 
 
 
backgroundPosition: (-frameOffset - frameID) + 'px 0px',
 
 
 
left: Math.round((v.width - v.maxFrameWidth) / 2.0 + v.cropMap[frameID]) + 'px',
 
 
 
width: frameWidth + 'px'
 
 
 
});
 
 
 
},
 
 
 
move: function(e) {
 
 
 
if(viewer3d.dragging == null) {
 
 
 
return;
 
 
 
}
 
 
 
var v = viewer3d.dragging;
 
 
 
var mouseDeltaX = e.pageX - v.mouseX;
 
 
 
var mouseDeltaY = e.pageY - v.mouseY;
 
 
 
var frameDeltaX = Math.round(mouseDeltaX / viewer3d.frameThresholdX);
 
 
 
var frameDeltaY = -Math.round(mouseDeltaY / viewer3d.frameThresholdY);
 
 
 
viewer3d.draggingFrameX = v.frameX + frameDeltaX;
 
 
 
viewer3d.draggingFrameY = Math.max(0, Math.min(v.xStep - 1, v.frameY + frameDeltaY));
 
 
 
viewer3d.display(v, viewer3d.draggingFrameX, viewer3d.draggingFrameY);
 
 
 
}
 
 
 
}
 
addOnloadHook(viewer3d.init);
 

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 ///