Created
January 10, 2018 04:34
-
-
Save indigo6alpha/dfe56e67f235cffd0732586357e793fe to your computer and use it in GitHub Desktop.
Base64 decode selected text
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 SelectedText = function() {}; | |
SelectedText.prototype.get = function() { | |
var text = ""; | |
if (window.getSelection) { | |
text = window.getSelection().toString(); | |
} else if (document.selection && document.selection.type != "Control") { | |
text = document.selection.createRange().text; | |
} | |
return text; | |
}; | |
SelectedText.prototype.set = function(replacementText) { | |
var sel, range; | |
if (window.getSelection) { | |
sel = window.getSelection(); | |
if (sel.rangeCount) { | |
range = sel.getRangeAt(0); | |
range.deleteContents(); | |
range.insertNode(document.createTextNode(replacementText)); | |
} | |
} else if (document.selection && document.selection.createRange) { | |
range = document.selection.createRange(); | |
range.text = replacementText; | |
} | |
}; | |
try { | |
var sText = new SelectedText(); | |
var decodedText = atob(sText.get()); | |
sText.set(decodedText); | |
} catch(e) { | |
alert(e.message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment