Last active
April 6, 2018 19:10
-
-
Save developit/1f31408ceee234fc0a6dced03da668f2 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
| function getClipboardText(e) { | |
| return Promise.resolve().then(function(){ | |
| return navigator.permissions.query({ name: 'clipboard-read' }) | |
| }).then(function(r) { | |
| return r.state=='granted' && navigator.clipboard.readText() | |
| }).catch(Object).then(function(t) { | |
| return typeof t=='string' ? t : e.clipboardData.getData('text/plain') | |
| }) | |
| } | |
| /* @example | |
| * document.addEventListener('paste', function (e) { | |
| * getClipboardText(e).then(function (text) { | |
| * console.log(text) | |
| * }) | |
| * }) | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment