add webpack injection

This commit is contained in:
Er2 2022-04-24 20:14:41 +03:00
parent 8eac634cb8
commit b92d7226e4
5 changed files with 73 additions and 6 deletions

View File

@ -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 $@ $<

View File

@ -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"]

View File

@ -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"
}
}

View File

@ -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()

63
src/script/webpack.coffee Normal file
View File

@ -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()