Survev Randomiser

make survev.io unpredictable

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Survev Randomiser
// @namespace    https://survev.io/
// @version      1.0.0
// @description  make survev.io unpredictable
// @author       piesimp
// @match        *://survev.io/*
// @match        *://*.survev.io/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(() => {
  "use strict";

  const K = "survev-randomiser",
    L = {
      off: [0, "No randomization. Everything stays normal."],
      low: [
        0.25,
        "About 25% of guns/ammo get swapped. Most items look correct.",
      ],
      medium: [0.5, "About half are randomized. Common mislabels."],
      high: [0.75, "Around 75% randomized. Hard to trust item names/icons."],
      chaos: [1, "Attempts to randomize everything. Full confusion mode."],
    };

  let c = { level: "medium", seed: "" + Date.now() };
  try {
    Object.assign(c, JSON.parse(localStorage.getItem(K) || "{}"));
  } catch {}

  const r = ((s) => {
      let h = 2166136261 >>> 0;
      for (let i = 0; i < s.length; i++)
        h = Math.imul(h ^ s.charCodeAt(i), 16777619);
      return () => {
        h += 0x6d2b79f5;
        let t = Math.imul(h ^ (h >>> 15), h | 1);
        t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
        return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
      };
    })(c.seed),
    S = (a) => {
      for (let i = a.length - 1; i > 0; i--) {
        let j = Math.floor(r() * (i + 1));
        [a[i], a[j]] = [a[j], a[i]];
      }
      return a;
    };

  const ui = () => {
    let n = document.getElementById("news-block");
    if (!n) return;

    n.innerHTML = `<div id=news><h3 class=news-header style="color:#ffc400!important;margin-bottom:15px">Survev Randomiser</h3><div style="display:flex;flex-direction:column;gap:15px;padding:10px"><div style="display:flex;align-items:center;justify-content:space-between"><span style="font-weight:bold;font-size:14px">Intensity:</span><select id=sr-lvl style="background:#222;color:#fff;border:1px solid #555;padding:5px;border-radius:4px;cursor:pointer">${Object.keys(
      L,
    )
      .map(
        (x) =>
          `<option value=${x} ${c.level == x ? "selected" : ""}>${x.toUpperCase()}</option>`,
      )
      .join(
        "",
      )}</select></div><div id=sr-desc style="font-size:12px;color:#ccc;line-height:1.4;min-height:40px;background:rgba(0,0,0,.2);padding:8px;border-radius:4px">${L[c.level][1]}</div><button id=sr-btn style="padding:10px;background:#ffc400;color:#000;border:none;font-weight:bold;border-radius:4px;cursor:pointer;text-transform:uppercase">Apply & Reload</button></div></div>`;

    let s = document.getElementById("sr-lvl"),
      d = document.getElementById("sr-desc");

    s.onchange = () => (d.innerText = L[s.value][1]);

    document.getElementById("sr-btn").onclick = () => {
      localStorage.setItem(
        K,
        JSON.stringify({
          level: s.value,
          seed: "" + Date.now(),
        }),
      );
      location.reload();
    };
  };

  (async () => {
    let i = setInterval(() => {
        if (document.getElementById("news-block")) {
          ui();
          clearInterval(i);
        }
      }, 100),
      m = [...document.querySelectorAll('script[type="module"]')].find(
        (x) => x.src && !/turnstile|captcha/i.test(x.src),
      )?.src;

    if (!m) return;

    try {
      let t = await fetch(m).then((r) => r.text()),
        p = t.match(/from\s*["']\.\/([^"']+)["']/)?.[1];

      if (!p) return;

      let o = await import(new URL(p, m).href),
        d = o?.H;

      if (!d) return;

      let g = [],
        a = [];

      for (let k in d)
        d[k]?.type == "gun" && d[k].lootImg
          ? g.push(k)
          : d[k]?.type == "ammo" && d[k].lootImg && a.push(k);

      let v = L[c.level][0],
        M = (l) => {
          let m = {};
          l.forEach((x) => (m[x] = x));

          if (v <= 0) return m;

          let s = S([...l]).slice(0, Math.max(2, Math.floor(l.length * v))),
            p = [...s];

          p.push(p.shift());

          s.forEach((x, i) => (m[x] = p[i]));

          return m;
        };

      let f = { ...M(g), ...M(a) },
        snap = {};

      [...g, ...a].forEach(
        (x) =>
          (snap[x] = {
            n: d[x].name,
            i: JSON.parse(JSON.stringify(d[x].lootImg)),
          }),
      );

      for (let x in f) {
        let t = snap[f[x]];

        d[x].name = t.n;
        d[x].lootImg = JSON.parse(JSON.stringify(t.i));
      }

      if (o.t?.prototype) {
        let old = o.t.prototype.translate,
          k = Object.keys(f).sort((a, b) => b.length - a.length);

        o.t.prototype.translate = function (x) {
          if (typeof x != "string") return old.apply(this, arguments);

          for (let p of ["game-hud-", "game-"])
            if (x.startsWith(p)) {
              let t = x.slice(p.length);

              for (let i of k)
                if (t == i || t.startsWith(i + "-"))
                  return old.call(this, p + f[i] + t.slice(i.length));
            }

          return old.call(this, x);
        };
      }
    } catch (e) {
      console.error("SR Error:", e);
    }
  })();
})();