navigator.permissions.query({name: "clipboard-write"}).then(result => {
if (result.state == "granted" || result.state == "prompt") {
/* write to the clipboard now */
}
});
function updateClipboard(newClip) {
navigator.clipboard.writeText(newClip).then(function() {
/* clipboard successfully set */
}, function() {
/* clipboard write failed */
});
}
const bodyEle = document.querySelector('body') // Change this 'Body' with any Tag, Class or ID
bodyEle.addEventListener('copy', function(e){
const selection = document.getSelection() // Catch the Selection
const selToStr = selection.toString() // Convert Selection to String
console.log(selToStr) // Display Copied Text
})