Automatically clicks the Sun Button on pressing "S" and Stops Clicking when pressing "M" on https://neal.fun/sun-vs-moon/
当前为
// ==UserScript==
// @name Sun vs Moon Auto Click (For Sun)
// @namespace http://tampermonkey.net/
// @version 3.0 Beta
// @description Automatically clicks the Sun Button on pressing "S" and Stops Clicking when pressing "M" on https://neal.fun/sun-vs-moon/
// @author Lav1nRulez
// @match https://neal.fun/sun-vs-moon/
// @grant none
// @icon https://i.ibb.co/QXR89nv/2024-11-03-0z1-Kleki.png
// @license MIT
// ==/UserScript==
(function() {
'use strict';
let clickInterval; // Variable to store the interval ID
// Function to display on-screen messages
function showMessage(text) {
// Check if a message div already exists, if not create it
let messageDiv = document.getElementById("autoclicker-message");
if (!messageDiv) {
messageDiv = document.createElement("div");
messageDiv.id = "autoclicker-message";
messageDiv.style.position = "fixed";
messageDiv.style.bottom = "20px";
messageDiv.style.right = "20px";
messageDiv.style.padding = "10px 20px";
messageDiv.style.backgroundColor = "rgba(0, 0, 0, 0.7)";
messageDiv.style.color = "white";
messageDiv.style.fontSize = "16px";
messageDiv.style.borderRadius = "5px";
messageDiv.style.zIndex = "1000";
document.body.appendChild(messageDiv);
}
// Set the text and display the message
messageDiv.textContent = text;
messageDiv.style.display = "block";
// Hide the message after 2 seconds
setTimeout(() => {
messageDiv.style.display = "none";
}, 2000);
}
// Add event listener for keydown events
document.addEventListener('keydown', function(event) {
if (event.key === 'S' || event.key === 's') {
// If "S" is pressed, start the auto-clicker
if (!clickInterval) { // Only start if it's not already running
clickInterval = setInterval(() => {
const sunButton = document.getElementById("sun-btn");
if (sunButton) {
sunButton.click();
}
}, 1); // 1 millisecond interval
showMessage("Autoclicker Started"); // Show on-screen message
}
} else if (event.key === 'M' || event.key === 'm') {
// If "M" is pressed, stop the auto-clicker
if (clickInterval) {
clearInterval(clickInterval); // Clear the interval
clickInterval = null; // Reset the interval variable
showMessage("Autoclicker Stopped"); // Show on-screen message
}
}
});
})();