// ==UserScript== // @name PerplexityTools - Floating Copy Button For Code (AFU IT) // @namespace http://tampermonkey.net/ // @version 1.1 // @description Adds copy button for make copying code easier // @author AFU IT // @match https://www.perplexity.ai/* // @license MIT // @grant none // @downloadURL https://update.greasyfork.icu/scripts/535221/PerplexityTools%20-%20Floating%20Copy%20Button%20For%20Code%20%28AFU%20IT%29.user.js // @updateURL https://update.greasyfork.icu/scripts/535221/PerplexityTools%20-%20Floating%20Copy%20Button%20For%20Code%20%28AFU%20IT%29.meta.js // ==/UserScript== (function() { 'use strict'; const CHECK_INTERVAL = 2000; // Check every 2 seconds // Function to remove existing arrow buttons function removeArrowButtons() { // Find all buttons with the specific styling and SVG content const buttons = document.querySelectorAll('button[style*="position: sticky"][style*="top: 95px"]'); buttons.forEach(button => { const svg = button.querySelector('svg'); if (svg) { const path = svg.querySelector('path'); if (path) { const pathData = path.getAttribute('d'); // Check for up arrow path (M12 19V5M5 12l7-7 7 7) // or down arrow path (M12 5v14M5 12l7 7 7-7) if (pathData === 'M12 19V5M5 12l7-7 7 7' || pathData === 'M12 5v14M5 12l7 7 7-7') { button.remove(); } } } }); } // Floating copy button functionality function addFloatingButtons() { // First remove any existing arrow buttons removeArrowButtons(); // Find all pre elements that don't already have our buttons const codeBlocks = document.querySelectorAll('pre:not(.buttons-added)'); codeBlocks.forEach(block => { // Mark this block as processed block.classList.add('buttons-added'); // Create the copy button with Perplexity's styling const copyBtn = document.createElement('button'); copyBtn.type = 'button'; copyBtn.className = 'focus-visible:bg-offsetPlus dark:focus-visible:bg-offsetPlusDark hover:bg-offsetPlus text-textOff dark:text-textOffDark hover:text-textMain dark:hover:bg-offsetPlusDark dark:hover:text-textMainDark font-sans focus:outline-none outline-none outline-transparent transition duration-300 ease-out font-sans select-none items-center relative group/button justify-center text-center items-center rounded-full cursor-pointer active:scale-[0.97] active:duration-150 active:ease-outExpo origin-center whitespace-nowrap inline-flex text-sm h-8 aspect-square'; copyBtn.style.cssText = ` position: sticky; top: 95px; right: 40px; float: right; z-index: 100; margin-right: 5px; `; copyBtn.innerHTML = `