Hello There, Guest! Register

Share your scripts!
#1
Here is a 2 click fake script that is supported and approved! 


Code:
javascript:var index = localStorage.getItem('currentIndex') ? parseInt(localStorage.getItem('currentIndex')) : 0;
var doc = document;

function attackWithNextCoords() {
    var currentCoords = coords[index];
    index = (index + 1) % coords.length;

    $('#place_target').find('input').val(currentCoords.x + '|' + currentCoords.y);
    doc.forms[0].x.value = currentCoords.x;
    doc.forms[0].y.value = currentCoords.y;
    doc.forms[0].unit_input_ram.value = 1;

    $('#target_attack').click();

    localStorage.setItem('currentIndex', index);

    var url = doc.URL;
    if (url.indexOf('screen=place') == -1) {
        alert('Use the script in the rally point page!');
        return;
    }
}

if (window.frames.length > 0 && window.main != null) {
    doc = window.main.document;
}

var url = doc.URL;

if (url.indexOf('try=confirm') > 0) {
    document.getElementsByName("submit")[0].click();
}

if (url.indexOf('screen=place') == -1) {
    alert('Use the script in the rally point page!');
} else {
    var coordsString = 'ENTER COORDS HERE IN xxx|yyy format';

    var coordsPairs = coordsString.split(' ');

    function parseCoordinates(coordString) {
        var parts = coordString.split('|');
        if (parts.length === 2 && !isNaN(parts[0]) && !isNaN(parts[1])) {
            return { x: parseInt(parts[0]), y: parseInt(parts[1]) };
        }
        return null;
    }

    var coords = coordsPairs.map(parseCoordinates).filter(function(coord) {
        return coord !== null;
    });

    attackWithNextCoords();
}
[Image: Chase-Banner.png]
[-] The following 1 user says Thank You to Chase for this post:
  • Lord DciBelia
Reply
#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
#3
This script automates both! Run using this script loaded in the quick bar on the targets user page. Choose which script you want and copy it - then add it to the quickbar. The fake or spy script can be used in the rally point, click once to load the attack, click again to send the attack.

[Image: final-script-generator.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 fetchWithRetry(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(' ');

        displayFinalScriptPopup(coordinatesText, coordinatesToDisplay.length);
    } catch (error) {
        console.error('Error fetching user villages:', error.message);
        displayDebuggingPopup(error.message);
    }
}

async function fetchWithRetry(url, retries = 3) {
    for (let attempt = 1; attempt <= retries; attempt++) {
        try {
            const response = await fetch(url);
            if (!response.ok && attempt < retries) {
                console.warn(`Retry attempt ${attempt} for URL: ${url}`);
                continue;
            }
            return response;
        } catch (error) {
            if (attempt === retries) throw error;
        }
    }
}

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 generateAttackScript(coordinatesText, unitCounts, isSupport = false) {
    const scriptType = isSupport ? 'support' : 'attack';
    return `javascript:
var index = localStorage.getItem('currentIndex') ? parseInt(localStorage.getItem('currentIndex')) : 0;
var doc = document;

function sendNextCommand() {
    var currentCoords = coords[index];
    index = (index + 1) % coords.length;

    $('#place_target').find('input').val(currentCoords.x + '|' + currentCoords.y);
    doc.forms[0].x.value = currentCoords.x;
    doc.forms[0].y.value = currentCoords.y;

    ${Object.keys(unitCounts).map(unit => `doc.forms[0].unit_input_${unit}.value = ${unitCounts[unit]};`).join('\n')}

    $('#target_${scriptType}').click();

    localStorage.setItem('currentIndex', index);

    var url = doc.URL;
    if (url.indexOf('screen=place') == -1) {
        alert('Use the script in the rally point page!');
        return;
    }
}

if (window.frames.length > 0 && window.main != null) {
    doc = window.main.document;
}

var url = doc.URL;

if (url.indexOf('try=confirm') > 0) {
    document.getElementsByName("submit")[0].click();
}

if (url.indexOf('screen=place') == -1) {
    alert('Use the script in the rally point page!');
} else {
    var coordsString = '${coordinatesText}';

    var coordsPairs = coordsString.split(' ');

    function parseCoordinates(coordString) {
        var parts = coordString.split('|');
        if (parts.length === 2 && !isNaN(parts[0]) && !isNaN(parts[1])) {
            return { x: parseInt(parts[0]), y: parseInt(parts[1]) };
        }
        return null;
    }

    var coords = coordsPairs.map(parseCoordinates).filter(function(coord) {
        return coord !== null;
    });

    sendNextCommand();
}`;
}

