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

Keyboard controls for Bilge Dice, including streak tracking.

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

  1. // ==UserScript==
  2. // @name [GC | BETA] - Bilge Dice Streak Tracking & Keyboard Controls
  3. // @namespace https://greasyfork.org/en/users/1225524-kaitlin
  4. // @match https://www.grundos.cafe/games/bilgedice/*
  5. // @license MIT
  6. // @version 2.0
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @author Cupkait
  10. // @description Keyboard controls for Bilge Dice, including streak tracking.
  11. // ==/UserScript==
  12.  
  13. const getStreakCount = () => GM_getValue("StreakCount", 0);
  14. const setStreakCount = count => GM_setValue("StreakCount", count);
  15. const updateStreakCount = () => getStreakCount();
  16.  
  17. const displayStreakCount = () => {
  18. const streakCountElement = document.createElement("div");
  19. streakCountElement.style.paddingBottom = "5px";
  20. streakCountElement.style.fontSize = "14px";
  21. const gameWindow = document.getElementById("page_content");
  22. streakCountElement.id = "streak-count-display";
  23. streakCountElement.textContent = `Streak Count: ${updateStreakCount()}`;
  24. gameWindow.insertAdjacentElement('afterbegin', streakCountElement);
  25.  
  26. };
  27.  
  28. const activeGame = document.querySelector("#bilge-dice-user-wrapper");
  29. const gameStart = document.querySelector("form.mt-1");
  30.  
  31. function indexElements(elements, type) {
  32. if (elements) {
  33. const maxCount = Math.min(elements.length, 6);
  34.  
  35. elements.forEach((element, index) => {
  36. const key = (index + 1).toString();
  37.  
  38. const label = document.createElement('label');
  39. label.textContent = key;
  40. label.style.fontWeight = 'bold';
  41. label.style.fontSize = '10px';
  42. label.style.color = 'black';
  43. label.style.background = 'EEEEEE';
  44. label.style.marginRight = '1px';
  45.  
  46. element.parentNode.insertBefore(label, element);
  47. });
  48. }
  49. }
  50.  
  51. const roundStatusElement = document.querySelector("#bilge-dice-inner > div.bilge-dice-wrapper-5 > div:nth-child(1) > div");
  52.  
  53. if (roundStatusElement) {
  54. const roundStatus = roundStatusElement.innerText.toLowerCase();
  55.  
  56. if (roundStatus.startsWith("you won")) {
  57. setStreakCount(getStreakCount() + 1);
  58. } else if (roundStatus.includes("you tied") || roundStatus.includes("oh no") || roundStatus.includes("you lose")) {
  59. setStreakCount(0);
  60. }
  61.  
  62. displayStreakCount();
  63. } else {
  64. displayStreakCount();
  65. }
  66.  
  67. if (activeGame) {
  68. indexElements(activeGame.querySelectorAll('input[type="checkbox"]'), 'dice');
  69.  
  70. document.addEventListener('keydown', event => {
  71. const key = event.key;
  72.  
  73. if (key >= '1' && key <= '6') {
  74. const index = parseInt(key) - 1;
  75. const checkboxes = activeGame.querySelectorAll('input[type="checkbox"]');
  76. if (checkboxes.length > 0 && index < checkboxes.length) {
  77. checkboxes[index].checked = !checkboxes[index].checked;
  78. checkboxes[index].dispatchEvent(new Event('change', {
  79. bubbles: true
  80. }));
  81. }
  82. }
  83.  
  84. if (key === 'Enter') {
  85. const submitButton = activeGame.querySelector('input[type="submit"]');
  86. if (submitButton) {
  87. submitButton.click();
  88. }
  89. }
  90. });
  91. } else if (gameStart) {
  92. indexElements(gameStart.querySelectorAll('input[type="submit"]'), 'ante');
  93.  
  94. document.addEventListener('keydown', event => {
  95. const key = event.key;
  96.  
  97. if (key >= '1' && key <= '6') {
  98. const index = parseInt(key) - 1;
  99. const placeAnte = document.querySelectorAll('#page_content > div:nth-child(5) > form input[type="submit"]');
  100. if (placeAnte.length > 0 && index < placeAnte.length) {
  101. placeAnte[index].click();
  102. }
  103. }
  104. });
  105. } else {
  106. document.addEventListener('keydown', event => {
  107. const key = event.key;
  108.  
  109. if (key === 'Enter') {
  110. const endGame = document.querySelector('#page_content');
  111. const submitButton = endGame.querySelector('input[type="submit"]');
  112. if (submitButton) {
  113. submitButton.click();
  114. }
  115. }
  116. });
  117. }