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. Currently doesn't account for computer science bonus (hoping to add it soon once I get comp sci bonus myself)

当前为 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.3
  5. // @description Adds to games a quick reference of how many points you'll need to max out your remaining NP. Currently doesn't account for computer science bonus (hoping to add it soon once I get comp sci bonus myself)
  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. let featuredGame = false;
  18. try {
  19. featuredGame = document.querySelector('strong.green.large-font').innerText.includes('This game is featured');
  20. }
  21. catch{
  22. }
  23.  
  24. gameInfo.querySelector('div:nth-child(2)').insertAdjacentHTML('beforebegin',`<span id="npToEarn" style='text-align:center'></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. // Your code here...
  42. //Get the np per points info
  43. let npPerPoints = Number(gameInfo.querySelector('div:first-child span:first-child strong:nth-child(2)').textContent.replaceAll(/(?=NP).*/gi,'').replaceAll(',','').trim());
  44. if (featuredGame) {
  45. npPerPoints = npPerPoints*2;
  46. }
  47. //Get max NP
  48. const maxNP = Number(gameInfo.querySelector('div:last-child span:first-child strong:last-child').textContent.replaceAll(',','').trim());
  49. //Get the remaining NP to obtain
  50. const npRemaining = maxNP-Number(document.getElementById('np_earned').textContent.replaceAll('NP','').replaceAll(',','').trim());
  51. let pointsToEarn;
  52.  
  53. if (npRemaining > 0) {
  54. //Points to get calculation:
  55. //Rounded up since I dont think any games have decimal point points.
  56. pointsToEarn = Math.ceil(npRemaining/npPerPoints)
  57. }
  58. else {
  59. pointsToEarn = 'All Done!'
  60. }
  61. npToEarnElem.innerHTML = `Points to Max:<br><strong>${pointsToEarn}</strong>`;
  62. }
  63. updatePoints();