Skip to content

Instantly share code, notes, and snippets.

@spencerpogo
Created February 11, 2021 19:08
Show Gist options
  • Save spencerpogo/737b96487e4aaffda9807b3bf6d93c7c to your computer and use it in GitHub Desktop.
Save spencerpogo/737b96487e4aaffda9807b3bf6d93c7c to your computer and use it in GitHub Desktop.
Use simplediscordcrypt in web console or on discord
(function fixLocalStorage() {
// https://stackoverflow.com/a/53773662/9196137
// If we create an <iframe> and connect it to our document, its
// contentWindow property will return a new Window object with
// a freshly created `localStorage` property. Once we obtain the
// property descriptor, we can disconnect the <iframe> and let it
// be collected — the getter function itself doesn’t depend on
// anything from its origin realm to work**.
function getLocalStoragePropertyDescriptor() {
const iframe = document.createElement("iframe");
document.head.append(iframe);
const pd = Object.getOwnPropertyDescriptor(
iframe.contentWindow,
"localStorage"
);
iframe.remove();
return pd;
}
Object.defineProperty(
window,
"localStorage",
getLocalStoragePropertyDescriptor()
);
})();
// -- temporary hack to get simplediscordcrypt working in discord desktop console --
// By Scoder12
// Discord CSP allows fetching from 127.0.0.1:* so we can host the script locally and
// fetch and eval it from the console
// Setup:
// curl -sSLo main.js https://gitlab.com/An0/SimpleDiscordCrypt/-/raw/master/SimpleDiscordCrypt.user.js
// curl -sSlo blacklist.txt https://gitlab.com/An0/SimpleDiscordCrypt/raw/master/blacklist.txt
// Replace BLACKLIST_URL value with http://127.0.0.1:35181/blacklist.txt
// Setup part 2 Host:
// place the following in server.py
/*
#!/usr/bin/env python3
from http.server import HTTPServer, SimpleHTTPRequestHandler, test
import sys
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Access-Control-Allow-Origin', 'https://discord.com')
SimpleHTTPRequestHandler.end_headers(self)
if __name__ == '__main__':
test(CORSRequestHandler, HTTPServer, bind="127.0.0.1", port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
*/
// python3 server.py 35181
// now, in discord press ctrl+shift+i, then click console, and paste this entire file in
(async function loadDcrypt() {
const port = 35181;
const filename = "main.js";
const r = await fetch(`http://127.0.0.1:${port}/${filename}`);
if (r.status != 200) {
console.error(`Fetch error (status ${r.status} ${r.statusText})`, r);
return;
}
const code = await r.text();
console.log(
`Sucessfully fetched dcrypt js (${code.length} bytes), evalling...`
);
window._dcrypt_src = code;
console.log(code.split("\n").slice(0, 35).join("\n"));
eval(code);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment