// ==UserScript== // @name Univeral Copy // @version 0.1 // @description try to take over the world! // @author SmartManoj // @namespace https://github.com/SmartManoj // @match * // @grant unsafeWindow // @grant GM_setClipboard // @updateURL https://raw.githubusercontent.com/SmartManoj/SmartUserScripts/master/Univeral_Copy.user.js // ==/UserScript== function fallbackCopyTextToClipboard(text) { var textArea = document.createElement("textarea"); textArea.value = text; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Fallback: Copying text command was ' + msg); } catch (err) { console.error('Fallback: Oops, unable to copy', err); } document.body.removeChild(textArea); } function copyTextToClipboard(text) { if (!navigator.clipboard) { fallbackCopyTextToClipboard(text); return; } navigator.clipboard.writeText(text).then(function() { console.log('Async: Copying to clipboard was successful!'); }, function(err) { console.error('Async: Could not copy text: ', err); }); } unsafeWindow.fallbackCopyTextToClipboard=fallbackCopyTextToClipboard unsafeWindow.copyTextToClipboard=copyTextToClipboard