Skip to content

Instantly share code, notes, and snippets.

@magasine
Created August 31, 2022 22:59
Show Gist options
  • Save magasine/c2d4c22ca0f4f859126eeca2f04ce67e to your computer and use it in GitHub Desktop.
Save magasine/c2d4c22ca0f4f859126eeca2f04ce67e to your computer and use it in GitHub Desktop.
! ROT13 - Bookmarklet
javascript: var coding =
"abcdefghijklmnopqrstuvwxyzabcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM";
function rot13(t) {
for (var r = "", i = 0; i < t.length; i++) {
character = t.charAt(i);
position = coding.indexOf(character);
if (position > -1) character = coding.charAt(position + 13);
r += character;
}
return r;
}
S = window.getSelection();
function t(N) {
return N.nodeType == N.TEXT_NODE;
}
function r(N) {
if (t(N)) N.data = rot13(N.data);
}
for (j = 0; j < S.rangeCount; ++j) {
var g = S.getRangeAt(j),
e = g.startContainer,
f = g.endContainer,
E = g.startOffset,
F = g.endOffset,
m = e == f;
if (!m || !t(e)) {
q = document.createTreeWalker(
g.commonAncestorContainer,
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
null,
false
);
q.currentNode = e;
for (N = q.nextNode(); N && N != f; N = q.nextNode()) r(N);
}
if (t(f)) f.splitText(F);
if (!m) r(f);
if (t(e)) {
r((k = e.splitText(E)));
if (m) f = k;
e = k;
}
if (t(f)) g.setEnd(f, f.data.length);
}
void 0;
// Rotate by 13 places (Concept: https://en.wikipedia.org/wiki/ROT13)
// Low complexity cryptographic algorithm
// Usage: Select text and trigger bookmarklet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment