[GC | BETA] - Bilge Dice Keyboard Controls

Keyboard controls for Bilge Dice. Streak tracking removed after it was implemented on-site.

当前为 2024-01-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        [GC | BETA] - Bilge Dice Keyboard Controls
// @namespace   https://greasyfork.org/en/users/1225524-kaitlin
// @match       https://www.grundos.cafe/games/bilgedice/*
// @license     MIT
// @version     2.2
// @grant       GM_getValue
// @grant       GM_setValue
// @author      Cupkait
// @description Keyboard controls for Bilge Dice. Streak tracking removed after it was implemented on-site.
// ==/UserScript==

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

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