anjo.geee / Click Search Bar Input and Random Mouse Mover

// ==UserScript==
// @name         Click Search Bar Input and Random Mouse Mover
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Clicks the search input and moves the mouse randomly
// @author       Your Name
// @match        http://xviews.42web.io/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to click and focus the search input
    function clickSearchInput() {
        const searchInput = document.querySelector(".search-input"); // Select the input field by class
        console.log("Searching for input field..."); // Debug log
        if (searchInput) {
            console.log("Input field found, focusing..."); // Debug log
            searchInput.focus(); // Focus on the input field
            searchInput.dispatchEvent(new Event('focus', { bubbles: true })); // Trigger focus event
            searchInput.dispatchEvent(new MouseEvent('mousedown')); // Simulate mouse down
            searchInput.dispatchEvent(new MouseEvent('mouseup')); // Simulate mouse up
            searchInput.dispatchEvent(new MouseEvent('click')); // Simulate click
        } else {
            console.log("Input field not found."); // Debug log
        }
    }

    // Function to move the mouse randomly
    function randomMouseMovement() {
        const randomX = Math.floor(Math.random() * window.innerWidth);
        const randomY = Math.floor(Math.random() * window.innerHeight);
        
        // Create a mouse event
        const mouseEvent = new MouseEvent('mousemove', {
            bubbles: true,
            cancelable: true,
            clientX: randomX,
            clientY: randomY
        });

        // Dispatch the event
        document.dispatchEvent(mouseEvent);
    }

    // Click the search input when the page is loaded
    window.addEventListener('load', () => {
        clickSearchInput();
        
        // Move mouse randomly every 3 seconds
        setInterval(randomMouseMovement, 3000);
    });
})();