您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Detects and stops URL redirections, loads the original URL, and logs the actions
当前为
// ==UserScript== // @name Nefarious URL Redirect Blocker // @namespace http://tampermonkey.net/ // @version 1.8 // @description Detects and stops URL redirections, loads the original URL, and logs the actions // @match http://*/* // @match https://*/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // Store the original URL const originalUrl = window.location.href; // Flag to track if the script has been activated let scriptActivated = false; // Function to log actions function logAction(message) { console.log(message); } // Function to handle redirection function handleRedirect(event) { // Check if the URL has changed if (window.location.href !== originalUrl && !scriptActivated) { // Set the script activation flag scriptActivated = true; // Stop the redirection event.preventDefault(); event.stopPropagation(); // Log the action logAction('Redirection stopped.'); } } // Function to continuously check for URL changes function checkUrlChange() { if (window.location.href !== originalUrl && !scriptActivated) { // Set the script activation flag scriptActivated = true; // Push the original URL into the browser history window.history.pushState(null, null, originalUrl); // Replace the current URL with the original URL window.history.replaceState(null, null, originalUrl); // Log the action logAction('Redirection stopped. Original URL loaded.'); } // Reset the script activation flag scriptActivated = false; // Schedule the next check setTimeout(checkUrlChange, 100); } // Listen for the beforeunload event (forward direction) window.addEventListener('beforeunload', handleRedirect); // Listen for the popstate event (backward direction) window.addEventListener('popstate', handleRedirect); // Start checking for URL changes checkUrlChange(); })();