mirror of
https://github.com/xyzeva/k-id-age-verifier.git
synced 2026-06-04 22:18:01 +02:00
Update snippet to use findByCode (#1)
The previous snippet uses variables that might change in future discord builds Co-authored-by: NotNite <hi@notnite.com>
This commit is contained in:
+35
-17
@@ -32,30 +32,48 @@
|
||||
up
|
||||
<span class="text-white/70">(typing "allow pasting" before if necessary)</span>:
|
||||
</p>
|
||||
<pre class="my-4 bg-white/10 p-5 text-wrap">// add a chunk to get all of the webpack chunks
|
||||
_mods = webpackChunkdiscord_app.push([[Symbol()],{},r=>r.c]);
|
||||
webpackChunkdiscord_app.pop(); // cleanup the chunk we added
|
||||
<pre class="my-4 bg-white/10 p-5 text-wrap">
|
||||
// add a chunk to extract webpack's moduleCache
|
||||
let webpackRequire = webpackChunkdiscord_app.push([[Symbol()],{},(r) => r]);
|
||||
// cleanup the chunk we added
|
||||
webpackChunkdiscord_app.pop();
|
||||
|
||||
// utility to find a webpack chunk by property
|
||||
findByProps = (...props) => {
|
||||
for (let m of Object.values(_mods)) {
|
||||
try {
|
||||
if (!m.exports || m.exports === window) continue;
|
||||
if (props.every((x) => m.exports?.[x])) return m.exports;
|
||||
let modules = webpackRequire.m;
|
||||
let cache = webpackRequire.c;
|
||||
|
||||
for (let ex in m.exports) {
|
||||
if (props.every((x) => m.exports?.[ex]?.[x]) && m.exports[ex][Symbol.toStringTag] !== 'IntlMessagesProxy') return m.exports[ex];
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
// https://github.com/moonlight-mod/moonlight/blob/main/packages/core-extensions/src/spacepack/webpackModules/spacepack.ts
|
||||
// helper to find a webpack module via code snippet
|
||||
function findByCode(src) {
|
||||
for (const [id, mod] of Object.entries(modules)) {
|
||||
if (mod.toString().includes(src)) {
|
||||
return cache[id].exports;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper to find an object by its key
|
||||
function findObjectFromKey(exports, key) {
|
||||
if (!exports) return;
|
||||
for (const exportKey in exports) {
|
||||
const obj = exports[exportKey];
|
||||
if (obj && obj[key]) return obj;
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/moonlight-mod/moonlight/blob/main/packages/mappings/src/mappings/discord/utils/HTTPUtils.ts
|
||||
// find the discord api client
|
||||
api = findByProps('Bo','oh').Bo
|
||||
const api = findObjectFromKey(
|
||||
findByCode('.set("X-Audit-Log-Reason",'),
|
||||
"patch",
|
||||
);
|
||||
|
||||
// send a api request to discord /age-verification/verify and then redirect the page to our website
|
||||
window.location.href = `https://age-verifier.kibty.town/webview?url=${encodeURIComponent((await api.post({ url: '/age-verification/verify', body: { method: 3 }})).body.verification_webview_url)}`</pre>
|
||||
const request = await api.post({
|
||||
url: "/age-verification/verify",
|
||||
body: { method: 3 },
|
||||
});
|
||||
const verificationUrl = request.body.verification_webview_url;
|
||||
window.location.href = `https://age-verifier.kibty.town/webview?url=${encodeURIComponent(verificationUrl)}`;</pre>
|
||||
<p class="text-center text-white/50">
|
||||
(feel free to read the code, we made it readable and we have nothing to hide)
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user