Set Dice

Inject script untuk manipulasi hasil akhir roll dadu berdasarkan API

Από την 01/08/2025. Δείτε την τελευταία έκδοση.

Αυτός ο κώδικας δεν πρέπει να εγκατασταθεί άμεσα. Είναι μια βιβλιοθήκη για άλλους κώδικες που περιλαμβάνεται μέσω της οδηγίας meta // @require https://update.sleazyfork.org/scripts/544272/1633702/Set%20Dice.js

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Set Dice
// @version      1.1
// @description  Inject script untuk manipulasi hasil akhir roll dadu berdasarkan API
// @author       Zyetaa
// @match        *://*/*
// @grant        none
// @namespace http://tampermonkey.net/
// ==/UserScript==

(function () {
    'use strict';
  
    const originalRandom = Math.random;
    let apiResponse = null;
    let isScriptActive = false;
  
    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);
      } catch (error) {
        console.error('Error fetching API data:', error);
      }
    }
  
    setInterval(fetchApiData, 1000);
    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 = 20000;
      
        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 countNext = freq[next] || 0;
      
          // Batasi maksimal kemunculan angka (kecuali terpaksa)
          const maxRepeat = Math.floor(len / 2); // misalnya: 4
          if (countNext >= maxRepeat) continue;
      
          // Prioritaskan angka yang jarang muncul
          const score = 1 / (1 + countNext);
          if (originalRandom() > score) continue;
      
          out[i] = next;
          freq[curr] = (freq[curr] || 0) - 1;
          freq[next] = (freq[next] || 0) + 1;
          sisa--;
        }
      
        if (attempt >= maxAttempt) {
          console.warn("Distribusi kurang 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);
      isScriptActive = true;
  
      Math.random = () => (p[i++ % p.length] - 0.0001) / 6;
  
      setTimeout(() => {
        isScriptActive = false;
        Math.random = originalRandom;
      }, 1000);
    }
  
    // Tunggu hingga tombol tersedia di DOM
    const interval = setInterval(() => {
      const btn = document.querySelector('[jsname="puTT7d"]');
      if (btn) {
        clearInterval(interval);
        btn.addEventListener('click', () => {
          if (apiResponse && apiResponse.value) {
            set(apiResponse.value);
          } else {
            set("k");
          }
        });
      }
    }, 500);
  })();