Skip to content

Instantly share code, notes, and snippets.

@indigo6alpha
Created January 10, 2018 04:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indigo6alpha/dfe56e67f235cffd0732586357e793fe to your computer and use it in GitHub Desktop.
Save indigo6alpha/dfe56e67f235cffd0732586357e793fe to your computer and use it in GitHub Desktop.
Base64 decode selected text
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