Last active
March 4, 2025 15:49
-
-
Save Wedz0ff/51eef6ae2b2935a9b660420ea5aac1f0 to your computer and use it in GitHub Desktop.
Tampermonkey script to get your Tibia Coin Spent History.
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 Tibia Coin History Scrapper | |
// @namespace https://github.com/Wedz0ff | |
// @version 1.0 | |
// @description Scrapes how many Tibia Coins you spent on XP Boosts/Preys, additionally it saves all history as well. | |
// @author Wed | |
// @match https://www.tibia.com/account/?subtopic=accountmanagement&page=tibiacoinshistory¤tpage=* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const uniqueId = localStorage.getItem("scraperId") || Math.random().toString(36).substr(2, 9); | |
localStorage.setItem("scraperId", uniqueId); | |
let currentPage = parseInt(localStorage.getItem(`currentPage_${uniqueId}`)) || 1; | |
let scrapedData = JSON.parse(localStorage.getItem(`scrapedData_${uniqueId}`)) || []; | |
let total_xp_boost = parseInt(localStorage.getItem(`total_xp_boost_${uniqueId}`)) || 0; | |
let total_prey_wildcards = parseInt(localStorage.getItem(`total_prey_wildcards_${uniqueId}`)) || 0; | |
let total = parseInt(localStorage.getItem(`total_${uniqueId}`)) || 0; | |
function getMaxPages() { | |
const lastPageLink = $("a[href*='currentpage=']:contains('Last Page')").attr("href"); | |
if (lastPageLink) { | |
const match = lastPageLink.match(/currentpage=(\d+)/); | |
if (match) { | |
return parseInt(match[1]); | |
} | |
} | |
return 1; | |
} | |
function scrapeData() { | |
const result = $("#accountmanagement > div.Border_2 > div > div > div:nth-child(4) > table > tbody > tr > td > div > table > tbody > tr > td > div > table > tbody > tr").map((i, element) => { | |
const id = $(element).find('td:nth-of-type(1)').text().trim(); | |
if (!/^[0-9]+$/.test(id)) return null; | |
const desc = $(element).find('td:nth-of-type(3)').text().trim(); | |
const balance = parseInt($(element).find('td:nth-of-type(5)').text().trim().replace(/,/g, '')) || 0; | |
if (desc === "XP Boost") { | |
total_xp_boost += balance | |
} else if (/Prey Wildcard/.test(desc)) { | |
total_prey_wildcards += balance; | |
} | |
total = total_xp_boost + total_prey_wildcards; | |
return { | |
id, | |
date: $(element).find('td:nth-of-type(2)').text().trim(), | |
desc, | |
character: $(element).find('td:nth-of-type(4)').text().trim(), | |
balance | |
}; | |
}).get().filter(Boolean); | |
scrapedData.push(...result); | |
localStorage.setItem(`scrapedData_${uniqueId}`, JSON.stringify(scrapedData)); | |
localStorage.setItem(`total_xp_boost_${uniqueId}`, total_xp_boost); | |
localStorage.setItem(`total_prey_wildcards_${uniqueId}`, total_prey_wildcards); | |
localStorage.setItem(`total_${uniqueId}`, total); | |
console.log(`Page ${currentPage} Data:`, result); | |
console.log(`Total XP Boost:`, total_xp_boost); | |
console.log(`Total Prey Wildcards:`, total_prey_wildcards); | |
console.log(`Total Sum:`, total); | |
} | |
function nextPage() { | |
const maxPages = getMaxPages(); | |
if (currentPage >= maxPages) { | |
console.log("Scraping completed.", scrapedData); | |
console.log(`Final Total XP Boost:`, total_xp_boost); | |
console.log(`Final Total Prey Wildcards:`, total_prey_wildcards); | |
console.log(`Final Total Sum:`, total); | |
localStorage.removeItem(`currentPage_${uniqueId}`); | |
localStorage.removeItem(`scrapedData_${uniqueId}`); | |
localStorage.removeItem(`total_xp_boost_${uniqueId}`); | |
localStorage.removeItem(`total_prey_wildcards_${uniqueId}`); | |
localStorage.removeItem(`total_${uniqueId}`); | |
localStorage.removeItem("scraperId"); | |
return; | |
} | |
currentPage++; | |
localStorage.setItem(`currentPage_${uniqueId}`, currentPage); | |
window.location.href = `https://www.tibia.com/account/?subtopic=accountmanagement&page=tibiacoinshistory¤tpage=${currentPage}`; | |
} | |
setTimeout(() => { | |
scrapeData(); | |
if (currentPage < getMaxPages()) { | |
setTimeout(nextPage, 2000); | |
} | |
}, 2000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment