Last active
September 13, 2024 22:48
-
-
Save ArnoldsK/ffc1d8fb2812100208aade3f07f0fbb7 to your computer and use it in GitHub Desktop.
Counts total MTX points spent in Path of Exile (https://www.pathofexile.com/my-account/microtransactions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PoE total MTX points cost | |
// @namespace https://arnoldsk.lv/ | |
// @version 2024-08-09 | |
// @description Counts total MTX points spent in Path of Exile | |
// @author ArnoldsK | |
// @match https://*.pathofexile.com/my-account/microtransactions* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=pathofexile.com | |
// @grant none | |
// ==/UserScript== | |
;(() => { | |
const handleGetCost = () => { | |
const cost = [...document.querySelectorAll(".transaction-cost")] | |
.map((el) => parseInt(el.innerText)) | |
.reduce((sum, value) => sum + value, 0) | |
const totalCost = parseInt(localStorage.getItem("totalMtxCost") ?? "0") + cost | |
localStorage.setItem("totalMtxCost", totalCost) | |
console.log("Page cost", cost, "; Total cost", totalCost) | |
const next = document.querySelector(".pagination .current").nextSibling | |
if (!next) { | |
localStorage.removeItem("handleGetCost") | |
const costInUsd = Intl.NumberFormat("en-US", { | |
style: "currency", | |
currency: "USD", | |
}).format(totalCost / 10) | |
alert(`Total MTX cost is ${totalCost} points (${costInUsd})`) | |
} else { | |
setTimeout(() => { | |
next.click() | |
}, 3_000) | |
} | |
} | |
const addButton = () => { | |
const button = document.querySelector(".button-text") | |
if (button && button.innerText.trim() === "View Account Transactions") { | |
const el = document.createElement("a") | |
el.classList.add("button-text") | |
el.classList.add("red") | |
el.innerText = "Count Total" | |
el.href = "javascript:void(0)" | |
el.addEventListener("click", () => { | |
localStorage.setItem("handleGetCost", true) | |
localStorage.setItem("totalMtxCost", 0) | |
handleGetCost() | |
}) | |
button.parentElement.insertBefore(el, button) | |
} | |
} | |
if ( | |
localStorage.getItem("handleGetCost") && | |
/\/page\/\d+/.test(location.pathname) && | |
!/\/page\/1$/.test(location.pathname) | |
) { | |
handleGetCost() | |
} else { | |
localStorage.removeItem("handleGetCost") | |
addButton() | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment