[GC | BETA] - Bilge Dice Streak Tracking & Keyboard Controls

Keyboard controls for Bilge Dice, including streak tracking.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        [GC | BETA] - Bilge Dice Streak Tracking & Keyboard Controls
// @namespace   https://greasyfork.org/en/users/1225524-kaitlin
// @match       https://www.grundos.cafe/games/bilgedice/*
// @license     MIT
// @version     2.0
// @grant       GM_getValue
// @grant       GM_setValue
// @author      Cupkait
// @description Keyboard controls for Bilge Dice, including streak tracking.
// ==/UserScript==

const getStreakCount = () => GM_getValue("StreakCount", 0);
const setStreakCount = count => GM_setValue("StreakCount", count);
const updateStreakCount = () => getStreakCount();

const displayStreakCount = () => {
	const streakCountElement = document.createElement("div");
	streakCountElement.style.paddingBottom = "5px";
	streakCountElement.style.fontSize = "14px";
	const gameWindow = document.getElementById("page_content");
	streakCountElement.id = "streak-count-display";
	streakCountElement.textContent = `Streak Count: ${updateStreakCount()}`;
	gameWindow.insertAdjacentElement('afterbegin', streakCountElement);

};

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

function indexElements(elements, type) {
	if (elements) {
		const maxCount = Math.min(elements.length, 6);

		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);
		});
	}
}

const roundStatusElement = document.querySelector("#bilge-dice-inner > div.bilge-dice-wrapper-5 > div:nth-child(1) > div");

if (roundStatusElement) {
	const roundStatus = roundStatusElement.innerText.toLowerCase();

	if (roundStatus.startsWith("you won")) {
		setStreakCount(getStreakCount() + 1);
	} else if (roundStatus.includes("you tied") || roundStatus.includes("oh no") || roundStatus.includes("you lose")) {
		setStreakCount(0);
	}

	displayStreakCount();
} else {
	displayStreakCount();
}

if (activeGame) {
	indexElements(activeGame.querySelectorAll('input[type="checkbox"]'), 'dice');

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

		if (key >= '1' && key <= '6') {
			const index = parseInt(key) - 1;
			const checkboxes = activeGame.querySelectorAll('input[type="checkbox"]');
			if (checkboxes.length > 0 && index < checkboxes.length) {
				checkboxes[index].checked = !checkboxes[index].checked;
				checkboxes[index].dispatchEvent(new Event('change', {
					bubbles: true
				}));
			}
		}

		if (key === 'Enter') {
			const submitButton = activeGame.querySelector('input[type="submit"]');
			if (submitButton) {
				submitButton.click();
			}
		}
	});
} else if (gameStart) {
	indexElements(gameStart.querySelectorAll('input[type="submit"]'), 'ante');

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

		if (key >= '1' && key <= '6') {
			const index = parseInt(key) - 1;
			const placeAnte = document.querySelectorAll('#page_content > div:nth-child(5) > form input[type="submit"]');
			if (placeAnte.length > 0 && index < placeAnte.length) {
				placeAnte[index].click();
			}
		}
	});
} else {
	document.addEventListener('keydown', event => {
		const key = event.key;

		if (key === 'Enter') {
			const endGame = document.querySelector('#page_content');
			const submitButton = endGame.querySelector('input[type="submit"]');
			if (submitButton) {
				submitButton.click();
			}
		}
	});
}