Created
August 14, 2025 19:29
-
-
Save blizzrdof77/657a9ac3f58e7f1cb9dbf27590cbbec7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clipboard = { | |
"isSecureContent": function() { | |
return (window.isSecureContext && navigator.clipboard); | |
}, | |
"secureCopy": function(text) { | |
navigator.clipboard.writeText(text) | |
}, | |
"insecureCopy": function(text) { | |
const textArea = document.createElement("textarea"); | |
textArea.value = text; | |
document.body.appendChild(textArea); | |
textArea.focus(); | |
textArea.select(); | |
try { | |
document.execCommand('copy'); | |
} catch(err) { | |
console.error('Unable to copy to clipboard', err); | |
} | |
document.body.removeChild(textArea) | |
}, | |
"copy": function(content) { | |
var text = (function() { | |
if (typeof content === 'string') { | |
return content; | |
} else if (typeof content === 'object') { | |
return $(content)[0].innerText; | |
} else if (document.getSelection().toString().length > 0) { | |
return document.getSelection().toString(); | |
} | |
})(); | |
if (this.isSecureContent()) { | |
this.secureCopy(text); | |
} else { | |
this.insecureCopy(text); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment