Time Hooker

Hook the wait timers for websites that use them to delay content

Από την 29/11/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Time Hooker
// @namespace    https://tampermonkey.net/
// @version      1.1
// @description  Hook the wait timers for websites that use them to delay content
// @author       Niteesh
// @match        *://*/*
// @grant        none
// @license      MIT
// @run-at       document-start
// ==/UserScript==


(function() {
    'use strict';
    
    const originalSetInterval = window.setInterval;
    const originalSetTimeout = window.setTimeout;
    
    function print() {
        console.log(...arguments);
    }
    
    function clearAllTimers() {
        const highestIntervalId = setInterval(() => {}, 0);
        for (let i = 0; i <= highestIntervalId; i++) {
            clearInterval(i);
        }
    
        const highestTimeoutId = setTimeout(() => {}, 0);
        for (let i = 0; i <= highestTimeoutId; i++) {
            clearTimeout(i);
        }
    
        print('Cleared all active timers.');
    }
    
    function restoreOriginalTimers() {
        window.setInterval = originalSetInterval;
        window.setTimeout = originalSetTimeout;
        print("Restoring done.");
    }
    
    function interceptTimers(val) {
        window.setTimeout = function(callback, delay, ...args) {
            const newDelay = delay / val;
            print(`[Intercepted] setTimeout: ${delay}ms -> ${newDelay}ms`);
            return originalSetTimeout(callback, newDelay, ...args);
        };

        window.setInterval = function(callback, interval, ...args) {
            const newInterval = interval / val;
            print(`[Intercepted] setInterval: ${interval}ms -> ${newInterval}ms`);
            return originalSetInterval(callback, newInterval, ...args);
        };
    }
	interceptTimers(15);
    let timerUsed = false;
    let potentialTimers = undefined;
    
    window.onload = function() {
    
        potentialTimers = [...document.querySelectorAll('*')].filter(el => {
    		const text = el.textContent.trim().toLowerCase();
    		const waitRegexes = [
                /wait\s+\d+\s+seconds/i,          
                /please\s+wait/i,                
                /click\s+on\s+(image|button)/i, 
                /click\s+and\s+wait\s+\d+/i
            ];
            return waitRegexes.some(regex => regex.test(text));
    		//return /wait\s+\d+\s+seconds/i.test(text) || /please\s+wait/i.test(text);
    	});
    	if (potentialTimers.length > 0) {
    		print("Potential timers detected:", potentialTimers);
    		timerUsed = true;
    
    	} else {
    		print("No timers detected.");
    		clearAllTimers();
        	restoreOriginalTimers();
    	}
    	
    	if (timerUsed) {
            print("Hacking...");
            
            originalSetInterval(() => {
                const button = document.querySelector('button:enabled, .clickable');
        		const clickable = [...document.querySelectorAll('*')].find(el => 
        			(el.textContent.toLowerCase().includes("continue") || el.textContent.toLowerCase().includes("get link")) && 
        			(el.tagName === 'BUTTON' || el.tagName === 'A') && !el.disabled
        		);
    
        		if (clickable) {
        			print("Clickable element found:", clickable);
        			if (clickable.tagName === 'BUTTON') {
        			     clickable.click();
        			} else if (clickable.tagName === 'A') {
        			     print(clickable.href);
        			     window.location.replace(clickable.href);
        			} else {
        			     print("just trying to click, do you find the exact button?");
        			     clickable.click();
        			}
        			
        		} else {
        			print("No clickable element with found.");
        		}
    		}, 1000);
            
            // dynamically searching for a button
    		const observer = new MutationObserver((mutations) => {
    			mutations.forEach(mutation => {
    				const button = [...document.querySelectorAll('*')].find(el => 
    					(el.textContent.toLowerCase().includes("continue") || el.textContent.toLowerCase().includes("get link")) &&
    					(el.tagName === 'BUTTON' || el.tagName === 'A') && !el.disabled
    				);
    				if (button) {
    					print("Dynamically loaded 'continue' button found:", button);
    					observer.disconnect(); // Stop observing once found
                        button.click();
    					print("clicked");
    				}
    			});
    		});
    
    		// Start observing changes in the DOM
    		observer.observe(document.body, {
    			childList: true,
    			subtree: true
    		});
    	} else {
			clearAllTimers();
        	restoreOriginalTimers();
		}
    }

})();