Hello There, Guest! Register

Commands Carbon's Attack Script Generator
#1
This Script can be used in many ways.
to help send fakes, scouts, and attacks.

first run the script on a player info page it will fetch that players coordinates, and create a popup.

enter what troops you want to use for the generated script.
Click generate script button

copy this script and use it in your quickbar.

the generated script is ran on the rally place.

when the generated script is executed on the rally place it will input the troops that were selected and randomly choose one of the coordinates that were fetched.
next time this script is executed it will choose another one of the coordinates not repeating until all coordinates have been used.

Code:
javascript:(function() {
   if (!window.location.href.includes("info_player&id=")) {
       alert("This script can only be used on player info pages.");
       return;
   }

   async function fetchVillages() {
       let coordinates = new Set();
       let page = 1;

       while (true) {
           const response = await fetch(window.location.href.split('&page=')[0] + '&page=' + page);
           const text = await response.text();
           const parser = new DOMParser();
           const doc = parser.parseFromString(text, 'text/html');

           const villageLinks = doc.querySelectorAll('a[href*="screen=info_village"]');
           if (villageLinks.length === 0) break;

           villageLinks.forEach(link => {
               const coordText = link.textContent.match(/\(([^)]+)\)/);
               if (coordText) {
                   coordinates.add(coordText[1]);
               }
           });

           const nextPage = doc.querySelector('a[href*="page=' + (page + 1) + '"]');
           if (!nextPage) break;
           page++;
       }

       return Array.from(coordinates);
   }

   async function createPopup(coordinates) {
       const popup = window.open('', 'Carbon Attack Script Generator', 'width=700,height=500');

       if (!popup) {
           alert("Popup blocked. Please allow popups for this site.");
           return;
       }

       popup.document.write(`
           <style>
               body {
                   font-family: Arial, sans-serif;
                   background-color: #f2e0c9; /* Updated to a more accurate color */
                   color: #3b3b3b;
                   margin: 0;
                   padding: 20px;
                   overflow: hidden; /* Prevent scroll bars */
               }
               h1 {
                   color: #5c4a32;
                   text-align: center;
               }
               textarea {
                   width: 100%;
                   height: 100px;
                   margin: 10px 0;
                   resize: none; /* Prevent resizing */
               }
               table {
                   width: 100%;
                   border-collapse: collapse;
                   margin-bottom: 10px;
               }
               td {
                   padding: 8px;
                   border: 2px solid #5c4a32; /* Bold border for table cells */
                   text-align: center;
               }
               input[type="number"] {
                   width: 40px; /* Adjusted width for number inputs */
               }
               button {
                   background-color: #5c4a32;
                   color: white;
                   border: 2px solid #3b3b3b; /* Bold border for buttons */
                   padding: 10px 15px;
                   cursor: pointer;
                   margin-right: 5px;
                   display: inline-block; /* Center buttons */
               }
               button:hover {
                   background-color: #7c5a42;
               }
           </style>
           <h1>Carbon's Attack Script Generator</h1>
           <textarea id="coordinates">${coordinates.join('\n')}</textarea>
           <div id="troops">
               <table>
                   <tr>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_spear.png" title="Spear fighter" alt=""></td>
                       <td>Spear:</td><td><input type="number" id="unit_input_spear" value="0" /></td>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_sword.png" title="Swordsman" alt=""></td>
                       <td>Sword:</td><td><input type="number" id="unit_input_sword" value="0" /></td>
                   </tr>
                   <tr>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_axe.png" title="Axeman" alt=""></td>
                       <td>Axe:</td><td><input type="number" id="unit_input_axe" value="0" /></td>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_archer.png" title="Archer" alt=""></td>
                       <td>Archer:</td><td><input type="number" id="unit_input_archer" value="0" /></td>
                   </tr>
                   <tr>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_spy.png" title="Scout" alt=""></td>
                       <td>Spy:</td><td><input type="number" id="unit_input_spy" value="0" /></td>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_light.png" title="Light cavalry" alt=""></td>
                       <td>Light:</td><td><input type="number" id="unit_input_light" value="0" /></td>
                   </tr>
                   <tr>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_marcher.png" title="Mounted archer" alt=""></td>
                       <td>Mounted Archer:</td><td><input type="number" id="unit_input_marcher" value="0" /></td>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_heavy.png" title="Heavy cavalry" alt=""></td>
                       <td>Heavy Cavalry:</td><td><input type="number" id="unit_input_heavy" value="0" /></td>
                   </tr>
                   <tr>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_ram.png" title="Ram" alt=""></td>
                       <td>Ram:</td><td><input type="number" id="unit_input_ram" value="0" /></td>
                       <td><img src="https://cdn.infernal-wars.com/graphic/unit/unit_catapult.png" title="Catapult" alt=""></td>
                       <td>Catapult:</td><td><input type="number" id="unit_input_catapult" value="0" /></td>
                   </tr>
               </table>
           </div>
           <div style="text-align: center;">
               <button id="generate">Generate Script</button>
               <button id="cancel">Cancel</button>
           </div>
           <script>
               document.getElementById('cancel').onclick = function() {
                   window.close();
               };
               
               document.getElementById('generate').onclick = function() {
                   const troops = {
                       spear: document.getElementById('unit_input_spear').value,
                       sword: document.getElementById('unit_input_sword').value,
                       axe: document.getElementById('unit_input_axe').value,
                       archer: document.getElementById('unit_input_archer').value,
                       spy: document.getElementById('unit_input_spy').value,
                       light: document.getElementById('unit_input_light').value,
                       ram: document.getElementById('unit_input_ram').value,
                       catapult: document.getElementById('unit_input_catapult').value,
                       mounted: document.getElementById('unit_input_marcher').value,
                       heavy: document.getElementById('unit_input_heavy').value,
                   };
                   
                   const script = \`javascript:(function() {
                       if (!window.location.href.endsWith("=place")) {
                           alert("Use this Script on Rally Point");
                           return;
                       }
                       
                       const coordinates = ${JSON.stringify(coordinates)};
                       let usedCoordinates = JSON.parse(localStorage.getItem('usedCoordinates')) || [];
                       
                       if (usedCoordinates.length === coordinates.length) {
                           alert("All coordinates have been used, starting over.");
                           usedCoordinates = [];
                       }
                       
                       const availableCoordinates = coordinates.filter(coord => !usedCoordinates.includes(coord));
                       const randomCoord = availableCoordinates[Math.floor(Math.random() * availableCoordinates.length)];
                       usedCoordinates.push(randomCoord);
                       localStorage.setItem('usedCoordinates', JSON.stringify(usedCoordinates));
                       document.querySelector("input[name='input']").value = randomCoord;

                       const troops = {
                           spear: \${troops.spear},
                           sword: \${troops.sword},
                           axe: \${troops.axe},
                           archer: \${troops.archer},
                           spy: \${troops.spy},
                           light: \${troops.light},
                           ram: \${troops.ram},
                           catapult: \${troops.catapult},
                           mounted: \${troops.mounted},
                           heavy: \${troops.heavy},
                       };

                       for (let unit in troops) {
                           const inputField = document.getElementById("unit_input_" + (unit === 'mounted' ? 'marcher' : unit));
                           if (inputField) {
                               inputField.value = troops[unit];
                           }
                       }
                   })();\`;

                   window.close();

                   const outputPopup = window.open('', 'Generated Script', 'width=700,height=500');
                   outputPopup.document.write(\`
                       <style>
                           body {
                               font-family: Arial, sans-serif;
                               background-color: #f2e0c9; /* Match the same background color */
                               color: #3b3b3b;
                               margin: 0;
                               padding: 20px;
                               overflow: hidden; /* Prevent scroll bars */
                           }
                           h1 {
                               color: #5c4a32;
                               text-align: center;
                           }
                           textarea {
                               width: 100%;
                               height: 200px;
                               margin: 10px 0;
                               resize: none; /* Prevent resizing */
                           }
                           button {
                               background-color: #5c4a32;
                               color: white;
                               border: 2px solid #3b3b3b; /* Bold border for buttons */
                               padding: 10px 15px;
                               cursor: pointer;
                               margin-right: 5px;
                               display: inline-block; /* Center buttons */
                           }
                           button:hover {
                               background-color: #7c5a42;
                           }
                       </style>
                       <h1>Generated JavaScript</h1>
                       <textarea>\${script}</textarea>
                       <button onclick="navigator.clipboard.writeText(document.querySelector('textarea').value)">Copy that</button>
                       <button onclick="window.close()">Close</button>
                   \`);
               };
           </script>
       `);
   }

   fetchVillages().then(coordinates => {
       if (coordinates.length > 0) {
           createPopup(coordinates);
       } else {
           alert("No villages found.");
       }
   });
})();


There is a slight bug that can happen here and there.
sometimes when you click the Generate Script button in the popup that displays the generated script it will show it twice in one popup.
i believe this is due to having a different popup already for the same script so make sure you close the popup once you have copied the script.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Commands Carbon's Mass Attack Planner Carbon 0 166 28-09-2024, 05:39
Last Post: Carbon
  Misc Carbon's Front Line Coordinate Grabber Carbon 0 100 28-09-2024, 04:55
Last Post: Carbon
  Misc Report Sharing Script Carbon 0 140 24-09-2024, 04:12
Last Post: Carbon

Forum Jump:


Users browsing this thread: 3 Guest(s)
Current time: 22-10-2024, 08:57