Skip to content

Instantly share code, notes, and snippets.

@blizzrdof77
Created August 14, 2025 19:29
Show Gist options
  • Save blizzrdof77/657a9ac3f58e7f1cb9dbf27590cbbec7 to your computer and use it in GitHub Desktop.
Save blizzrdof77/657a9ac3f58e7f1cb9dbf27590cbbec7 to your computer and use it in GitHub Desktop.
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