function displayFinalScriptPopup(coordinatesText, coordinateCount) {
    const units = [
        { name: 'spear', label: 'Spear', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_spear.png?1' },
        { name: 'sword', label: 'Sword', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_sword.png?1' },
        { name: 'axe', label: 'Axe', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_axe.png?1' },
        { name: 'spy', label: 'Spy', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_spy.png?1' },
        { name: 'light', label: 'Light', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_light.png?1' },
        { name: 'heavy', label: 'Heavy', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_heavy.png?1' },
        { name: 'ram', label: 'Ram', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_ram.png?1' },
        { name: 'catapult', label: 'Catapult', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_catapult.png?1' },
        { name: 'snob', label: 'Snob', icon: 'https://cdn.infernal-wars.com/graphic/unit/unit_snob.png' }
    ];

    const popup = document.createElement('div');
    popup.className = 'final-script-popup';
    popup.style.position = 'fixed';
    popup.style.top = '50%';
    popup.style.left = '50%';
    popup.style.transform = 'translate(-50%, -50%)';
    popup.style.width = '700px';
    popup.style.height = '650px';
    popup.style.border = '2px solid #DED3B9';
    popup.style.backgroundColor = '#F4E4BC';
    popup.style.boxShadow = '0 4px 20px rgba(0,0,0,0.2)';
    popup.style.zIndex = '10000';
    popup.style.padding = '20px';
    popup.style.borderRadius = '10px';
    popup.style.display = 'flex';
    popup.style.flexDirection = 'column';
    popup.style.fontFamily = 'Arial, sans-serif';

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

    popup.addEventListener('mousedown', startDrag);

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

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

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

    const header = document.createElement('div');
    header.style.display = 'flex';
    header.style.justifyContent = 'space-between';
    header.style.alignItems = 'center';
    header.style.marginBottom = '10px';
    header.style.borderBottom = '1px solid #DED3B9';
    header.style.paddingBottom = '10px';

    const title = document.createElement('h3');
    title.textContent = 'Generate Attack/Support Script';
    title.style.margin = '0';
    title.style.color = '#5D4037';
    header.appendChild(title);

    const closeButton = document.createElement('button');
    closeButton.textContent = '×';
    closeButton.style.border = 'none';
    closeButton.style.background = 'none';
    closeButton.style.fontSize = '24px';
    closeButton.style.cursor = 'pointer';
    closeButton.addEventListener('click', () => {
        popup.style.display = 'none';
    });
    header.appendChild(closeButton);

    popup.appendChild(header);

    const coordinatesInfo = document.createElement('p');
    coordinatesInfo.textContent = `Number of coordinates generated: ${coordinateCount}`;
    coordinatesInfo.style.marginBottom = '10px';
    coordinatesInfo.style.color = '#333';
    popup.appendChild(coordinatesInfo);

    const scriptTypeSelect = document.createElement('select');
    scriptTypeSelect.style.marginBottom = '10px';
    scriptTypeSelect.style.border = '1px solid #DED3B9';
    scriptTypeSelect.style.padding = '5px';
    const scriptTypes = [
        { name: 'Attack Script', value: 'attack' },
        { name: 'Support Script', value: 'support' },
    ];
    scriptTypes.forEach(type => {
        const option = document.createElement('option');
        option.value = type.value;
        option.textContent = type.name;
        scriptTypeSelect.appendChild(option);
    });
    popup.appendChild(scriptTypeSelect);

    const unitInputsContainer = document.createElement('div');
    unitInputsContainer.style.display = 'grid';
    unitInputsContainer.style.gridTemplateColumns = 'repeat(3, 1fr)';
    unitInputsContainer.style.gap = '10px';
    unitInputsContainer.style.marginBottom = '10px';

    units.forEach(unit => {
        const unitContainer = document.createElement('div');
        unitContainer.style.display = 'flex';
        unitContainer.style.flexDirection = 'column';
        unitContainer.style.alignItems = 'center';

        const unitLabel = document.createElement('label');
        unitLabel.textContent = unit.label;
        unitLabel.style.marginBottom = '5px';
        unitLabel.style.color = '#5D4037';
        unitContainer.appendChild(unitLabel);

        const unitImage = document.createElement('img');
        unitImage.src = unit.icon;
        unitImage.alt = unit.label;
        unitImage.style.width = '30px';
        unitImage.style.height = '30px';
        unitImage.style.marginBottom = '5px';
        unitContainer.appendChild(unitImage);

        const unitInput = document.createElement('input');
        unitInput.type = 'number';
        unitInput.min = '0';
        unitInput.value = '0';
        unitInput.style.border = '1px solid #DED3B9';
        unitInput.style.padding = '5px';
        unitInput.style.width = '100%';
        unitInput.id = `unit_${unit.name}`;
        unitContainer.appendChild(unitInput);

        unitInputsContainer.appendChild(unitContainer);
    });
    popup.appendChild(unitInputsContainer);

    const scriptArea = document.createElement('textarea');
    scriptArea.setAttribute('readonly', '');
    scriptArea.style.width = '100%';
    scriptArea.style.height = 'calc(100% - 370px)';
    scriptArea.style.border = '1px solid #DED3B9';
    scriptArea.style.borderRadius = '4px';
    scriptArea.style.padding = '10px';
    scriptArea.style.boxSizing = 'border-box';
    scriptArea.style.marginBottom = '10px';
    scriptArea.style.fontFamily = 'Courier New, monospace';
    scriptArea.style.backgroundColor = '#FAF3E0';
    popup.appendChild(scriptArea);

    const buttonContainer = document.createElement('div');
    buttonContainer.style.display = 'flex';
    buttonContainer.style.justifyContent = 'space-between';

    const generateButton = document.createElement('button');
    generateButton.textContent = 'Generate Script';
    generateButton.style.flex = '1';
    generateButton.style.marginRight = '10px';
    generateButton.style.padding = '10px';
    generateButton.style.border = '1px solid #DED3B9';
    generateButton.style.backgroundColor = '#8D6E63';
    generateButton.style.color = '#fff';
    generateButton.style.borderRadius = '4px';
    generateButton.style.cursor = 'pointer';
    generateButton.addEventListener('click', () => {
        const scriptType = scriptTypeSelect.value;
        let isSupport = scriptType === 'support';
        let unitCounts = {};

        units.forEach(unit => {
            const unitInput = document.getElementById(`unit_${unit.name}`);
            const unitCount = parseInt(unitInput.value, 10);
            if (unitCount > 0) {
                unitCounts[unit.name] = unitCount;
            }
        });

        const finalScript = generateAttackScript(coordinatesText, unitCounts, isSupport);
        scriptArea.value = finalScript;
    });
    buttonContainer.appendChild(generateButton);

    const copyButton = document.createElement('button');
    copyButton.textContent = 'Copy Script';
    copyButton.style.flex = '1';
    copyButton.style.padding = '10px';
    copyButton.style.border = '1px solid #DED3B9';
    copyButton.style.backgroundColor = '#8D6E63';
    copyButton.style.color = '#fff';
    copyButton.style.borderRadius = '4px';
    copyButton.style.cursor = 'pointer';
    copyButton.addEventListener('click', () => {
        scriptArea.select();
        document.execCommand('copy');
        alert('Script copied to clipboard!');
    });
    buttonContainer.appendChild(copyButton);

    popup.appendChild(buttonContainer);

    document.body.appendChild(popup);
}

function displayDebuggingPopup(errorMessage) {
    const popup = document.createElement('div');
    popup.className = 'debugging-popup';
    popup.style.position = 'fixed';
    popup.style.top = '50%';
    popup.style.left = '50%';
    popup.style.transform = 'translate(-50%, -50%)';
    popup.style.width = '400px';
    popup.style.height = '200px';
    popup.style.border = '1px solid #8D6E63';
    popup.style.backgroundColor = '#F4E4BC';
    popup.style.boxShadow = '0 4px 20px rgba(0,0,0,0.2)';
    popup.style.zIndex = '10000';
    popup.style.padding = '20px';
    popup.style.borderRadius = '10px';
    popup.style.display = 'flex';
    popup.style.flexDirection = 'column';
    popup.style.justifyContent = 'center';
    popup.style.alignItems = 'center';
    popup.style.fontFamily = 'Arial, sans-serif';

    const errorText = document.createElement('p');
    errorText.textContent = `Error: ${errorMessage}`;
    errorText.style.color = '#8D6E63';
    errorText.style.marginBottom = '20px';
    popup.appendChild(errorText);

    const closeButton = document.createElement('button');
    closeButton.textContent = 'Close';
    closeButton.style.border = '1px solid #8D6E63';
    closeButton.style.background = '#8D6E63';
    closeButton.style.color = '#fff';
    closeButton.style.padding = '10px 20px';
    closeButton.style.borderRadius = '4px';
    closeButton.style.cursor = 'pointer';
    closeButton.addEventListener('click', () => {
        popup.style.display = 'none';
    });
    popup.appendChild(closeButton);

    document.body.appendChild(popup);
}

fetchAllUserVillageCoordinates();
[Image: Chase-Banner.png]
Reply
#4
Automated Report Sorting

[Image: report-1.png]
[Image: report-2.png]
[Image: report3.png]

Code:
javascript:const DEBUG = false;

const scriptConfig = {
   scriptData: {
       prefix: 'automateReports',
       name: 'Automate Reports',
       version: 'v1.0.0',
       author: 'Chase',
       authorUrl: '',
       helpLink: '',
   },
   allowedMarkets: [],
   allowedScreens: ['report'],
   allowedModes: ['all'],
   isDebug: DEBUG,
   enableCountApi: true,
};

let playerDatabase = {};

const extractUnitData = (doc, tableId) => {
   const table = doc.getElementById(tableId);
   if (!table) return null;

   const rows = table.querySelectorAll('tr');
   const unitTypes = Array.from(rows[0].querySelectorAll('td img')).map(img => img.title.toLowerCase().replace(/ /g, '_'));
   const quantities = Array.from(rows[1].querySelectorAll('td')).slice(1).map(td => parseInt(td.textContent, 10) || 0);

   const unitsData = {};
   unitTypes.forEach((unitType, index) => {
       unitsData[unitType] = quantities[index];
   });

   return unitsData;
};

const extractUnitsOutsideVillage = (doc) => {
   const thElements = doc.querySelectorAll('th');
   for (let th of thElements) {
       if (th.textContent.trim() === 'Units outside village:') {
           const table = th.parentElement.nextElementSibling.querySelector('table');
           if (!table) return null;

           const rows = table.querySelectorAll('tr');
           const unitTypes = Array.from(rows[0].querySelectorAll('th img')).map(img => img.title.toLowerCase().replace(/ /g, '_'));
           const quantities = Array.from(rows[1].querySelectorAll('td')).map(td => parseInt(td.textContent, 10) || 0);

           const unitsData = {};
           unitTypes.forEach((unitType, index) => {
               unitsData[unitType] = quantities[index];
           });

           return unitsData;
       }
   }
   return null;
};

const fetchReportData = async (url, retryCount = 3) => {
   if (!url.startsWith('http')) {
       console.error(`Invalid URL: ${url}`);
       return null;
   }
   try {
       const response = await fetch(url);
       if (!response.ok) {
           if (response.status === 520 && retryCount > 0) {
               console.warn(`Encountered 520 error, retrying... (${3 - retryCount + 1})`);
               await new Promise(res => setTimeout(res, 2000));
               return fetchReportData(url, retryCount - 1);
           }
           throw new Error(`HTTP error! Status: ${response.status}`);
       }
       const text = await response.text();
       const parser = new DOMParser();
       const doc = parser.parseFromString(text, 'text/html');

       const findPlayerData = (label) => {
           const thElements = doc.querySelectorAll('th');
           for (let th of thElements) {
               if (th.textContent.trim() === label) {
                   const playerLink = th.nextElementSibling.querySelector('a[href*="screen=info_player"]');
                   const villageLink = th.closest('table').querySelector('a[href*="screen=info_village"]');
                   const playerName = playerLink ? playerLink.textContent.trim() : 'Unknown';
                   const villageCoords = villageLink ? villageLink.textContent.trim().match(/\d+\|\d+/)[0] : 'Unknown';
                   return { playerName, villageCoords };
               }
           }
           return null;
       };

       const attacker = findPlayerData('Attacker:');
       const defender = findPlayerData('Defender:');
       const attackerUnits = extractUnitData(doc, 'attack_info_att_units');
       const defenderUnits = extractUnitData(doc, 'attack_info_def_units');
       const unitsOutside = extractUnitsOutsideVillage(doc);

       return {
           attacker: { ...attacker, units: attackerUnits },
           defender: { ...defender, units: defenderUnits },
           unitsOutside,
           reportPageLink: url,
       };
   } catch (error) {
       console.error('Error fetching report data:', error);
       return null;
   }
};

const classifyUnits = (units, unitsOutside) => {
   const offensiveUnits = ['axe', 'light_cavalry'];
   const defensiveUnits = ['spear', 'sword', 'heavy_cavalry'];

   let offensiveCount = 0;
   let defensiveCount = 0;

   const countUnits = (units) => {
       if (!units) return;
       for (const [unitType, count] of Object.entries(units)) {
           if (offensiveUnits.includes(unitType)) {
               offensiveCount += count;
           } else if (defensiveUnits.includes(unitType)) {
               defensiveCount += count;
           }
       }
   };

   countUnits(units);
   countUnits(unitsOutside);

   if (offensiveCount > defensiveCount) {
       return 'offensive';
   } else if (defensiveCount > offensiveCount) {
       return 'defensive';
   } else {
       return 'unknown';
   }
};

const countVillages = () => {
   for (const playerName in playerDatabase) {
       const playerData = playerDatabase[playerName];
       let offensiveCount = 0;
       let defensiveCount = 0;

       for (const villageCoords in playerData.villages) {
           const villageData = playerData.villages[villageCoords];
           if (villageData.classification === 'offensive') {
               offensiveCount++;
           } else if (villageData.classification === 'defensive') {
               defensiveCount++;
           }
       }

       playerData.offensiveCount = offensiveCount;
       playerData.defensiveCount = defensiveCount;
   }
};

const processReports = async () => {
   const reportLinks = document.querySelectorAll('a[href*="view="]');
   const validReportLinks = Array.from(reportLinks).filter(link => link.href.startsWith('http'));
   const reportPromises = validReportLinks.map(async (link) => {
       const reportPageLink = link.href;
       const reportData = await fetchReportData(reportPageLink);
       if (reportData) {
           const { attacker, defender, unitsOutside } = reportData;

           if (attacker && attacker.units) {
               const classification = classifyUnits(attacker.units, unitsOutside);
               if (!playerDatabase[attacker.playerName]) {
                   playerDatabase[attacker.playerName] = { villages: {} };
               }
               playerDatabase[attacker.playerName].villages[attacker.villageCoords] = {
                   classification,
                   reportLink: reportPageLink,
                   units: attacker.units,
                   unitsOutside,
               };
           }

           if (defender && defender.units) {
               const classification = classifyUnits(defender.units, unitsOutside);
               if (!playerDatabase[defender.playerName]) {
                   playerDatabase[defender.playerName] = { villages: {} };
               }
               playerDatabase[defender.playerName].villages[defender.villageCoords] = {
                   classification,
                   reportLink: reportPageLink,
                   units: defender.units,
                   unitsOutside,
               };
           }
       }
   });

   await Promise.all(reportPromises);
   countVillages();
   updatePlayerList();
};

const generateNotebookEntry = () => {
   let notebookEntry = '';

   Object.keys(playerDatabase).forEach(playerName => {
       const playerData = playerDatabase[playerName];
       notebookEntry += `[player]${playerName}[/player]\n`;

       const villages = [];

       Object.keys(playerData.villages).forEach(villageCoords => {
           const villageData = playerData.villages[villageCoords];
           const classification = villageData.classification === 'offensive' ? '[color=#ae0e0e]OFFENSIVE[/color]' : '[color=#0e0eae]DEFENSE[/color]';
           villages.push(`[village]${villageCoords}[/village] - ${classification}`);
       });

       notebookEntry += villages.join('\n') + '\n\n';
   });

   return notebookEntry;
};

const copyNotebookEntryToClipboard = () => {
   const notebookEntry = generateNotebookEntry();
   const tempTextArea = document.createElement('textarea');
   tempTextArea.value = notebookEntry;
   document.body.appendChild(tempTextArea);
   tempTextArea.select();
   document.execCommand('copy');
   document.body.removeChild(tempTextArea);
   alert('Notebook entry copied to clipboard!');
};

const updatePlayerList = () => {
   const playerListContainer = document.querySelector('#playerListContainer');
   playerListContainer.innerHTML = '';
   for (const playerName in playerDatabase) {
       const playerData = playerDatabase[playerName];
       const playerButton = document.createElement('button');
       playerButton.textContent = `${playerName} (O: ${playerData.offensiveCount}, D: ${playerData.defensiveCount})`;
       playerButton.onclick = () => showPlayerData(playerName);
       playerListContainer.appendChild(playerButton);
   }
};

const showPlayerData = (playerName) => {
   const playerData = playerDatabase[playerName];
   const offensiveVillages = [];
   const defensiveVillages = [];

   for (const villageCoords in playerData.villages) {
       const villageData = playerData.villages[villageCoords];
       if (villageData.classification === 'offensive') {
           offensiveVillages.push(villageCoords);
       } else if (villageData.classification === 'defensive') {
           defensiveVillages.push(villageCoords);
       }
   }

   const offensiveCount = playerData.offensiveCount || 0;
   const defensiveCount = playerData.defensiveCount || 0;

   const popupContent = `
       <div>
           <h3>${playerName}</h3>
           <p>Total Offensive Villages: ${offensiveCount}</p>
           <p>Total Defensive Villages: ${defensiveCount}</p>
           <textarea id="offensiveCoords" rows="10" cols="60">${offensiveVillages.join('\n')}</textarea>
           <button onclick="copyToClipboard('offensiveCoords')">Copy Offensive Coordinates</button>
           <textarea id="defensiveCoords" rows="10" cols="60">${defensiveVillages.join('\n')} </textarea>
           <button onclick="copyToClipboard('defensiveCoords')">Copy Defensive Coordinates</button>
       </div>
   `;

   const popup = window.open('', 'Player Data', 'width=800,height=600,scrollbars=yes');
   popup.document.write(popupContent);
   popup.document.close();
};

const copyToClipboard = (elementId) => {
   const textarea = document.getElementById(elementId);
   textarea.select();
   document.execCommand('copy');
   alert('Coordinates copied to clipboard!');
};

const exportData = () => {
   const dataStr = JSON.stringify(playerDatabase, null, 2);
   const dataBlob = new Blob([dataStr], { type: 'application/json' });
   const url = URL.createObjectURL(dataBlob);
   const a = document.createElement('a');
   a.href = url;
   a.download = 'playerDatabase.json';
   a.click();
   URL.revokeObjectURL(url);
};

const viewData = () => {
   const popup = window.open('', 'Player Data', 'width=800,height=600,scrollbars=yes');
   const dataStr = JSON.stringify(playerDatabase, null, 2);
   popup.document.write('<pre>' + dataStr + '</pre>');
   popup.document.close();
};

const isValidScreen = location.search.includes('screen=report');
const isValidMode = location.search.includes('mode=all');
if (isValidScreen && isValidMode) {
   const content = `
       <div class="ra-mb15">
           <a href="javascript:void(0);" id="raProcessReportsBtn" class="btn">Automate Reports</a>
           <a href="javascript:void(0);" id="raCopyNotebookEntryBtn" class="btn">Copy to Clipboard</a>
           <a href="javascript:void(0);" id="raExportDataBtn" class="btn">Export Data</a>
           <a href="javascript:void(0);" id="raViewDataBtn" class="btn">View Data</a>
       </div>
       <div id="playerListContainer" class="ra-mb15"></div>
   `;
   const widget = document.createElement('div');
   widget.innerHTML = content;
   const contentValue = document.getElementById('content_value');
   contentValue.insertBefore(widget, contentValue.firstChild);

   document.querySelector('#raProcessReportsBtn').addEventListener('click', processReports);
   document.querySelector('#raCopyNotebookEntryBtn').addEventListener('click', copyNotebookEntryToClipboard);
   document.querySelector('#raExportDataBtn').addEventListener('click', exportData);
   document.querySelector('#raViewDataBtn').addEventListener('click', viewData);
} else {
   console.log('Redirecting...');
   location.href = 'https://w1.infernal-wars.com/game.php?village=21&screen=report&mode=all';
}
[Image: Chase-Banner.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)
Current time: 22-10-2024, 11:40