CopyAnything

AMEND09
2025-06-19T20:41:59Z

Allows highlighting and copying text on websites where it might be disabled by overriding CSS and removing common disabling attributes.

README: CopyAnything Greasemonkey Script

CopyAnything

This is a user script designed for Greasemonkey, Tampermonkey, and similar browser extensions. Its purpose is to overcome common restrictions imposed by websites that prevent users from highlighting, selecting, or copying text.

How It Works

The script employs a multi-pronged approach to ensure text selection and copying are enabled:

1. CSS Override: It injects CSS rules with !important declarations that force all elements on the webpage to have user-select: text. This overrides any styles set by the website that might try to disable text selection (e.g., user-select: none). It includes vendor prefixes (-webkit-, -moz-, -ms-) for broader browser compatibility.

2. Attribute Removal: Many websites use JavaScript event handlers attached directly to HTML elements to prevent interactions. This script identifies and removes common attributes like:

onselectstart: Prevents text selection from starting.

ondragstart: Prevents elements from being dragged, which can sometimes interfere with text selection.

oncontextmenu: Prevents the right-click context menu from appearing, which often contains the "Copy" option.

3. Dynamic Content Handling (MutationObserver): Modern websites frequently load content dynamically after the initial page load. A simple one-time fix isn't enough for such sites. This script uses a MutationObserver to continuously monitor the webpage for changes. If new elements are added to the DOM or existing elements have their attributes modified, the script automatically applies the CSS overrides and removes disabling attributes to the new or changed content in real-time.

Key Features

Enables Text Selection: Allows you to highlight and select text on pages where it was previously disabled.

Restores Copy Functionality: By enabling selection and context menus, it facilitates copying text.

Handles Dynamic Content: Works effectively on single-page applications and sites that load content after the initial page render.

Lightweight: Designed to be efficient with minimal performance impact.

Installation

To use this script, you'll need a user script manager extension installed in your web browser. Popular options include:

Tampermonkey (Recommended for Chrome, Brave, Edge, Opera, Safari, Firefox)

Greasemonkey (For Firefox)

Steps:

1. Install the Extension: Download and install either Tampermonkey or Greasemonkey from your browser's official extension store.

2. Create a New Script: Once installed, click on the extension icon in your browser's toolbar and choose "Create a new script" (Tampermonkey) or "New User Script" (Greasemonkey).

3. Paste the Code: A new editor tab will open. Delete any pre-existing code in this tab, then copy the entire content of the greasemonkey-text-enabler.js script and paste it into the editor.

4. Save: Save the script (usually via File > Save or Ctrl+S/Cmd+S).

5. Refresh Page: Navigate to the desired webpage and refresh it. The script should now be active.

Script made by Aditya Mendiratta