Skip to content

Instantly share code, notes, and snippets.

@UAVXP
Forked from SevereCloud/testpool.js
Created October 13, 2018 11:26
Show Gist options
  • Save UAVXP/499dba7d01218bd243dd1a44dbbe4374 to your computer and use it in GitHub Desktop.
Save UAVXP/499dba7d01218bd243dd1a44dbbe4374 to your computer and use it in GitHub Desktop.

Revisions

  1. @SevereCloud SevereCloud revised this gist Oct 12, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions testpool.js
    Original file line number Diff line number Diff line change
    @@ -233,6 +233,7 @@ function PixelBot() {
    PixelBot.reload();
    PixelBot.pts = 60;
    } else if (PixelBot.inited && PixelBot.canvas) {
    PixelBot.reload();
    PixelBot.pts--;
    PixelBot.draw();
    }
  2. @SevereCloud SevereCloud revised this gist Oct 12, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions testpool.js
    Original file line number Diff line number Diff line change
    @@ -120,8 +120,8 @@ function PixelBot() {
    var colorEl = qe('.color[style="background-color: ' + color + ';"]');
    if (!colorEl) {
    console.log("ошибка подбора цвета %c " + color, 'background:' + color + ';');
    PixelBot.setState("ошибка подбора цвета " + color);
    PixelBot.state.textContent = "ошибка подбора цвета " + color;
    PixelBot.setState("ошибка подбора цвета "+ x + ", "+ y +", "+ color);
    PixelBot.state.textContent = "ошибка подбора цвета "+ x + ", "+ y +", "+ color;
    return PixelBot.draw();
    } else if (pxColor == color) {
    //console.log("совпал цвет " + x + "x" + y + "%c " + pxColor, 'background:' + pxColor + ';');
  3. @SevereCloud SevereCloud revised this gist Oct 12, 2018. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions testpool.js
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ function PixelBot() {
    PixelBot.pts = 60;
    PixelBot.v = 3.0;
    PixelBot.tc = "rgb(17, 17, 17)";
    PixelBot.src = "https://id0.pw/pixel.png";
    PixelBot.src = "https://id0.pw/pixel-logo.png?" + parseInt(new Date().getTime()/1000);

    PixelBot.state = document.createElement("div");
    PixelBot.state.textContent = "Загрузка приложения...";
    @@ -146,6 +146,7 @@ function PixelBot() {
    console.log(x + "x" + y + "%c " + pxColor + " > %c " + color + " " + xy, 'background:' + pxColor + ';', 'background:' + color + ';');
    console.log("поставил точку " + x + "x" + y + " " + xy);
    PixelBot.state.textContent = "поставил точку " + x + "x" + y + " " + xy;
    PixelBot.canvasMoveTo(x+1500,y+750);
    };

    PixelBot.draw = function() {
    @@ -154,8 +155,10 @@ function PixelBot() {
    console.log("точек нет");
    } else {
    if (PixelBot.pixs.length < 20) {
    px = PixelBot.pixs.shift();
    console.log("pop")
    px = PixelBot.pixs.pop();
    } else {
    console.log("splice")
    px = PixelBot.pixs.splice(PixelBot.pixs.length - Math.floor(Math.random() * 20), 1)[0];
    }
    PixelBot.canvasClick(px[0], px[1], px[2]);
  4. @SevereCloud SevereCloud revised this gist Oct 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion testpool.js
    Original file line number Diff line number Diff line change
    @@ -156,7 +156,7 @@ function PixelBot() {
    if (PixelBot.pixs.length < 20) {
    px = PixelBot.pixs.shift();
    } else {
    px = PixelBot.pixs.splice(Math.floor(Math.random() * 20), 1)[0];
    px = PixelBot.pixs.splice(PixelBot.pixs.length - Math.floor(Math.random() * 20), 1)[0];
    }
    PixelBot.canvasClick(px[0], px[1], px[2]);
    }
  5. @SevereCloud SevereCloud revised this gist Oct 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion testpool.js
    Original file line number Diff line number Diff line change
    @@ -153,7 +153,7 @@ function PixelBot() {
    if (!PixelBot.pixs.length) {
    console.log("точек нет");
    } else {
    if (PixelBot.pixs.length < 5) {
    if (PixelBot.pixs.length < 20) {
    px = PixelBot.pixs.shift();
    } else {
    px = PixelBot.pixs.splice(Math.floor(Math.random() * 20), 1)[0];
  6. @SevereCloud SevereCloud revised this gist Oct 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion testpool.js
    Original file line number Diff line number Diff line change
    @@ -156,7 +156,7 @@ function PixelBot() {
    if (PixelBot.pixs.length < 5) {
    px = PixelBot.pixs.shift();
    } else {
    px = PixelBot.pixs.splice(Math.floor(Math.random() * 5), 1)[0];
    px = PixelBot.pixs.splice(Math.floor(Math.random() * 20), 1)[0];
    }
    PixelBot.canvasClick(px[0], px[1], px[2]);
    }
  7. @SevereCloud SevereCloud revised this gist Oct 12, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions testpool.js
    Original file line number Diff line number Diff line change
    @@ -96,6 +96,7 @@ function PixelBot() {

    canvas = ctx = null;
    console.log("перезагрузил зону защиты." + PixelBot.pixs.length + "px");
    PixelBot.state.textContent = "перезагрузил зону защиты." + PixelBot.pixs.length + "px";
    };
    PixelBot.img.src = PixelBot.src + "?r=" + Math.random();
    PixelBot.img2.src = "https://pixel.vkforms.ru/data/1.bmp?r=" + Math.random();
    @@ -120,6 +121,7 @@ function PixelBot() {
    if (!colorEl) {
    console.log("ошибка подбора цвета %c " + color, 'background:' + color + ';');
    PixelBot.setState("ошибка подбора цвета " + color);
    PixelBot.state.textContent = "ошибка подбора цвета " + color;
    return PixelBot.draw();
    } else if (pxColor == color) {
    //console.log("совпал цвет " + x + "x" + y + "%c " + pxColor, 'background:' + pxColor + ';');
    @@ -143,6 +145,7 @@ function PixelBot() {
    var xy = document.querySelectorAll(".App__statistic .value")[1].textContent;
    console.log(x + "x" + y + "%c " + pxColor + " > %c " + color + " " + xy, 'background:' + pxColor + ';', 'background:' + color + ';');
    console.log("поставил точку " + x + "x" + y + " " + xy);
    PixelBot.state.textContent = "поставил точку " + x + "x" + y + " " + xy;
    };

    PixelBot.draw = function() {
    @@ -204,6 +207,7 @@ function PixelBot() {
    PixelBot.init = function() {
    PixelBot.inited = 1;
    console.log("запущен.");
    PixelBot.state.textContent = "запущен";
    };

    PixelBot.wait = setInterval(function() {
  8. @SevereCloud SevereCloud created this gist Oct 11, 2018.
    268 changes: 268 additions & 0 deletions testpool.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,268 @@
    // ==UserScript==
    // @name Pixel Bot
    // @namespace https://tampermonkey.net/
    // @version 3.0
    // @description try to take over the world!
    // @author Flyink13, igoose
    // @match https://pixel.vkforms.ru/*
    // @grant none
    // ==/UserScript==

    function PixelBot() {
    //window.PixelBot = PixelBot;

    function qe(x) {
    if(!document.querySelectorAll(x)) return false;
    return document.querySelectorAll(x)[0];
    }

    PixelBot.pts = 60;
    PixelBot.v = 3.0;
    PixelBot.tc = "rgb(17, 17, 17)";
    PixelBot.src = "https://id0.pw/pixel.png";

    PixelBot.state = document.createElement("div");
    PixelBot.state.textContent = "Загрузка приложения...";
    console.log("Загрузка приложения...");
    Object.assign(PixelBot.state.style, {
    background: "rgba(0,0,0,0.5)",
    top: "0px",
    right: "0px",
    width: "100%",
    height: "100%",
    lineHeight: "57px",
    textAlign: "center",
    color: "#fff",
    position: "fixed",
    zIndex: 10000
    });
    document.body.appendChild(PixelBot.state);

    PixelBot.loger = document.createElement("div");
    Object.assign(PixelBot.loger.style, {
    background: "rgba(0,0,0,0)",
    top: "0px",
    left: "0px",
    width: "250px",
    height: "100%",
    color: "#fff",
    position: "fixed",
    borderRight: "1px solid #fff",
    fontSize: "11px",
    padding: "12px",
    zIndex: 10001,
    overflow: "auto",
    boxSizing: "border-box"
    });
    document.body.appendChild(PixelBot.loger);

    PixelBot.log = function(x) {
    PixelBot.loger.innerHTML += x + "<br>";
    // PixelBot.loger.scrollTo(0, 10000);
    };

    PixelBot.setState = function(s) {
    PixelBot.state.innerHTML = "PixelBot (" + PixelBot.v + ") " + s;
    // PixelBot.log(s);
    };

    PixelBot.reloadImage = function() {
    PixelBot.img = new Image();
    PixelBot.img2 = new Image();
    var canvas = document.createElement("canvas"),
    ctx = canvas.getContext("2d");
    PixelBot.img.crossOrigin = "Anonymous";
    PixelBot.img.onload = PixelBot.img2.onload = function() {
    this.loaded = this.src;
    if(PixelBot.img.src != PixelBot.img.loaded || PixelBot.img2.src != PixelBot.img2.loaded) return;
    canvas.width = PixelBot.img.width;
    canvas.height = PixelBot.img.height;
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.drawImage(PixelBot.img, 0, 0, canvas.width, canvas.height);
    var imd = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
    ctx.drawImage(PixelBot.img2, 0, 0, canvas.width, canvas.height);
    var imd2 = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
    PixelBot.pixs = [];
    for (var i = 0; i < imd.length; i += 4) {
    var x = (i / 4) % canvas.width + 1,
    y = ~~((i / 4) / canvas.width) + 1;
    if (PixelBot.getColor(imd, i) !== PixelBot.tc && PixelBot.getColor(imd2, i) !== PixelBot.getColor(imd, i)) {
    PixelBot.pixs.push([x, y, PixelBot.getColor(imd, i)]);
    }
    }
    PixelBot.pixs = PixelBot.pixs
    .sort(function (a, b) { return a[1] - b[1]; })
    .sort(function (a, b) { return b[0] - a[0]; });

    canvas = ctx = null;
    console.log("перезагрузил зону защиты." + PixelBot.pixs.length + "px");
    };
    PixelBot.img.src = PixelBot.src + "?r=" + Math.random();
    PixelBot.img2.src = "https://pixel.vkforms.ru/data/1.bmp?r=" + Math.random();
    };

    PixelBot.canvasEvent = function(type, q) {
    if (!PixelBot.canvas) return;
    if (type == "mousewheel") {
    PixelBot.canvas.dispatchEvent(new WheelEvent("mousewheel", q));
    } else {
    PixelBot.canvas.dispatchEvent(new MouseEvent(type, q));
    }
    };

    PixelBot.canvasClick = function(x, y, color) {
    PixelBot.resetZoom();
    PixelBot.canvasMoveTo(0, 0);
    PixelBot.resetZoom(-200);
    PixelBot.canvasMove(-5 * x + 5, -5 * y - 1);
    var pxColor = PixelBot.getColor(PixelBot.ctx.getImageData(3, 3, 1, 1).data, 0);
    var colorEl = qe('.color[style="background-color: ' + color + ';"]');
    if (!colorEl) {
    console.log("ошибка подбора цвета %c " + color, 'background:' + color + ';');
    PixelBot.setState("ошибка подбора цвета " + color);
    return PixelBot.draw();
    } else if (pxColor == color) {
    //console.log("совпал цвет " + x + "x" + y + "%c " + pxColor, 'background:' + pxColor + ';');
    //PixelBot.setState("пропускаю " + x + "x" + y + " совпал цвет");
    return PixelBot.draw();
    }
    colorEl.click();
    var q = {
    bubbles: true,
    cancelable: true,
    button: 1,
    clientX: 0,
    clientY: 0
    };
    PixelBot.canvasEvent("mousedown", q);
    PixelBot.canvasEvent("click", q);
    PixelBot.canvasEvent("mousemove", q);
    q.button = 0;
    PixelBot.canvasEvent("mouseup", q);
    qe(".App__confirm button").click();
    var xy = document.querySelectorAll(".App__statistic .value")[1].textContent;
    console.log(x + "x" + y + "%c " + pxColor + " > %c " + color + " " + xy, 'background:' + pxColor + ';', 'background:' + color + ';');
    console.log("поставил точку " + x + "x" + y + " " + xy);
    };

    PixelBot.draw = function() {
    var px = 0;
    if (!PixelBot.pixs.length) {
    console.log("точек нет");
    } else {
    if (PixelBot.pixs.length < 5) {
    px = PixelBot.pixs.shift();
    } else {
    px = PixelBot.pixs.splice(Math.floor(Math.random() * 5), 1)[0];
    }
    PixelBot.canvasClick(px[0], px[1], px[2]);
    }
    };

    //alert = function() {
    // location.reload();
    //};

    PixelBot.canvasMove = function(x, y) {
    var q = {
    bubbles: true,
    cancelable: true,
    button: 1,
    clientX: 0,
    clientY: 0
    };
    PixelBot.canvasEvent("mousedown", q);
    q.clientY = y;
    q.clientX = x;
    PixelBot.canvasEvent("mousemove", q);
    PixelBot.canvasEvent("mouseup", q);
    };

    PixelBot.canvasMoveTo = function(x, y) {
    PixelBot.canvasMove(10000, 10000);
    PixelBot.canvasMove(-40 - x, -149 - y);
    };

    PixelBot.getColor = function(data, i) {
    return "rgb(" + data[i] + ", " + data[i + 1] + ", " + data[i + 2] + ")";
    };

    PixelBot.resetZoom = function(d) {
    PixelBot.canvasEvent("mousewheel", {
    deltaY: d || 100000,
    deltaX: d || 0,
    clientX: 0,
    clientY: 0,
    });
    };

    PixelBot.isTimer = function() {
    if(!qe(".Ttl .Ttl__wait")) return false;
    return [qe(".Ttl .Ttl__wait"), qe(".Ttl .Ttl__wait").style.display];
    };

    PixelBot.init = function() {
    PixelBot.inited = 1;
    console.log("запущен.");
    };

    PixelBot.wait = setInterval(function() {
    if (!PixelBot.inited && PixelBot.canvas) {
    // console.log('hm 1')
    PixelBot.ctx = PixelBot.canvas.getContext("2d");
    PixelBot.init();
    } else if (!PixelBot.pts) {
    // console.log('hm 2')
    PixelBot.reload();
    PixelBot.pts = 60;
    } else if (PixelBot.canvas && PixelBot.isTimer()) {
    // console.log('hm 3')
    PixelBot.timer = 1;
    } else if (!PixelBot.canvas) {
    // console.log('hm 4')
    PixelBot.canvas = Array.prototype.slice.call(document.querySelectorAll('canvas'))[0];
    } else if (!PixelBot.pts) {
    // console.log('hm 5')
    PixelBot.reload();
    PixelBot.pts = 60;
    } else if (PixelBot.inited && PixelBot.canvas) {
    PixelBot.pts--;
    PixelBot.draw();
    }
    }, 500);

    PixelBot.reload = function() {
    // PixelBot.state.outerHTML = "";
    // PixelBot.loger.outerHTML = "";
    // clearInterval(PixelBot.wait);
    // var script = document.createElement('script');
    // script.src = "https://raw.githubusercontent.com/one2go/lentachbot/master/lentachbot.js";
    // document.body.appendChild(script);
    // script.outerHTML = "";
    PixelBot.reloadImage();
    };

    // PixelBot.state.onclick = PixelBot.reload;
    // PixelBot.loger.onclick = PixelBot.reload;
    PixelBot.reloadImage();
    console.log("PixelBot loaded");
    }

    function sleep (time) {
    return new Promise((resolve) => setTimeout(resolve, time));
    }

    sleep(2000).then(() => {
    // var script = document.createElement('script');
    // script.appendChild(document.createTextNode('(' + PixelBot + ')();'));
    // (document.body || document.head || document.documentElement).appendChild(script);
    // script.outerHTML = "";
    PixelBot();
    });
    // window.addEventListener("load", function() {
    // window.loaded = 1;
    // var script = document.createElement('script');
    // script.appendChild(document.createTextNode('(' + PixelBot + ')();'));
    // (document.body || document.head || document.documentElement).appendChild(script);
    // script.outerHTML = "";
    // });