make a userscript that shows a button on tope left corner that runs a function
- User
make a userscript that shows a button on tope left corner that runs a function
- Assistant
Sure! Here's an example of a user script that adds a button to the top left corner of the page and runs a function when clicked:
// ==UserScript== // @name Button Example // @namespace http://tampermonkey.net/ // @version 1.0 // @description Adds a button to the top left corner of the page // @author Your Name // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Create the button element const button = document.createElement('button'); button.style.position = 'fixed'; button.style.top = '10px'; button.style.left = '10px'; button.textContent = 'Click Me'; // Append the button to the page body document.body.appendChild(button); // Add event listener to the button click event button.addEventListener('click', function() { // Call your custom function here yourFunction(); }); // Function to be called when the button is clicked function yourFunction() { alert('Button Clicked!'); // Add your custom logic here } })(); - User
make it so that the button appears in front of <div class="media" on the top left corner
- Assistant
To make the button appear in front of a
<div class="media">element, you can modify the user script as follows:// ==UserScript== // @name Button Example // @namespace http://tampermonkey.net/ // @version 1.0 // @description Adds a button to the top left corner of the page in front of <div class="media"> // @author Your Name // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Create the button element const button = document.createElement('button'); button.style.position = 'fixed'; button.style.top = '10px'; button.style.left = '10px'; button.style.zIndex = '9999'; // Set a higher z-index to appear in front button.textContent = 'Click Me'; // Append the button to the page body document.body.appendChild(button); // Find the first <div class="media"> element const mediaElement = document.querySelector('div.media'); // If a <div class="media"> element is found, get its position and adjust the button's position accordingly if (mediaElement) { const rect = mediaElement.getBoundingClientRect(); button.style.top = rect.top + 'px'; button.style.left = rect.left + 'px'; } // Add event listener to the button click event button.addEventListener('click', function() { // Call your custom function here yourFunction(); }); // Function to be called when the button is clicked function yourFunction() { alert('Button Clicked!'); // Add your custom logic here } })();
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.