Hello There, Guest! Register

Share your scripts!
#2
here is a script that will capture all player coordinates from the users profile.


[Image: coords-capture.png]


Code:
javascript:async function fetchAllUserVillageCoordinates() {
   try {
       const playerId = extractPlayerIdFromUrl();
       if (!playerId) {
           throw new Error('Player ID not found in URL');
       }

       const initialUrl = `https://w1.infernal-wars.com/game.php?village=3&screen=info_player&id=${playerId}&page=1`;
       let nextPageUrl = initialUrl;
       let allCoordinates = [];
       let visitedPages = new Set();

       while (nextPageUrl && !visitedPages.has(nextPageUrl)) {
           visitedPages.add(nextPageUrl);
           const response = await fetch(nextPageUrl);

           if (!response.ok) {
               throw new Error(`HTTP error! Status: ${response.status}`);
           }

           const html = await response.text();
           const coordinates = parsePlayerCoordinates(html);

           allCoordinates = allCoordinates.concat(coordinates);

           nextPageUrl = getNextPageUrl(html, nextPageUrl);
       }

       const uniqueCoordinates = Array.from(new Set(allCoordinates));
       const coordinatesToDisplay = uniqueCoordinates.slice(1);

       const coordinatesText = coordinatesToDisplay.join('\n');
       displayCoordinatesPopup(coordinatesText, coordinatesToDisplay.length);
   } catch (error) {
       console.error('Error fetching user villages:', error.message);
       displayDebuggingPopup(error.message);
   }
}

function parsePlayerCoordinates(html) {
   const regex = /\((\d+)\|(\d+)\)/g;
   let match;
   const coordinates = [];

   while ((match = regex.exec(html)) !== null) {
       const x = match[1];
       const y = match[2];
       coordinates.push(`${x}|${y}`);
   }

   return coordinates;
}

function getNextPageUrl(html, currentPageUrl) {
   const tempElement = document.createElement('div');
   tempElement.innerHTML = html;

   const currentPageMatch = currentPageUrl.match(/page=(\d+)/);
   const currentPage = currentPageMatch ? parseInt(currentPageMatch[1]) : 1;

   const nextPageElement = tempElement.querySelector(`a[href*="page=${currentPage + 1}"]`);

   return nextPageElement ? nextPageElement.href : null;
}

function extractPlayerIdFromUrl() {
   const urlParams = new URLSearchParams(window.location.search);
   return urlParams.get('id');
}

function displayCoordinatesPopup(coordinatesText, totalCoordinates) {
   const coordinatesBox = createPopupBox(coordinatesText, totalCoordinates);
   document.body.appendChild(coordinatesBox);
}

function displayDebuggingPopup(debugInfo) {
   const debugBox = createDebugPopupBox(debugInfo);
   document.body.appendChild(debugBox);
}

function createPopupBox(coordinatesText, totalCoordinates) {
   const coordinatesBox = document.createElement('div');
   coordinatesBox.className = 'coordinates-popup';
   coordinatesBox.style.position = 'fixed';
   coordinatesBox.style.top = '20px';
   coordinatesBox.style.left = '20px';
   coordinatesBox.style.width = '400px';
   coordinatesBox.style.height = '300px';
   coordinatesBox.style.border = '2px solid #333';
   coordinatesBox.style.backgroundColor = '#f2f2f2';
   coordinatesBox.style.zIndex = '9999';
   coordinatesBox.style.padding = '10px';
   coordinatesBox.style.resize = 'both';
   coordinatesBox.style.overflow = 'auto';
   coordinatesBox.style.cursor = 'move';

   let offsetX = 0;
   let offsetY = 0;
   let isDragging = false;

   coordinatesBox.addEventListener('mousedown', startDrag);

   function startDrag(e) {
       isDragging = true;
       offsetX = e.clientX - coordinatesBox.getBoundingClientRect().left;
       offsetY = e.clientY - coordinatesBox.getBoundingClientRect().top;
       document.addEventListener('mousemove', drag);
       document.addEventListener('mouseup', stopDrag);
   }

   function drag(e) {
       if (isDragging) {
           coordinatesBox.style.left = `${e.clientX - offsetX}px`;
           coordinatesBox.style.top = `${e.clientY - offsetY}px`;
       }
   }

   function stopDrag() {
       isDragging = false;
       document.removeEventListener('mousemove', drag);
       document.removeEventListener('mouseup', stopDrag);
   }

   const closeButton = document.createElement('button');
   closeButton.textContent = 'Close';
   closeButton.style.position = 'absolute';
   closeButton.style.top = '10px';
   closeButton.style.right = '10px';
   closeButton.style.padding = '5px';
   closeButton.style.cursor = 'pointer';
   closeButton.addEventListener('click', () => {
       coordinatesBox.style.display = 'none';
   });
   coordinatesBox.appendChild(closeButton);

   const minimizeButton = document.createElement('button');
   minimizeButton.textContent = 'Minimize';
   minimizeButton.style.position = 'absolute';
   minimizeButton.style.top = '10px';
   minimizeButton.style.right = '70px';
   minimizeButton.style.padding = '5px';
   minimizeButton.style.cursor = 'pointer';
   minimizeButton.addEventListener('click', () => {
       coordinatesBox.style.height = '30px';
       minimizeButton.style.display = 'none';
       maximizeButton.style.display = 'block';
   });
   coordinatesBox.appendChild(minimizeButton);

   const maximizeButton = document.createElement('button');
   maximizeButton.textContent = 'Maximize';
   maximizeButton.style.display = 'none';
   maximizeButton.style.position = 'absolute';
   maximizeButton.style.top = '10px';
   maximizeButton.style.right = '70px';
   maximizeButton.style.padding = '5px';
   maximizeButton.style.cursor = 'pointer';
   maximizeButton.addEventListener('click', () => {
       coordinatesBox.style.height = '300px';
       maximizeButton.style.display = 'none';
       minimizeButton.style.display = 'block';
   });
   coordinatesBox.appendChild(maximizeButton);

   const totalCoordinatesInfo = document.createElement('p');
   totalCoordinatesInfo.textContent = 'Total Coordinates Captured';
   totalCoordinatesInfo.style.fontWeight = 'bold';
   totalCoordinatesInfo.style.fontSize = '16px';
   totalCoordinatesInfo.style.marginTop = '20px';
   coordinatesBox.appendChild(totalCoordinatesInfo);

   const totalCoordinatesNumber = document.createElement('p');
   totalCoordinatesNumber.textContent = totalCoordinates.toString();
   totalCoordinatesNumber.style.fontSize = '24px';
   totalCoordinatesNumber.style.fontWeight = 'bold';
   coordinatesBox.appendChild(totalCoordinatesNumber);

   const coordinatesTextArea = document.createElement('textarea');
   coordinatesTextArea.value = coordinatesText;
   coordinatesTextArea.setAttribute('readonly', '');
   coordinatesTextArea.style.width = '100%';
   coordinatesTextArea.style.height = 'calc(100% - 100px)';
   coordinatesTextArea.style.border = 'none';
   coordinatesTextArea.style.backgroundColor = '#f2f2f2';
   coordinatesBox.appendChild(coordinatesTextArea);

   const copyButton = document.createElement('button');
   copyButton.textContent = 'Copy All';
   copyButton.style.position = 'absolute';
   copyButton.style.bottom = '10px';
   copyButton.style.left = '10px';
   copyButton.style.padding = '5px';
   copyButton.style.cursor = 'pointer';
   copyButton.addEventListener('click', () => {
       copyToClipboard(coordinatesText);
   });
   coordinatesBox.appendChild(copyButton);

   return coordinatesBox;
}

