Code:
javascript:(function () {
if (!window.location.href.endsWith('=ranking')) {
alert('Please run this script on the =ranking page.');
return;
}
const urlParams = new URLSearchParams(window.location.search);
const server = window.location.hostname;
const village = urlParams.get('village');
async function fetchData(url) {
const response = await fetch(url);
const text = await response.text();
const parser = new DOMParser();
return parser.parseFromString(text, 'text/html');
}
async function collectPlayerData() {
let currentPage = 1;
let players = {};
while (true) {
const url = `${window.location.origin}/game.php?village=${village}&screen=ranking&page=${currentPage}`;
const doc = await fetchData(url);
const playerLinks = doc.querySelectorAll('a[href*="screen=info_player&id="]');
playerLinks.forEach(link => {
const playerId = new URL(link.href).searchParams.get('id');
players[link.textContent.trim()] = playerId;
});
const nextPageLink = doc.querySelector(`a[href*="screen=ranking&page=${currentPage + 1}"]`);
if (!nextPageLink) break;
currentPage++;
}
return players;
}
function createPopup(title, content) {
const popup = document.createElement('div');
popup.style.position = 'fixed';
popup.style.top = '50%';
popup.style.left = '50%';
popup.style.transform = 'translate(-50%, -50%)';
popup.style.background = '#f4e2d0';
popup.style.border = '2px solid #b38b6d';
popup.style.padding = '20px';
popup.style.borderRadius = '8px';
popup.style.zIndex = '10000';
popup.style.width = '400px';
popup.style.boxShadow = '0px 0px 15px rgba(0, 0, 0, 0.2)';
const titleEl = document.createElement('h2');
titleEl.textContent = title;
titleEl.style.textAlign = 'center';
titleEl.style.color = '#5a3d2a';
titleEl.style.marginBottom = '10px';
popup.appendChild(titleEl);
popup.appendChild(content);
document.body.appendChild(popup);
return popup;
}
function showPlayerSelectionPopup(players) {
const content = document.createElement('div');
const dropdown = document.createElement('select');
dropdown.style.width = '100%';
dropdown.style.marginBottom = '10px';
Object.keys(players).forEach(playerName => {
const option = document.createElement('option');
option.value = players[playerName];
option.textContent = playerName;
dropdown.appendChild(option);
});
const cancelButton = document.createElement('button');
cancelButton.textContent = 'Cancel';
cancelButton.style.background = '#8b5e3c';
cancelButton.style.color = 'white';
cancelButton.style.border = 'none';
cancelButton.style.padding = '8px 12px';
cancelButton.style.marginRight = '10px';
cancelButton.style.cursor = 'pointer';
cancelButton.style.borderRadius = '4px';
cancelButton.onclick = () => document.body.removeChild(popup);
const grabberButton = document.createElement('button');
grabberButton.textContent = 'Grab Coordinates';
grabberButton.style.background = '#8b5e3c';
grabberButton.style.color = 'white';
grabberButton.style.border = 'none';
grabberButton.style.padding = '8px 12px';
grabberButton.style.cursor = 'pointer';
grabberButton.style.borderRadius = '4px';
grabberButton.onclick = async () => {
const selectedPlayerId = dropdown.value;
const coordinates = await fetchCoordinates(selectedPlayerId);
showCoordinatesPopup(coordinates);
document.body.removeChild(popup);
};
content.appendChild(dropdown);
content.appendChild(cancelButton);
content.appendChild(grabberButton);
const popup = createPopup('Carbons Coordinate Grabber', content);
}
async function fetchCoordinates(playerId) {
let currentPage = 1;
let coordinates = [];
while (true) {
const url = `${window.location.origin}/game.php?village=${village}&screen=info_player&id=${playerId}&page=${currentPage}`;
const doc = await fetchData(url);
const coordLinks = doc.querySelectorAll('a[href*="screen=info_village&id="]');
coordLinks.forEach(link => {
const coordText = link.textContent.match(/\((\d+\|\d+)\)/);
if (coordText) coordinates.push(coordText[1]);
});
const nextPageLink = doc.querySelector(`a[href*="screen=info_player&id=${playerId}&page=${currentPage + 1}"]`);
if (!nextPageLink) break;
currentPage++;
}
return coordinates;
}
function showCoordinatesPopup(coordinates) {
const content = document.createElement('div');
const textArea = document.createElement('textarea');
textArea.style.width = '360px';
textArea.style.height = '150px';
textArea.value = coordinates.join('\n');
textArea.style.marginBottom = '10px';
textArea.style.border = '1px solid #b38b6d';
textArea.style.borderRadius = '4px';
textArea.style.padding = '5px';
const cancelButton = document.createElement('button');
cancelButton.textContent = 'Cancel';
cancelButton.style.background = '#8b5e3c';
cancelButton.style.color = 'white';
cancelButton.style.border = 'none';
cancelButton.style.padding = '8px 12px';
cancelButton.style.marginRight = '10px';
cancelButton.style.cursor = 'pointer';
cancelButton.style.borderRadius = '4px';
cancelButton.onclick = () => document.body.removeChild(popup);
const copyButton = document.createElement('button');
copyButton.textContent = 'Copy';
copyButton.style.background = '#8b5e3c';
copyButton.style.color = 'white';
copyButton.style.border = 'none';
copyButton.style.padding = '8px 12px';
copyButton.style.cursor = 'pointer';
copyButton.style.borderRadius = '4px';
copyButton.onclick = () => {
navigator.clipboard.writeText(textArea.value);
document.body.removeChild(popup);
alert('Coordinates copied to clipboard.');
};
content.appendChild(textArea);
content.appendChild(cancelButton);
content.appendChild(copyButton);
const popup = createPopup('Carbons Coordinate Grabber', content);
}
async function main() {
const players = await collectPlayerData();
if (Object.keys(players).length === 0) {
alert('No players found.');
return;
}
showPlayerSelectionPopup(players);
}
main();
})();