Auto Key Press Simulation

Simulate key presses (0 and 9) with a delay of 2.89 seconds each, start/stop with buttons

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto Key Press Simulation
// @namespace    http://your-unique-namespace.com
// @version      1.0
// @description  Simulate key presses (0 and 9) with a delay of 2.89 seconds each, start/stop with buttons
// @author       Your Name
// @match        *://*/*  // This matches all URLs, change it to a specific site if needed
// @license      MIT
// ==/UserScript==

(function() {
  let intervalId; // For storing the interval ID to stop the process
  let running = false; // State to track if the process is running

  // Create the start and stop buttons
  const startBtn = document.createElement('button');
  startBtn.innerText = 'Start';
  startBtn.style.position = 'absolute';
  startBtn.style.top = '10px';
  startBtn.style.right = '10px';
  startBtn.style.padding = '10px';
  startBtn.style.backgroundColor = '#4CAF50';
  startBtn.style.color = 'white';
  startBtn.style.border = 'none';
  startBtn.style.cursor = 'pointer';
  document.body.appendChild(startBtn);

  const stopBtn = document.createElement('button');
  stopBtn.innerText = 'Stop';
  stopBtn.style.position = 'absolute';
  stopBtn.style.top = '50px';
  stopBtn.style.right = '10px';
  stopBtn.style.padding = '10px';
  stopBtn.style.backgroundColor = '#f44336';
  stopBtn.style.color = 'white';
  stopBtn.style.border = 'none';
  stopBtn.style.cursor = 'pointer';
  stopBtn.style.display = 'none'; // Initially hidden
  document.body.appendChild(stopBtn);

  // Function to simulate key press (in this case, we will just log to the page)
  function simulateAction() {
    // Simulating the "0" press
    const message0 = document.createElement('p');
    message0.innerText = '0 pressed';
    document.body.appendChild(message0);

    // After 2.89 seconds, simulate the "9" press
    setTimeout(() => {
      const message9 = document.createElement('p');
      message9.innerText = '9 pressed';
      document.body.appendChild(message9);
    }, 2890); // Wait for 2.89 seconds
  }

  // Function to start the repeating actions
  function startRepeating() {
    if (!running) {
      running = true;
      intervalId = setInterval(() => {
        simulateAction();
      }, 5780); // Total interval is 5.78 seconds (2.89s + 2.89s)
      stopBtn.style.display = 'block'; // Show the Stop button when the process starts
    }
  }

  // Function to stop the repeating actions
  function stopRepeating() {
    clearInterval(intervalId);
    running = false;
    stopBtn.style.display = 'none'; // Hide the Stop button when the process stops
  }

  // Add event listener for Start button
  startBtn.addEventListener('click', startRepeating);

  // Add event listener for Stop button
  stopBtn.addEventListener('click', stopRepeating);
})();