[GC] - Bilge Dice Keyboard Controls & Tracking Enhancements

Keyboard controls for Bilge Dice. Streak tracking tweaked so the new in-game streak is displayed during gameplay. You can now press enter to start a game with a default Ante, which is set to 10 NP unless you change it.

目前為 2024-02-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        [GC] - Bilge Dice Keyboard Controls & Tracking Enhancements
// @namespace   https://greasyfork.org/en/users/1225524-kaitlin
// @match       https://www.grundos.cafe/games/bilgedice/*
// @license     MIT
// @version     2.3
// @grant       GM_getValue
// @grant       GM_setValue
// @author      Cupkait
// @icon        https://i.imgur.com/4Hm2e6z.png
// @description Keyboard controls for Bilge Dice. Streak tracking tweaked so the new in-game streak is displayed during gameplay. You can now press enter to start a game with a default Ante, which is set to 10 NP unless you change it.
// ==/UserScript==

const activeGame = document.querySelector("#bilge-dice-user-wrapper");
const gameStart = document.querySelector("form.mt-1");

//CHANGE BELOW TO HAVE ENTER DEFAULT TO A SPECIFIC ANTE AMOUNT
//** Don't set a default higher than you've unlocked or it won't work!
//1=10 NP, 2=50 NP,3=100 NP, 4=200 NP, 5=500 NP,6=1000 NP 
const defaultAnteIndex = 1;

function indexElements(elements) {
    if (elements) {
        elements.forEach((element, index) => {
            const key = (index + 1).toString();
            const label = document.createElement('label');
            label.textContent = key;
            label.style.fontWeight = 'bold';
            label.style.fontSize = '10px';
            label.style.color = 'black';
            label.style.background = 'EEEEEE';
            label.style.marginRight = '1px';
            element.parentNode.insertBefore(label, element);
        });
    }
}

function createPlayStreakDiv() {
    const playStreakDiv = document.createElement('div');
    playStreakDiv.textContent = `${GM_getValue("playStreak", "N/A")}`;
    return playStreakDiv;
}

function handleCheckboxEvent(key, checkboxes) {
    const index = parseInt(key) - 1;
    if (checkboxes.length > 0 && index < checkboxes.length) {
        checkboxes[index].checked = !checkboxes[index].checked;
        checkboxes[index].dispatchEvent(new Event('change', { bubbles: true }));
    }
}

function handleEnterKeyEvent(buttonSelector) {
    const button = document.querySelector(buttonSelector);
    if (button) {
        button.click();
    }
}

if (activeGame) {
    const pageContent = document.querySelector('#page_content');
    pageContent.appendChild(createPlayStreakDiv());
    indexElements(activeGame.querySelectorAll('input[type="checkbox"]'));

    const submitButton = document.querySelector("#bilge-dice-user-wrapper > form");

    const spaceText = document.createElement('p');
    spaceText.textContent = '(Press Space to Keep All)';
    spaceText.style.fontSize = '10px';
    spaceText.style.width = 'auto';
    spaceText.style.fontWeight = 'bold';
    spaceText.style.textAlign = 'center';

    submitButton.insertAdjacentElement('afterend', spaceText);

    document.addEventListener('keydown', event => {
        const key = event.key;

        if (key >= '1' && key <= '6') {
            handleCheckboxEvent(key, activeGame.querySelectorAll('input[type="checkbox"]'));
        }

        if (key === ' ') {
            event.preventDefault();
            const checkboxes = activeGame.querySelectorAll('input[type="checkbox"]');
            checkboxes.forEach(checkbox => {
                checkbox.checked = !checkbox.checked;
                checkbox.dispatchEvent(new Event('change', { bubbles: true }));
            });
        }

        if (key === 'Enter') {
            handleEnterKeyEvent('#bilge-dice-user-wrapper input[type="submit"]');
        }
    });
} else if (gameStart) {
    const playStreakElement = document.querySelector("#page_content > div:nth-child(6) > p:nth-child(1)");
    const playStreak = playStreakElement ? playStreakElement.textContent : null;

    if (playStreak) {
        GM_setValue("playStreak", playStreak);
    }

    const pageContent = document.querySelector('#page_content');
    pageContent.appendChild(createPlayStreakDiv());
    indexElements(gameStart.querySelectorAll('input[type="submit"]'));

    document.addEventListener('keydown', event => {
        const key = event.key;

        if (key >= '1' && key <= '6') {
            handleEnterKeyEvent('#page_content > div:nth-child(5) > form input[type="submit"]');
        }

        if (key === 'Enter') {
            const options = gameStart.querySelectorAll('input[type="submit"]');
            const selectedOption = options[defaultAnteIndex - 1];
            if (selectedOption) {
                selectedOption.click();
            }
        }
    });
} else {
    const pageContent = document.querySelector('#page_content');
    if (pageContent) {
        pageContent.appendChild(createPlayStreakDiv());
    }

    document.addEventListener('keydown', event => {
        if (event.key === 'Enter') {
            handleEnterKeyEvent('#page_content input[type="submit"]');
        }
    });
}