Fair Party Distribution

This overrides the biased uniform random distribution of guesstheparty.co.uk with an impartial random distribution.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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        Fair Party Distribution
// @namespace   Violentmonkey Scripts
// @icon        https://guesstheparty.co.uk/favicon.svg
// @version     1.0.0
//
// @match       *://guesstheparty.co.uk/*
// @grant       none
//
// @author      darraghd493
// @description This overrides the biased uniform random distribution of guesstheparty.co.uk with an impartial random distribution.
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    function injectCode() {
      window.partyBuckets = {};
      window.sortIntoBuckets = function() {
          if (!window.pool || window.pool.length === 0) return;

          window.partyBuckets = {};
          for (const party of window.PARTIES) {
              window.partyBuckets[party] = window.pool.filter(c => c.party === party);
          }
      };

      // hook into #load
      const originalLoad = window.load;
      window.load = async function() {
          await originalLoad();
          window.sortIntoBuckets();
          // originalLoad calls #nextRound, we call it again to
          // ensure the first candidate shown follows the new logic
          window.nextRound();
      };

      // overwrite #nextRound
      // written safely to avoid any potential issues in the future
      window.nextRound = function() {
          clearTimeout(window.advanceTimer);

          // avoid any potential bugs
          if (Object.keys(window.partyBuckets).length === 0) {
              window.sortIntoBuckets();
          }

          // select random party
          const randomPartyName = window.PARTIES[Math.floor(Math.random() * window.PARTIES.length)];
          const bucket = window.partyBuckets[randomPartyName];

          // select random politician (safely)
          if (bucket && bucket.length > 0) {
              window.current = bucket[Math.floor(Math.random() * bucket.length)];
          } else {
              window.current = window.pool[Math.floor(Math.random() * window.pool.length)];
          }

          window.answered = false;

          // ui
          window.els.reveal.classList.remove("show");
          window.els.countdown.classList.remove("run");
          for (const btn of window.els.buttons.children) {
              btn.disabled = false;
              btn.classList.remove("correct", "wrong");
          }

          window.swapPhoto(window.current.image_src);
      };
    }

    const checkInterval = setInterval(() => { // wait for the necessary page stuff to load - lazy solution lol
          if (window.PARTIES && window.pool && window.nextRound) {
              clearInterval(checkInterval);
              injectCode();
          }
      }, 50);
})();