Greasy Fork is available in English.

Stop Nefarious Redirects

Block unauthorized redirects and prevent history manipulation

Forfatter
slyfox1186
Daglige installasjoner
1
Totale installasjoner
503
Vurderinger
2 0 0
Versjon
4.1
Lagd
09.04.2024
Oppdatert
28.06.2024
Lisens
MIT
Gjelder
Alle sider

Stop Nefarious Redirects

Description

The "Stop Nefarious Redirects" Tampermonkey script is designed to block unauthorized redirects and prevent history manipulation on websites. This script helps users maintain control over their browsing experience by ensuring that only trusted URLs can navigate or open new windows, thus protecting against malicious redirections.

Features

  • Block Unauthorized Redirects: Prevents navigation to blacklisted URLs, keeping you safe from malicious websites.
  • Popup Control: Allows popups only from whitelisted domains.
  • History Manipulation Prevention: Protects against unauthorized changes to your browser history, ensuring that your back and forward navigation remains intact.
  • Automated and Manual Blacklists: Supports both automated and manual URL blacklists for comprehensive protection.
  • Real-time Alerts: Alerts and logs blocked attempts for better transparency and debugging.

How It Works

Initialization

  1. Script Metadata: The script includes metadata such as name, namespace, version, description, match patterns, grants, license, run-at directive, download URL, and update URL.
  2. Strict Mode Activation: The script runs in strict mode to enforce stricter parsing and error handling.
  3. Logging Initialization: Logs a message indicating that the script initialization has started.

Blacklists and Whitelists

  1. Manual Blacklist: A set of manually specified URLs that should always be blocked.
  2. Allowed Popups Whitelist: An empty set initialized for allowed popup domains, with a comment to indicate where to add domains manually.

Blacklist Management Functions

  1. Automated Blacklist Retrieval: Retrieves the automated blacklist from Tampermonkey storage.
  2. Add to Automated Blacklist: Adds a URL to the automated blacklist if it is not already present.
  3. Display Blacklist: Displays the combined manual and automated blacklist in the console and an alert box.

URL Handling Functions

  1. Check URL Allowed: Checks if a URL is allowed by comparing it against both the manual and automated blacklists.
  2. Handle Navigation: Handles navigation attempts by blocking or allowing them based on the blacklist checks. Blocks navigation to blacklisted URLs and redirects to the last known good URL if necessary.

Overriding Default Behavior

  1. Save Original Methods: Saves the original window.location.assign and window.open methods for later use.
  2. Override window.location.assign: Overrides the window.location.assign method to check the destination URL against the whitelist and blacklist before allowing the navigation.
  3. Override window.open: Overrides the window.open method to check if the popup's URL is in the whitelist. If not, the popup is blocked.

Proxy for window.location

  1. Proxy Setup: Creates a proxy for window.location to intercept property assignments and handle navigation attempts.
  2. Proxy Assignment: The proxy is assigned to window.location using Object.defineProperty to ensure it is always used.

Handling Browser History

  1. Popstate Event Listener: Adds an event listener for popstate events to handle back and forward button navigation. If the destination URL is not allowed, it blocks the navigation and redirects to the last known good URL.
  2. History Manipulation Functions: Wraps history.pushState and history.replaceState to prevent history manipulation to blocked URLs.

Finalization

  1. Initialization Complete: Logs a message indicating that the redirect control script with the blacklist has been initialized.

Installation

  1. Install the Tampermonkey extension for your browser.
  2. Click on the download link to add the script to Tampermonkey.
  3. Customize the allowed popups whitelist by editing the script and adding your trusted domains.

Conclusion

The "Stop Nefarious Redirects" script is a powerful tool to enhance your browsing security by blocking malicious redirects and preventing unauthorized history manipulation. Install this script to take control of your web navigation and protect yourself from nefarious online activities.