Last active
April 30, 2024 11:00
-
-
Save abdullah/ffa8d9c73ced0bc30296765176236892 to your computer and use it in GitHub Desktop.
Selection End Event
This file contains 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
let selectionEndTimeout = null, | |
event = new Event('selectionEnd'); | |
document.addEventListener('selectionEnd', function (evt/*event*/) { | |
console.log("End selection!") | |
}, false); | |
[ | |
"mouseup", | |
"selectionchange" | |
].map(e => { | |
document.addEventListener(e.toString(),(evt/*event*/)=>{ | |
if (selectionEndTimeout && evt.type == "selectionchange") { | |
clearTimeout(selectionEndTimeout); | |
console.info('User Selection Changed'); | |
} | |
selectionEndTimeout = setTimeout(function () { | |
if (evt.type == "mouseup" && window.getSelection().toString() != "") { | |
document.dispatchEvent(event); | |
} | |
}, 100); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Work fine! Thanks