Set Dice

Inject custom Math.random based on API response

2025-08-01 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.sleazyfork.org/scripts/544272/1633674/Set%20Dice.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Set Dice
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Inject custom Math.random based on API response
// @author       Kamu
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  const originalRandom = Math.random;

  // Variable to store the response from the API
  let apiResponse = null;

  // Function to fetch data from the API
  async function fetchApiData() {
    try {
      const response = await fetch('https://kaptenxxi2-blublublublu.hf.space/set?__sign=eyJhbGciOiJFZERTQSJ9.eyJyZWFkIjp0cnVlLCJwZXJtaXNzaW9ucyI6eyJyZXBvLmNvbnRlbnQucmVhZCI6dHJ1ZX0sIm9uQmVoYWxmT2YiOnsia2luZCI6InVzZXIiLCJfaWQiOiI2ODI2YWMwMjk3NTQ0YmNiMjI5ZTEyMGIiLCJ1c2VyIjoiS2FwdGVuWHhpMiIsInNlc3Npb25JZCI6IjY4N2VkMjQ4OTcwMTU2ODU2ZTg4ZDNjZSJ9LCJpYXQiOjE3NTQwMzE3NTksInN1YiI6Ii9zcGFjZXMvS2FwdGVuWHhpMi9ibHVibHVibHVibHUiLCJleHAiOjE3NTQxMTgxNTksImlzcyI6Imh0dHBzOi8vaHVnZ2luZ2ZhY2UuY28ifQ.hupQLCW4CWjJKTOmBdT3ZQT1U9J5RGibE7UWSkIIfyhw_gHe8sloFemfQCDemsaIxpJouqBsYml1bPVvuzFTBg&key=cuanku');
      const data = await response.json();
      apiResponse = data;
      console.log('API Response:', apiResponse);

      if (apiResponse && apiResponse.value) {
        set(apiResponse.value);
      }
    } catch (error) {
      console.error('Error fetching API data:', error);
    }
  }

  // Start making requests every second
  setInterval(fetchApiData, 1000);

  // Initial request
  fetchApiData();

  function generateFixedTotal(total, len = 9) {
    const maxTotal = len * 6;
    total = Math.min(total, maxTotal);

    const out = Array(len).fill(1);
    const freq = { 1: len };

    let sisa = total - len;
    let attempt = 0, maxAttempt = 10000;

    while (sisa > 0 && attempt < maxAttempt) {
      attempt++;
      const i = Math.floor(originalRandom() * len);
      const curr = out[i];
      if (curr >= 6) continue;

      const next = curr + 1;
      const count = freq[next] || 0;

      if (
        (count === 2 && originalRandom() > 0.2) ||
        (count === 1 && originalRandom() > 0.3) ||
        (count >= 3)
      ) {
        continue;
      }

      out[i] = next;
      freq[curr] = (freq[curr] || 0) - 1;
      freq[next] = (freq[next] || 0) + 1;

      sisa--;
    }

    if (attempt >= maxAttempt) {
      console.warn("Peringatan: distribusi tidak optimal, sisa:", sisa);
    }

    return out;
  }

  let i = 0, p = [];

  function set(tipe) {
    let total;

    if (tipe === "k") {
      total = Math.floor(originalRandom() * (31 - 20 + 1)) + 20;
    } else if (tipe === "b") {
      total = Math.floor(originalRandom() * (42 - 32 + 1)) + 32;
    } else {
      total = 30;
    }

    p = generateFixedTotal(total);
    i = 0;

    console.log("Total:", total);
    console.log("Generated array:", p);

    Math.random = () => (p[i++ % p.length] - 0.0001) / 6;

    setTimeout(() => {
      Math.random = originalRandom;
    }, 1000);
  }

  const waitForButton = setInterval(() => {
    const btn = document.querySelector('[jsname="puTT7d"]');
    if (btn) {
      clearInterval(waitForButton);
      btn.addEventListener('click', () => {
        if (apiResponse && apiResponse.value) {
          set(apiResponse.value);
        } else {
          set("k");
        }
      });
    }
  }, 500);
})();