GC - Games Points til Max NP

Adds to games a quick reference of how many points you'll need to max out your remaining NP and how many points you'll need to get the max amount of NP in one game.

  1. // ==UserScript==
  2. // @name GC - Games Points til Max NP
  3. // @namespace https://greasyfork.org/en/users/1202961-13ulbasaur
  4. // @version 0.5
  5. // @description Adds to games a quick reference of how many points you'll need to max out your remaining NP and how many points you'll need to get the max amount of NP in one game.
  6. // @author You
  7. // @match https://www.grundos.cafe/games/html5/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. //Set up the observer for when np changes
  14. const npElement = document.getElementById('np_earned');
  15. const config = { attributes: true, childList: true, subtree: true };
  16. const gameInfo = document.querySelector('div.games-info div.bg-action')
  17.  
  18. //Get the np per points info
  19. let npPerPointsText = gameInfo.querySelector('div:first-child span:first-child strong:nth-child(2)').textContent;
  20.  
  21. let gameBonus = Math.max(1,Number(npPerPointsText.split('×').splice(1).join('').trim()))
  22. let npPerPoints = Number(npPerPointsText.replaceAll(/(?=NP).*/gi,'').replaceAll(',','').trim());
  23. gameInfo.querySelector('div:first-child').insertAdjacentHTML('beforeend',`<span><strong>Points for Max NP</strong> : <strong style="color:green">${Math.ceil(60000/npPerPoints)}</strong></span>`);
  24. gameInfo.querySelector('div:nth-child(2)').insertAdjacentHTML('beforeend',`<span id="npToEarn"></span>`)
  25. const npToEarnElem = document.getElementById('npToEarn')
  26. // Callback function to execute when mutations are observed
  27. const callback = (mutationList, observer) => {
  28. for (const mutation of mutationList) {
  29. console.log(`mutation type: ${mutation.type}`);
  30. updatePoints();
  31. }
  32. };
  33.  
  34. // Create an observer instance linked to the callback function
  35. const observer = new MutationObserver(callback);
  36.  
  37. // Start observing the target node for configured mutations
  38. observer.observe(npElement, config);
  39.  
  40. function updatePoints() {
  41. //Get max NP
  42. const maxNP = Number(gameInfo.querySelector('div:last-child span:first-child strong:last-child').textContent.replaceAll(',','').trim());
  43. //If the maxNP is 120000, that means that the comp sci bonus is active. So the gamebonus will be an additional +1 multiplier (so x2 if not featured game, x3 if featured game)
  44. const bonusMultiplier = gameBonus + (maxNP == 120000 ? 1 : 0);
  45. //Get the remaining NP to obtain
  46. const npRemaining = maxNP-Number(document.getElementById('np_earned').textContent.replaceAll('NP','').replaceAll(',','').trim());
  47. let pointsToEarn;
  48.  
  49. if (npRemaining > 0) {
  50. //Points to get calculation:
  51. //Rounded up since I dont think any games have decimal point points.
  52. pointsToEarn = Math.ceil(npRemaining/(npPerPoints*bonusMultiplier))
  53. }
  54. else {
  55. pointsToEarn = 'All Done!'
  56. }
  57. npToEarnElem.innerHTML = `Points to NP Cap :<strong>${pointsToEarn}</strong>`;
  58. }
  59. updatePoints();