Hack Duckrace

Hack result of Duckrace game

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Hack Duckrace
// @icon        https://www.online-stopwatch.com/favicon.ico
// @namespace   Violentmonkey Scripts
// @match       https://www.online-stopwatch.com/*
// @grant       GM_registerMenuCommand
// @version     1.0
// @author      https://github.com/HoangTran0410
// @description Hack result of Duckrace game
// @license MIT
// ==/UserScript==

(() => {
  function main() {
    let targets = prompt(
      "Enter duck's name or duck's number you want to WIN:\n Split by comma ,\n E.g: 1,abc,5,20,test",
      ""
    );
    if (targets === null) return;

    targets = targets
      .split(",")
      .map((_) => _.trim())
      .filter((_) => _);

    let iframe = document.querySelector('iframe[src*="duck-race"]');

    [unsafeWindow, window, iframe?.contentWindow]
      .filter((_) => _)
      .forEach((win) => {
        if (!win.ufs_duckRace_originalShuffle)
          win.ufs_duckRace_originalShuffle = win.Array.prototype.shuffle;

        win.Array.prototype.shuffle = function () {
          const result = win.ufs_duckRace_originalShuffle.apply(
            this,
            arguments
          );
          if (result?.[0]?.instance) {
            for (let target of targets) {
              let targetIndex = result.findIndex(
                (i) => i?.name === target || i?.number == target
              );
              if (targetIndex >= 0) {
                let temp = result[0];
                result[0] = result[targetIndex];
                result[targetIndex] = temp;
                break;
              }
            }
          }
          console.log("shuffle", this, result, result[0]);
          return result;
        };
      });
  }

  GM_registerMenuCommand("Start hack", main);
})();