From b92d7226e490a0453bb661518e5994b9ce879203 Mon Sep 17 00:00:00 2001 From: Er2 Date: Sun, 24 Apr 2022 20:14:41 +0300 Subject: [PATCH] add webpack injection --- Makefile | 2 +- manifest.json | 5 +--- package.json | 2 +- src/script/inj.coffee | 7 +++++ src/script/webpack.coffee | 63 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/script/webpack.coffee diff --git a/Makefile b/Makefile index a97dac0..3739d46 100644 --- a/Makefile +++ b/Makefile @@ -28,4 +28,4 @@ out/css/base.css: src/style/base.less $(OSTYLES) npx lessc $< > $@ out/js/%.js: src/script/%.coffee - npx coffee --no-header -bco $@ $< + npx coffee --no-header -co $@ $< diff --git a/manifest.json b/manifest.json index 3f72750..79ef808 100644 --- a/manifest.json +++ b/manifest.json @@ -5,10 +5,6 @@ "description": "Custom theme for Discord", - "icons": { - "48": "ext.png" - }, - "permissions": [ "https://raw.githubusercontent.com/Er2ch/diskort/*", "*://discord.com/", @@ -21,6 +17,7 @@ "persistent": true }, + "web_accessible_resources": ["js/webpack.js"], "content_scripts": [{ "matches": ["*://discord.com/*"], "js": ["js/inj.js"] diff --git a/package.json b/package.json index fc8a8d8..d8c8d7a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "3.0.0", "description": "Custom script and style engine for Discord", "dependencies": { - "coffeescript": "^2.6.1", + "coffeescript": "^2.7.0", "lessc": "^1.0.2" } } diff --git a/src/script/inj.coffee b/src/script/inj.coffee index e690a17..c58813d 100644 --- a/src/script/inj.coffee +++ b/src/script/inj.coffee @@ -10,6 +10,13 @@ base = 'https://raw.githubusercontent.com/Er2ch/diskort/main/' inject = -> + # inject webpack reader + s = document.createElement 'script' + s.setAttribute 'type', 'text/javascript' + s.setAttribute 'src', chrome.extension.getURL 'js/webpack.js' + document.head.appendChild s + + # inject style try resp = await fetch base + 'btfl.css' text = await resp.text() diff --git a/src/script/webpack.coffee b/src/script/webpack.coffee new file mode 100644 index 0000000..d8443a4 --- /dev/null +++ b/src/script/webpack.coffee @@ -0,0 +1,63 @@ +### DisKort +# (c) Er2 2022 +# Zlib License +### + +# Find and use Discord obfuscated webpack modules +window.webpack = {} + +# Helper functions +window.ModGetsAll = => + Object.values webpack.cache + .filter (m) => m.exports + +window.ModGet = (filt, first = true) => + if Array.isArray filt + key = filt + filt = (m) => key.every (k) => m.hasOwnProperty(k) or (m.__proto__ and m.__proto__.hasOwnProperty k) + + mods = ModGetsAll() + m = [] + for i of mods + continue if not mods.hasOwnProperty i + mod = mods[i] + {exports} = mod + continue if not exports + exports = exports.default if exports.default + continue if not filt exports + return exports if first + m.push exports + + first or m.length is 0 and null or m + +window.ModGets = (filt) => + ModGet filt, false + +window.ModGetName = (name, ret, forev) => + ModGet (m) => m.displayName?.toLowerCase() is name.toLowerCase() + +window.WinProps = => + platform: window.platform + GLOBAL_ENV: window.GLOBAL_ENV + DiscordSentry: window.DiscordSentry + __SENTRY__: window.__SENTRY__ + +console.log 'Welcome to DisKort!' + +init = => + while not window.webpackChunkdiscord_app or not window._ + await new Promise (res) => setTimeout res, 100 + + console.log 'Ready to inject' + + webpackChunkdiscord_app.push [ + [[ 'diskort' ]] + {} + (r) => + webpack.cache = r.c + webpack.require = (m) => r m + return + ] + return + +init()