[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.

  1. // ==UserScript==
  2. // @name [GC] - 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.3
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @author Cupkait
  10. // @icon https://i.imgur.com/4Hm2e6z.png
  11. // @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.
  12. // ==/UserScript==
  13.  
  14. const activeGame = document.querySelector("#bilge-dice-user-wrapper");
  15. const gameStart = document.querySelector("form.mt-1");
  16.  
  17. //CHANGE BELOW TO HAVE ENTER DEFAULT TO A SPECIFIC ANTE AMOUNT
  18. //** Don't set a default higher than you've unlocked or it won't work!
  19. //1=10 NP, 2=50 NP,3=100 NP, 4=200 NP, 5=500 NP,6=1000 NP
  20. const defaultAnteIndex = 1;
  21.  
  22. function indexElements(elements) {
  23. if (elements) {
  24. elements.forEach((element, index) => {
  25. const key = (index + 1).toString();
  26. const label = document.createElement('label');
  27. label.textContent = key;
  28. label.style.fontWeight = 'bold';
  29. label.style.fontSize = '10px';
  30. label.style.color = 'black';
  31. label.style.background = 'EEEEEE';
  32. label.style.marginRight = '1px';
  33. element.parentNode.insertBefore(label, element);
  34. });
  35. }
  36. }
  37.  
  38. function createPlayStreakDiv() {
  39. const playStreakDiv = document.createElement('div');
  40. playStreakDiv.textContent = `${GM_getValue("playStreak", "N/A")}`;
  41. return playStreakDiv;
  42. }
  43.  
  44. function handleCheckboxEvent(key, checkboxes) {
  45. const index = parseInt(key) - 1;
  46. if (checkboxes.length > 0 && index < checkboxes.length) {
  47. checkboxes[index].checked = !checkboxes[index].checked;
  48. checkboxes[index].dispatchEvent(new Event('change', { bubbles: true }));
  49. }
  50. }
  51.  
  52. function handleEnterKeyEvent(buttonSelector) {
  53. const button = document.querySelector(buttonSelector);
  54. if (button) {
  55. button.click();
  56. }
  57. }
  58.  
  59. if (activeGame) {
  60. const pageContent = document.querySelector('#page_content');
  61. pageContent.appendChild(createPlayStreakDiv());
  62. indexElements(activeGame.querySelectorAll('input[type="checkbox"]'));
  63.  
  64. const submitButton = document.querySelector("#bilge-dice-user-wrapper > form");
  65.  
  66. const spaceText = document.createElement('p');
  67. spaceText.textContent = '(Press Space to Keep All)';
  68. spaceText.style.fontSize = '10px';
  69. spaceText.style.width = 'auto';
  70. spaceText.style.fontWeight = 'bold';
  71. spaceText.style.textAlign = 'center';
  72.  
  73. submitButton.insertAdjacentElement('afterend', spaceText);
  74.  
  75. document.addEventListener('keydown', event => {
  76. const key = event.key;
  77.  
  78. if (key >= '1' && key <= '6') {
  79. handleCheckboxEvent(key, activeGame.querySelectorAll('input[type="checkbox"]'));
  80. }
  81.  
  82. if (key === ' ') {
  83. event.preventDefault();
  84. const checkboxes = activeGame.querySelectorAll('input[type="checkbox"]');
  85. checkboxes.forEach(checkbox => {
  86. checkbox.checked = !checkbox.checked;
  87. checkbox.dispatchEvent(new Event('change', { bubbles: true }));
  88. });
  89. }
  90.  
  91. if (key === 'Enter') {
  92. handleEnterKeyEvent('#bilge-dice-user-wrapper input[type="submit"]');
  93. }
  94. });
  95. } else if (gameStart) {
  96. const playStreakElement = document.querySelector("#page_content > div:nth-child(6) > p:nth-child(1)");
  97. const playStreak = playStreakElement ? playStreakElement.textContent : null;
  98.  
  99. if (playStreak) {
  100. GM_setValue("playStreak", playStreak);
  101. }
  102.  
  103. const pageContent = document.querySelector('#page_content');
  104. pageContent.appendChild(createPlayStreakDiv());
  105. indexElements(gameStart.querySelectorAll('input[type="submit"]'));
  106.  
  107. document.addEventListener('keydown', event => {
  108. const key = event.key;
  109.  
  110. if (key >= '1' && key <= '6') {
  111. handleEnterKeyEvent('#page_content > div:nth-child(5) > form input[type="submit"]');
  112. }
  113.  
  114. if (key === 'Enter') {
  115. const options = gameStart.querySelectorAll('input[type="submit"]');
  116. const selectedOption = options[defaultAnteIndex - 1];
  117. if (selectedOption) {
  118. selectedOption.click();
  119. }
  120. }
  121. });
  122. } else {
  123. const pageContent = document.querySelector('#page_content');
  124. if (pageContent) {
  125. pageContent.appendChild(createPlayStreakDiv());
  126. }
  127.  
  128. document.addEventListener('keydown', event => {
  129. if (event.key === 'Enter') {
  130. handleEnterKeyEvent('#page_content input[type="submit"]');
  131. }
  132. });
  133. }