function createDebugPopupBox(debugInfo) {
   const debugBox = document.createElement('div');
   debugBox.className = 'debug-popup';
   debugBox.style.position = 'fixed';
   debugBox.style.top = '50px';
   debugBox.style.left = '50px';
   debugBox.style.width = '400px';
   debugBox.style.height = '300px';
   debugBox.style.border = '2px solid #333';
   debugBox.style.backgroundColor = '#fff';
   debugBox.style.zIndex = '9999';
   debugBox.style.padding = '10px';
   debugBox.style.resize = 'both';
   debugBox.style.overflow = 'auto';
   debugBox.style.cursor = 'move';

   let offsetX = 0;
   let offsetY = 0;
   let isDragging = false;

   debugBox.addEventListener('mousedown', startDrag);

   function startDrag(e) {
       isDragging = true;
       offsetX = e.clientX - debugBox.getBoundingClientRect().left;
       offsetY = e.clientY - debugBox.getBoundingClientRect().top;
       document.addEventListener('mousemove', drag);
       document.addEventListener('mouseup', stopDrag);
   }

   function drag(e) {
       if (isDragging) {
           debugBox.style.left = `${e.clientX - offsetX}px`;
           debugBox.style.top = `${e.clientY - offsetY}px`;
       }
   }

   function stopDrag() {
       isDragging = false;
       document.removeEventListener('mousemove', drag);
       document.removeEventListener('mouseup', stopDrag);
   }

   const closeButton = document.createElement('button');
   closeButton.textContent = 'Close';
   closeButton.style.position = 'absolute';
   closeButton.style.top = '10px';
   closeButton.style.right = '10px';
   closeButton.style.padding = '5px';
   closeButton.style.cursor = 'pointer';
   closeButton.addEventListener('click', () => {
       debugBox.style.display = 'none';
   });
   debugBox.appendChild(closeButton);

   const debugInfoTextArea = document.createElement('textarea');
   debugInfoTextArea.value = debugInfo;
   debugInfoTextArea.setAttribute('readonly', '');
   debugInfoTextArea.style.width = '100%';
   debugInfoTextArea.style.height = 'calc(100% - 40px)';
   debugInfoTextArea.style.border = 'none';
   debugInfoTextArea.style.backgroundColor = '#fff';
   debugBox.appendChild(debugInfoTextArea);

   const copyButton = document.createElement('button');
   copyButton.textContent = 'Copy Debug Info';
   copyButton.style.position = 'absolute';
   copyButton.style.bottom = '10px';
   copyButton.style.left = '10px';
   copyButton.style.padding = '5px';
   copyButton.style.cursor = 'pointer';
   copyButton.addEventListener('click', () => {
       copyToClipboard(debugInfo);
   });
   debugBox.appendChild(copyButton);

   return debugBox;
}

function copyToClipboard(text) {
   const textarea = document.createElement('textarea');
   textarea.value = text;
   textarea.setAttribute('readonly', '');
   textarea.style.position = 'absolute';
   textarea.style.left = '-9999px';
   document.body.appendChild(textarea);
   textarea.select();
   document.execCommand('copy');
   document.body.removeChild(textarea);
}

fetchAllUserVillageCoordinates();
[Image: Chase-Banner.png]
Reply


Messages In This Thread
Share your scripts! - by Chase - 12-07-2024, 10:51
RE: Share your scripts! - by Chase - 14-07-2024, 04:46
RE: Share your scripts! - by Chase - 14-07-2024, 05:07
RE: Share your scripts! - by Chase - 17-07-2024, 13:24

Forum Jump:


Users browsing this thread: 4 Guest(s)
Current time: 22-10-2024, 10:36