Created
October 14, 2015 20:22
-
-
Save bennettscience/d888e5b896c1145cef81 to your computer and use it in GitHub Desktop.
Takes a window selection and downloads a plaintext file.
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
var text = ""; | |
function getPlainText() { | |
if(window.getSelection == undefined) { | |
alert("There is no text selected. Please select some text from the page and try again.") | |
} else { | |
text = window.getSelection().toString(); | |
console.log(text); | |
var download = document.getElementById('download'); | |
download.href = 'data:text/plain;charset:utf-8,' + encodeURIComponent(text); | |
var event = new MouseEvent('click'); | |
download.dispatchEvent(event); | |
} | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment