Hi
- User
Hi
- Assistant
Hello! How can I assist you today?
- User
TamperMonkey script to copy text button
- Assistant
Sure, you can create a Tampermonkey script that adds a button to a webpage, and when this button is clicked, it copies specific text to the clipboard. Below is a basic example of how you might achieve this.
Steps to Create the Script
-
Install Tampermonkey: If you haven't already, you need to install the Tampermonkey extension for your browser.
-
Create a New Script: Open the Tampermonkey dashboard and create a new script.
-
Paste the Script: Copy and paste the following script into the script editor:
// ==UserScript== // @name Copy Text Button // @namespace http://tampermonkey.net/ // @version 1.0 // @description Adds a button to copy text to clipboard // @author You // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Provide the text you want to copy here const textToCopy = "This is the text to copy!"; // Create the button const button = document.createElement('button'); button.innerHTML = 'Copy Text'; button.style.position = 'fixed'; button.style.top = '10px'; button.style.right = '10px'; button.style.zIndex = 1000; // Ensure the button is on top of other elements // Add click event to the button button.addEventListener('click', () => { // Create a temporary textarea element to hold the text const tempTextArea = document.createElement('textarea'); tempTextArea.value = textToCopy; document.body.appendChild(tempTextArea); // Select the text and copy it to clipboard tempTextArea.select(); document.execCommand('copy'); // Remove the temporary textarea document.body.removeChild(tempTextArea); // Provide feedback to the user (Optional) alert('Text copied to clipboard!'); }); // Append the button to the body document.body.appendChild(button); })();Explanation
-
Script Metadata:
@name: The name of your script.@namespace: Used to distinguish your script from others of the same name.@version: Version of the script.@description: A brief description of what the script does.@author: Your name or username.@match: Specifies the URLs where the script should run (currently set to all URLs).
-
Main Function:
- Creates a button with the label "Copy Text".
- Attaches the button to the page, positioning it fixed at the top-right corner.
- Adds an event listener to the button to copy predefined text to the clipboard when clicked.
- Uses a temporary
textareaelement to facilitate copying the text to the clipboard. - Optionally, provides a popup alert to inform the user that the text has been copied.
-
Save and Activate: Save the script and make sure it's enabled in the Tampermonkey dashboard.
-
Test: Navigate to any webpage within the
@matchdomain(s) specified to see the button and test its functionality.
Feel free to customize the
textToCopyvariable and the button's styles and behaviors to better suit your needs. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →