Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active January 9, 2024 14:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cowboy/bc0d6039a3aa5d60b44da897923b8c9c to your computer and use it in GitHub Desktop.
Save cowboy/bc0d6039a3aa5d60b44da897923b8c9c to your computer and use it in GitHub Desktop.
reddit megalinks: attempt to base64 decode all words 16+ chars in length
javascript:(function()%7B%5B...document.querySelectorAll('.usertext-body%20*')%5D.forEach(p%20%3D%3E%5B...p.childNodes%5D.filter(n%20%3D%3E%20n.nodeType%20%3D%3D%3D%203).forEach(n%20%3D%3E%20%7Bconst%20re%20%3D%20%2F%5CS%7B16%2C%7D%2Fg%3Bif%20(re.test(n.nodeValue))%20%7Btry%20%7Blet%20isHtml%2C%20child%3Bconst%20s%20%3D%20n.nodeValue.replace(re%2C%20s%20%3D%3E%20%7Bs%20%3D%20atob(s)%3Bif%20(%2F%5Ehttps%3F%3A%5C%2F%5C%2F%2F.test(s))%20%7Bs%20%3D%20%60%3Ca%20href%3D%22%24%7Bs%7D%22%20target%3D_blank%3E%24%7Bs%7D%3C%2Fa%3E%60%3BisHtml%20%3D%20true%3B%7Dreturn%20s%3B%7D)%3Bif%20(isHtml)%20%7Bconst%20tmp%20%3D%20document.createElement('div')%3Btmp.innerHTML%20%3D%20s%3Bchild%20%3D%20document.createDocumentFragment()%3B%5B...tmp.childNodes%5D.forEach(c%20%3D%3E%20child.append(c))%3B%7D%20else%20%7Bchild%20%3D%20document.createTextNode(s)%3B%7Dp.replaceChild(child%2C%20n)%3B%7D%20catch%20(e)%20%7B%7D%7D%7D))%7D)()
[...document.querySelectorAll('.usertext-body *')]
.forEach(p =>
[...p.childNodes]
.filter(n => n.nodeType === 3)
.forEach(n => {
const re = /\S{16,}/g;
if (re.test(n.nodeValue)) {
try {
let isHtml, child;
const s = n.nodeValue.replace(re, s => {
s = atob(s);
if (/^https?:\/\//.test(s)) {
s = `<a href="${s}" target=_blank>${s}</a>`;
isHtml = true;
}
return s;
});
if (isHtml) {
const tmp = document.createElement('div');
tmp.innerHTML = s;
child = document.createDocumentFragment();
[...tmp.childNodes].forEach(c => child.append(c));
} else {
child = document.createTextNode(s);
}
p.replaceChild(child, n);
} catch (e) {}
}
})
)
@cowboy
Copy link
Author

cowboy commented Mar 12, 2018

@Carlostaylorff
Copy link

Thanks .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment