Greasy Fork is available in English.
Wyświetl zrabowane surowce na profilu gracza w Tribal Wars
当前为
// ==UserScript==
// @name Tribal Wars - Zrabowane Surowce
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Wyświetl zrabowane surowce na profilu gracza w Tribal Wars
// @author Ten=Zly
// @match https://*.plemiona.pl/game.php*screen=info_player*
// @grant none
// @require http://code.jquery.com/jquery-latest.min.js
// @license GNU GPLv3
// ==/UserScript==
(function() {
'use strict';
function getPlayerName() {
const playerNameElement = document.querySelector('#content_value #player_info>tbody>tr>th');
return playerNameElement ? playerNameElement.textContent.trim() : null;
}
function fetchDailyRanking(playerName) {
return new Promise((resolve, reject) => {
$.ajax({
url: `/game.php?screen=ranking&mode=in_a_day&type=loot_res&name=${encodeURIComponent(playerName)}`,
success: (data) => {
const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
const rows = doc.querySelectorAll('#in_a_day_ranking_table tr:not(:first-child)');
for (const row of rows) {
const playerNameCell = row.querySelector('td:nth-child(2)');
const lootCell = row.querySelector('td:nth-child(4)');
const parsedPlayerName = playerNameCell ? playerNameCell.textContent.trim() : '';
if (parsedPlayerName === playerName) {
const loot = lootCell ? parseInt(lootCell.textContent.trim().replace(/,/g, '').replace('.', '')) : 0;
resolve(loot);
return;
}
}
resolve(0);
},
error: (xhr, status, error) => {
reject(error);
}
});
});
}
function displayLoot(loot) {
const container = document.querySelector('#content_value #player_info');
if (container) {
const newRow = document.createElement('tr');
newRow.innerHTML = `
<td>Zrabowane surowce (dziennie):</td>
<td><strong>${loot.toLocaleString()}</strong></td>
`;
container.appendChild(newRow);
}
}
const playerName = getPlayerName();
if (playerName) {
fetchDailyRanking(playerName)
.then(loot => {
displayLoot(loot);
})
.catch(error => {
console.error('Nie można pobrać danych o zrabowanych surowcach:', error);
});
}
})();