GC Bilge Dice Tracker

Tracks your current Bilge Dice streak. Does not work across multiple devices.

  1. // ==UserScript==
  2. // @name GC Bilge Dice Tracker
  3. // @namespace https://greasyfork.org/en/users/1175371/
  4. // @version 0.4
  5. // @description Tracks your current Bilge Dice streak. Does not work across multiple devices.
  6. // @author sanjix
  7. // @match https://www.grundos.cafe/games/bilgedice/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. var streakCount = JSON.parse(localStorage.getItem('BilgeDiceStreakCounter')) || 0;
  13. var log = JSON.parse(localStorage.getItem('BilgeDiceLog')) || [];
  14.  
  15. var game = document.querySelector('#bilge-dice-wrapper');
  16. var counterValue = document.createElement('p');
  17. var headerText = document.createElement('h4');
  18.  
  19. const WIN = 0;
  20. const TIE = 1;
  21. const LOSE = 2;
  22.  
  23. headerText.textContent = 'Current Streak:';
  24. headerText.classList.add('bilgeTracker');
  25. counterValue.textContent = streakCount;
  26. counterValue.classList.add('bilgeTracker');
  27. headerText.style.marginBottom = '5px';
  28. counterValue.style.marginTop = '5px';
  29.  
  30.  
  31. game.after(counterValue);
  32. counterValue.before(headerText);
  33.  
  34. function updateCounter(gameState) {
  35. if (gameState == WIN) {
  36. streakCount += 1;
  37. log.push('win');
  38. } else {
  39. streakCount = 0;
  40. log = [];
  41. }
  42. // } else if (gameState == TIE) {
  43. // if (log[log.length - 1] == 'tie') { // if this is the second consecutive tie, reset streak
  44. // streakCount = 0;
  45. // log = [];
  46. // } else {
  47. // log.push('tie'); // else add a tie to the log but do not alter streak
  48. // }
  49. // }
  50. counterValue.textContent = streakCount;
  51. localStorage.setItem('BilgeDiceStreakCounter', JSON.stringify(streakCount));
  52. localStorage.setItem('BilgeDiceLog', JSON.stringify(log));
  53. }
  54.  
  55.  
  56. if (document.evaluate(
  57. "count(//div[@id='bilge-dice-wrapper']//p[contains(.,'You won!')]) > 0",
  58. document,
  59. null,
  60. XPathResult.BOOLEAN_TYPE,
  61. null
  62. ).booleanValue) {
  63. updateCounter(WIN);
  64. } else if (document.evaluate(
  65. "count(//div[@id='bilge-dice-wrapper']//p[contains(.,'You tied.')]) > 0",
  66. document,
  67. null,
  68. XPathResult.BOOLEAN_TYPE,
  69. null
  70. ).booleanValue) {
  71. updateCounter(TIE);
  72. } else if (document.evaluate(
  73. "count(//div[@id='bilge-dice-wrapper']//p[contains(., 'Oh no!')]) > 0",
  74. document,
  75. null,
  76. XPathResult.BOOLEAN_TYPE,
  77. null
  78. ).booleanValue) {
  79. updateCounter(LOSE);
  80. } else if (document.evaluate(
  81. "count(//div[@id='bilge-dice-wrapper']//p[contains(., 'lose')]) > 0",
  82. document,
  83. null,
  84. XPathResult.BOOLEAN_TYPE,
  85. null
  86. ).booleanValue) {
  87. updateCounter(LOSE);
  88. }
  89.  
  90. console.log(log);