您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Set the desired arrival time in Tribal Wars and the script will automatically send the attack
当前为
// ==UserScript== // @name Set Arrival Time // @description Set the desired arrival time in Tribal Wars and the script will automatically send the attack // @author FunnyPocketBook // @version 2 // @date 03-10-2017 // @namespace FunnyPocketBook // @include https://*/game.php?village=*&screen=place&try=confirm // ==/UserScript== // CHANGE THESE NUMBERS TO GET THE CORRECT ARRIVAL TIME - higher number means more delay. // Change "windows.delayTime" before "intervalTime" and only change "intervalTime" if you // can't get it quite correct with only "delayTime" window.delayTime = 11; // Set delay in ms window.intervalTime = 10; // Set interval in ms var tRow = document.createElement("tr"); var tD = document.createElement("td"); var tD1 = document.createElement("td"); var parent1 = document.getElementById("date_arrival"); // Cell of relative_time window.tRow.appendChild(tD); window.tRow.appendChild(tD1); parent1.parentNode.parentNode.insertBefore(tRow, parent1.parentNode[1]); // Insert tablerow as last cell tD.innerHTML = "lalala"; tD1.innerHTML = "lelele"; // Create delay input var savedDelay = localStorage.getItem("savedDelay"); if(savedDelay == null) { savedDelay = 0; } var referenceNode = document.querySelector("#place_confirm_units"); // Place after this var delayInput = document.createElement("input"); delayInput.setAttribute("id", "delayInput"); delayInput.setAttribute("value", "savedDelay"); referenceNode.parentNode.insertBefore(delayInput, referenceNode.nextSibling); // Create okay button to save delay var delayButton = document.createElement("a"); delayButton.setAttribute("class", "btn"); delayButton.setAttribute("id", "delayButton"); $("#delayButton").onclick(function() { var delayTime = $("#delayInput").val(); localStorage.setItem("savedDelay", "delayTime"); }) var arrival; var reloadBefore = 1; // Reload page 1 minute before attack is supposed to be sent /* * Save tab ID */ var tabID = sessionStorage.tabID ? sessionStorage.tabID : sessionStorage.tabID = Math.random(); // Generate ID for tab console.log("tabID: " + tabID); var storedID = JSON.parse(localStorage.getItem("storedID")); // Get tab ID console.log("storedID: " + storedID); if(storedID == null) { // See if any tab IDs already exist, if not, initialize the array storedID = []; console.log("storedID = " + storedID); } if(!storedID.includes(tabID) && !storedID.includes(parseFloat(tabID))) { // If the tab ID of the current tab is not stored yet, push the array storedID.push(tabID); console.log("storedID pushed: " + storedID); } localStorage.setItem("storedID", JSON.stringify(storedID)); console.log("localStorage id set to " + localStorage.getItem("storedID")); /* * Reload boolean - set to true to reload, false to not reload */ var reload = JSON.parse(localStorage.getItem("reload")); // Get reload if(reload == null) { reload = []; } console.log("Reload: " + reload); localStorage.setItem("reload", JSON.stringify(reload)); /* * Get stored times */ var index = storedID.indexOf(tabID); // Get index of time of this tab var storedTimes = JSON.parse(localStorage.getItem("storedTimes")); // Get stored times if(storedTimes == null) { // If there are no times yet, initialize array storedTimes = []; } console.log("storedTimes = " + storedTimes); localStorage.setItem("storedTimes", JSON.stringify(storedTimes)); console.log("localStorage times set to " + localStorage.getItem("storedTimes")); var fullTime = storedTimes[index]; if(fullTime != null) { window.input = fullTime.slice(0, 8); window.ms = fullTime.slice(9); } // Set arrival time button var showArrTime = document.createElement("tr"); var showArrTimeTd = document.createElement("td"); var pEle = document.getElementById("troop_confirm_go"); // Button comes after this element var btn = document.createElement("a"); // Create button called btn as a link because any button causes the attack to launch btn.setAttribute("id", "arrTime"); btn.setAttribute("class", "btn"); btn.setAttribute("style", "cursor:pointer;"); pEle.parentNode.insertBefore(btn, pEle.nextElementSibling); // Place btn after pEle var t = document.createTextNode("Set arrival time"); btn.appendChild(t); // Create cell where set arrival time is shown var dateArrival = document.getElementById("date_arrival"); // Cell of relative_time showArrTime.appendChild(showArrTimeTd); dateArrival.parentNode.parentNode.insertBefore(showArrTime, dateArrival.parentNode[1]); // Insert tablerow as last cell // Display the set time if exist, else say "No time set" if(window.input != "" || window.ms != "") { showArrTimeTd.innerHTML = "You set the arrival time to: ~" + window.input + ":" + window.ms; } else { showArrTimeTd.innerHTML = "You set the arrival time to: No time set"; } showArrTimeTd.setAttribute("colspan", "2"); showArrTimeTd.setAttribute("id", "showArrTime"); btn.onclick = function() { "use strict"; var time = document.getElementsByClassName("relative_time")[0].textContent.slice(-8); // Get the time of arrival if sent now window.input = prompt("Please enter desired arrival time", time); // Save desired time window.ms = parseInt(prompt("Please enter approximate milliseconds", "000")); // Save desired ms var setTime = window.input + ":" + window.ms; showArrTimeTd.innerHTML = "You set the arrival time to: ~" + window.input + ":" + window.ms; storedTimes[index] = setTime; // Add new time to the array, same index as the tab ID localStorage.setItem("storedTimes", JSON.stringify(storedTimes)); reload[index] = true; localStorage.setItem("reload", JSON.stringify(reload)); }; console.log(window.input + ":" + window.ms); console.log(window.delayTime); var delay = window.delayTime + parseInt(window.ms); // setTimeout time var intervalCheck = setInterval(function retime() { "use strict"; arrival = document.getElementsByClassName("relative_time")[0].textContent; // Get time of arrival if sent now for comparison delay = window.delayTime + parseInt(window.ms); // setTimeout time if(arrival.slice(-8) === window.input) { console.log("inside"); setTimeout(function() { console.log("sent"); document.getElementById("troop_confirm_go").click(); // Clear set time for this tab and save again in localStorage storedTimes[index] = ""; localStorage.setItem("storedTimes", JSON.stringify(storedTimes)); }, delay); clearInterval(intervalCheck); } }, window.intervalTime); var minute = window.input.substr(3,2) - reloadBefore; // Get minute of input and subtract reloadBefore from it var arriveNow = document.getElementsByClassName("relative_time")[0].textContent.slice(-8); // Get relative_time to compare var timeReload; setInterval(function() { minute = window.input.substr(3,2) - reloadBefore; arriveNow = document.getElementsByClassName("relative_time")[0].textContent.slice(-8); timeReload = window.input.substr(0,3) + minute + window.input.substr(5,3); // Time stitched together with the minute subtracted by reloadBefore if(timeReload != -1 && arriveNow === timeReload && reload[index]) { reload[index] = false; localStorage.setItem("reload", JSON.stringify(reload)); window.location.reload(); } }, 1000);