Sexy PoW

Supa fast PoW

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Sexy PoW
// @namespace    shadamity
// @version      1.1
// @description  Supa fast PoW
// @author       don_shadaman
// @match        https://diep.io/*
// @match        https://diep-io--two.rivet.game/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=diep.io
// @grant        GM_xmlhttpRequest
// @run-at       document-start
// ==/UserScript==

var win = typeof unsafeWindow == "undefined" ? window : unsafeWindow;

let first = true;

win.WebSocket = class extends WebSocket {
  constructor(ip) {
    super(ip);
    first = true;
  }
}

function sleep(ms) {
  return new Promise(function(resolve) {
    setTimeout(resolve, ms);
  });
}

const p = win.Worker.prototype;

p.postMessage = new Proxy(p.postMessage, {
  apply: function(to, what, args) {
    const [id, action, string, difficulty, debug] = args[0];
    if(action == "solve" && !debug) {
      const date = new Date().getTime();
      GM_xmlhttpRequest({
        method: "POST",
        url: "http://localhost:16384/",
        data: JSON.stringify({ string, difficulty }),
        headers: {
          "Content-Type": "application/json"
        },
        onload: async function(res) {
          if(!first) {
            const wait = 9000 - (new Date().getTime() - date);
            await sleep(wait);
          } else {
            first = false;
          }
          what.onmessage({ data: [id, res.responseText] });
        }
      });
    }
  }
});