[GC | BETA] - 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-01-05 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name [GC | BETA] - Bilge Dice Keyboard Controls & Tracking Enhancements
  3. // @namespace https://greasyfork.org/en/users/1225524-kaitlin
  4. // @match https://www.grundos.cafe/games/bilgedice/*
  5. // @license MIT
  6. // @version 2.2.1
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @author Cupkait
  10. // @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.
  11. // ==/UserScript==
  12.  
  13. const activeGame = document.querySelector("#bilge-dice-user-wrapper");
  14. const gameStart = document.querySelector("form.mt-1");
  15.  
  16. //CHANGE BELOW TO HAVE ENTER DEFAULT TO A SPECIFIC ANTE AMOUNT
  17. //** Don't set a default higher than you've unlocked or it won't work!
  18. //1=10 NP, 2=50 NP,3=100 NP, 4=200 NP, 5=500 NP,6=1000 NP
  19. const defaultAnteIndex = 6;
  20.  
  21. function indexElements(elements, type) {
  22. if (elements) {
  23. const maxCount = Math.min(elements.length, 6);
  24.  
  25. elements.forEach((element, index) => {
  26. const key = (index + 1).toString();
  27.  
  28. const label = document.createElement('label');
  29. label.textContent = key;
  30. label.style.fontWeight = 'bold';
  31. label.style.fontSize = '10px';
  32. label.style.color = 'black';
  33. label.style.background = 'EEEEEE';
  34. label.style.marginRight = '1px';
  35.  
  36. element.parentNode.insertBefore(label, element);
  37. });
  38. }
  39. }
  40.  
  41. function createPlayStreakDiv() {
  42. const playStreakDiv = document.createElement('div');
  43. playStreakDiv.textContent = `${GM_getValue("playStreak", "N/A")}`;
  44. return playStreakDiv;
  45. }
  46.  
  47. function handleCheckboxEvent(key, checkboxes) {
  48. const index = parseInt(key) - 1;
  49. if (checkboxes.length > 0 && index < checkboxes.length) {
  50. checkboxes[index].checked = !checkboxes[index].checked;
  51. checkboxes[index].dispatchEvent(new Event('change', {
  52. bubbles: true
  53. }));
  54. }
  55. }
  56.  
  57. function handleEnterKeyEvent(buttonSelector) {
  58. const button = document.querySelector(buttonSelector);
  59. if (button) {
  60. button.click();
  61. }
  62. }
  63.  
  64. if (activeGame) {
  65. const pageContent = document.querySelector('#page_content');
  66. pageContent.appendChild(createPlayStreakDiv());
  67. indexElements(activeGame.querySelectorAll('input[type="checkbox"]'), 'dice');
  68.  
  69. document.addEventListener('keydown', event => {
  70. const key = event.key;
  71.  
  72. if (key >= '1' && key <= '6') {
  73. handleCheckboxEvent(key, activeGame.querySelectorAll('input[type="checkbox"]'));
  74. }
  75.  
  76. if (key === 'Enter') {
  77. handleEnterKeyEvent('#bilge-dice-user-wrapper input[type="submit"]');
  78. }
  79. });
  80. } else if (gameStart) {
  81. const playStreakElement = document.querySelector("#page_content > div:nth-child(6) > p:nth-child(1)");
  82. const playStreak = playStreakElement ? playStreakElement.textContent : null;
  83.  
  84. if (playStreak) {
  85. GM_setValue("playStreak", playStreak);
  86. }
  87.  
  88. const pageContent = document.querySelector('#page_content');
  89. pageContent.appendChild(createPlayStreakDiv());
  90. indexElements(gameStart.querySelectorAll('input[type="submit"]'), 'ante');
  91.  
  92. document.addEventListener('keydown', event => {
  93. const key = event.key;
  94.  
  95. if (key >= '1' && key <= '6') {
  96. handleEnterKeyEvent('#page_content > div:nth-child(5) > form input[type="submit"]');
  97. }
  98.  
  99. if (key === 'Enter') {
  100. // Click the option based on defaultAnteIndex
  101. const options = gameStart.querySelectorAll('input[type="submit"]');
  102. const selectedOption = options[defaultAnteIndex - 1];
  103. if (selectedOption) {
  104. selectedOption.click();
  105. }
  106. }
  107. });
  108. } else {
  109. const pageContent = document.querySelector('#page_content');
  110. if (pageContent) {
  111. pageContent.appendChild(createPlayStreakDiv());
  112. }
  113.  
  114. document.addEventListener('keydown', event => {
  115. if (event.key === 'Enter') {
  116. handleEnterKeyEvent('#page_content input[type="submit"]');
  117. }
  118. });
  119. }