auto send fake
当前为
// ==UserScript==
// @name Fake bot
// @version 1.6
// @description auto send fake
// @include https://*/game.php*screen=place*
// @namespace https://greasyfork.org/users/1388863
// ==/UserScript==
(function() {
'use strict';
// Create Start/Stop button
const startStopButton = document.createElement('button');
startStopButton.textContent = 'Start';
startStopButton.style.position = 'fixed';
startStopButton.style.bottom = '20px';
startStopButton.style.right = '20px';
startStopButton.style.padding = '10px 20px';
startStopButton.style.fontSize = '16px';
startStopButton.style.backgroundColor = '#4CAF50';
startStopButton.style.color = 'white';
startStopButton.style.border = 'none';
startStopButton.style.borderRadius = '5px';
startStopButton.style.cursor = 'pointer';
startStopButton.style.zIndex = '9999';
document.body.appendChild(startStopButton);
// Create Loop Count button (for setting the number of loops)
const loopButton = document.createElement('button');
loopButton.textContent = 'Set Loops';
loopButton.style.position = 'fixed';
loopButton.style.bottom = '20px';
loopButton.style.right = '120px'; // Adjusted position for spacing
loopButton.style.padding = '10px 20px';
loopButton.style.fontSize = '16px';
loopButton.style.backgroundColor = '#FF9800';
loopButton.style.color = 'white';
loopButton.style.border = 'none';
loopButton.style.borderRadius = '5px';
loopButton.style.cursor = 'pointer';
loopButton.style.zIndex = '9999';
document.body.appendChild(loopButton);
// Create remaining loop counter display
const loopCounterDisplay = document.createElement('div');
loopCounterDisplay.style.position = 'fixed';
loopCounterDisplay.style.bottom = '70px';
loopCounterDisplay.style.right = '20px';
loopCounterDisplay.style.fontSize = '18px';
loopCounterDisplay.style.color = 'white';
loopCounterDisplay.style.zIndex = '9999';
loopCounterDisplay.textContent = 'Remaining Loops: 0';
document.body.appendChild(loopCounterDisplay);
// Retrieve the last state from localStorage (Start or Stop)
let isRunning = localStorage.getItem('botState') === 'running';
let remainingLoops = parseFloat(localStorage.getItem('remainingLoops'), 10) || 0;
// Set initial button and loop counter state based on localStorage
startStopButton.textContent = isRunning ? 'Stop' : 'Start';
loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
console.log(isRunning ? "Bot started" : "Bot stopped");
// If bot is running, start it automatically when the page loads
if (isRunning) {
startBot();
}
// Function to toggle the script on/off
startStopButton.addEventListener('click', () => {
if (isRunning) {
stopBot();
} else {
startBot();
}
});
// Loop button click event to set the number of loops
loopButton.addEventListener('click', () => {
const loops = parseInt(prompt("Enter the number of loops to run:", remainingLoops), 10);
if (!isNaN(loops) && loops > 0) {
remainingLoops = loops * 2; // Double the entered loops
localStorage.setItem('remainingLoops', remainingLoops);
loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
console.log(`Set loops to: ${remainingLoops}`);
}
});
function startBot() {
// Set the bot as running in localStorage
isRunning = true;
localStorage.setItem('botState', 'running');
startStopButton.textContent = 'Stop';
console.log("Bot started");
// Start the loop process
loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
runBotLoop();
}
function stopBot() {
// Set the bot as stopped in localStorage
isRunning = false;
localStorage.setItem('botState', 'stopped');
startStopButton.textContent = 'Start';
console.log("Bot stopped");
}
function runBotLoop() {
if (remainingLoops > 0) {
// Dispatch '0' key event unless URL contains &screen=place&try=confirm
if (!window.location.href.includes("&screen=place&try=confirm")) {
setTimeout(() => {
document.dispatchEvent(new KeyboardEvent('keydown', {
key: '0', code: 'Digit0', keyCode: 48, which: 48, bubbles: true
}));
console.log("Key '0' pressed.");
}, 100 + Math.random() * 150); // Random delay between 100-250ms
}
// Proceed with URL-specific actions
setTimeout(() => {
const url = window.location.href;
if (url.includes("&screen=place&try=confirm")) {
console.log("Detected &screen=place&try=confirm");
setTimeout(() => clickButton('#troop_confirm_submit', Math.random() * 300 + 500), 100);
} else {
console.log("No matching URL condition");
checkTroopCount(() => {
console.log("Troop count sufficient. Proceeding...");
clickButton('#target_attack', Math.random() * 500 + 800);
});
}
// Decrement the remaining loop counter by 0.5 after each loop
remainingLoops -= 1;
localStorage.setItem('remainingLoops', remainingLoops);
loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops.toFixed(1)}`;
// Continue the loop if there are remaining loops
if (remainingLoops > 0) {
runBotLoop();
} else {
stopBot(); // Stop the bot if no loops are left
}
}, 2000 + Math.random() * 1000);
}
}
// Function to check troop count
function checkTroopCount(callback) {
setTimeout(() => {
const RAM = document.getElementById('unit_input_ram');
if (RAM && parseInt(RAM.value, 10) > 0) {
callback();
} else {
setTimeout(() => checkTroopCount(callback), 200);
}
}, 100 + Math.random() * 100);
}
// Function to click a button after a delay
function clickButton(selector, delay) {
const button = document.querySelector(selector);
if (button) {
setTimeout(() => button.click(), delay);
console.log(`Button clicked after ${delay}ms`);
} else {
console.log("Button not found!");
}
}
})();