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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GC - Games Points til Max NP
// @namespace    https://greasyfork.org/en/users/1202961-13ulbasaur
// @version      0.3
// @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)
// @author       You
// @match        https://www.grundos.cafe/games/html5/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant        none
// @license      MIT
// ==/UserScript==

//Set up the observer for when np changes
const npElement = document.getElementById('np_earned');
const config = { attributes: true, childList: true, subtree: true };
    const gameInfo = document.querySelector('div.games-info div.bg-action')
    let featuredGame = false;
try {
 featuredGame = document.querySelector('strong.green.large-font').innerText.includes('This game is featured');
}
catch{
}

gameInfo.querySelector('div:nth-child(2)').insertAdjacentHTML('beforebegin',`<span id="npToEarn" style='text-align:center'></span>`)
const npToEarnElem = document.getElementById('npToEarn')
// Callback function to execute when mutations are observed
const callback = (mutationList, observer) => {
  for (const mutation of mutationList) {
      console.log(`mutation type: ${mutation.type}`);
      updatePoints();
  }
};

// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(npElement, config);

function updatePoints() {
    // Your code here...
    //Get the np per points info
    let npPerPoints = Number(gameInfo.querySelector('div:first-child span:first-child strong:nth-child(2)').textContent.replaceAll(/(?=NP).*/gi,'').replaceAll(',','').trim());
    if (featuredGame) {
        npPerPoints = npPerPoints*2;
    }
    //Get max NP
    const maxNP = Number(gameInfo.querySelector('div:last-child span:first-child strong:last-child').textContent.replaceAll(',','').trim());
   //Get the remaining NP to obtain
    const npRemaining = maxNP-Number(document.getElementById('np_earned').textContent.replaceAll('NP','').replaceAll(',','').trim());
    let pointsToEarn;

    if (npRemaining > 0) {
    //Points to get calculation:
    //Rounded up since I dont think any games have decimal point points.
       pointsToEarn = Math.ceil(npRemaining/npPerPoints)
    }
    else {
        pointsToEarn = 'All Done!'
    }
    npToEarnElem.innerHTML = `Points to Max:<br><strong>${pointsToEarn}</strong>`;
}
updatePoints();