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.

当前为 2023-11-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GC - Games Points til Max NP
  3. // @namespace https://greasyfork.org/en/users/1202961-13ulbasaur
  4. // @version 0.2
  5. // @description Adds to games a quick reference of how many points you'll need to max out your remaining NP.
  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. gameInfo.querySelector('div:nth-child(2)').insertAdjacentHTML('beforebegin',`<span id="npToEarn" style='text-align:center'></span>`)
  19. const npToEarnElem = document.getElementById('npToEarn')
  20. // Callback function to execute when mutations are observed
  21. const callback = (mutationList, observer) => {
  22. for (const mutation of mutationList) {
  23. console.log(`mutation type: ${mutation.type}`);
  24. updatePoints();
  25. }
  26. };
  27.  
  28. // Create an observer instance linked to the callback function
  29. const observer = new MutationObserver(callback);
  30.  
  31. // Start observing the target node for configured mutations
  32. observer.observe(npElement, config);
  33.  
  34. function updatePoints() {
  35. // Your code here...
  36. //Get the np per points info
  37. const npPerPoints = Number(gameInfo.querySelector('div:first-child span:first-child strong:nth-child(2)').textContent.replaceAll(/(?=NP).*/gi,'').replaceAll(',','').trim());
  38. //Get max NP
  39. const maxNP = Number(gameInfo.querySelector('div:last-child span:first-child strong:last-child').textContent.replaceAll(',','').trim());
  40. //Get the remaining NP to obtain
  41. const npRemaining = maxNP-Number(document.getElementById('np_earned').textContent.replaceAll('NP','').replaceAll(',','').trim());
  42. let pointsToEarn;
  43.  
  44. if (npRemaining > 0) {
  45. //Points to get calculation:
  46. //Rounded up since I dont think any games have decimal point points.
  47. pointsToEarn = Math.ceil(npRemaining/npPerPoints)
  48. }
  49. else {
  50. pointsToEarn = 'All Done!'
  51. }
  52. npToEarnElem.innerHTML = `Points to Max:<br><strong>${pointsToEarn}</strong>`;
  53. }
  54. updatePoints();