From e587ea11ff57d00be6d157f8686d677648020dad Mon Sep 17 00:00:00 2001 From: Hazel Atkinson Date: Sat, 29 Jun 2024 22:04:33 +0100 Subject: [PATCH] add usrbg, i expected that to be harder, neat --- README.md | 2 ++ plugins/usrbg/index.tsx | 53 +++++++++++++++++++++++++++++++++++++++ plugins/usrbg/plugin.json | 5 ++++ 3 files changed, 60 insertions(+) create mode 100644 plugins/usrbg/index.tsx create mode 100644 plugins/usrbg/plugin.json diff --git a/README.md b/README.md index b0738bc..e5e9d3f 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,5 @@ No Devtools Detection: https://yellowsink.github.io/shelter-plugins/no-devtools- - Prevents the annoying "Wait" and "Hold Up" logs - Prevents you from being logged out of your session if you reload with the devtools open, or if you use a browser with vertical tabs, being logged out every single session! + +usrbg: https://yellowsink.github.io/shelter-plugins/usrbg \ No newline at end of file diff --git a/plugins/usrbg/index.tsx b/plugins/usrbg/index.tsx new file mode 100644 index 0000000..82b5e04 --- /dev/null +++ b/plugins/usrbg/index.tsx @@ -0,0 +1,53 @@ +const { + flux: { subscribe }, + observeDom, +} = shelter.plugin.scoped; + +const { getFiber, reactFiberWalker } = shelter.util; + +// todo: did this move? or is it just dead forever? +const dbUrl = `https://cdn.jsdelivr.net/gh/Discord-Custom-Covers/usrbg@63fbbbe59880e284ff84d881c2f35413d5d5ae80/dist/usrbg.json`; + +const db = fetch(dbUrl) + .then((r) => r.json()) + .then((raw) => { + const m = new Map(); + for (const o of raw) m.set(o.uid, o.img); + + return m; + }); + +["TRACK"].forEach((t) => subscribe(t, onDispatch)); + +function onDispatch(payload) { + if (payload.type === "TRACK" && payload.event !== "user_profile_action") + return; + + // user popouts + const unobs = observeDom( + `svg > foreignObject > [class*=banner]`, + async (e) => { + unobs(); + + // ignore users with a custom nitro banner + if (e.matches("[class*=bannerPremium]")) return; + + // get user + const user = reactFiberWalker(getFiber(e), "displayProfile", true) + ?.memoizedProps?.user; + if (!user) return; + + // get bg + const usrbg = (await db).get(user?.id); + if (!usrbg) return; + + // apply bg + Object.assign(e.style, { + "background-repeat": "no-repeat", + "background-position": "center", + "background-size": "cover", + "background-image": `url(${usrbg})`, + }); + }, + ); +} diff --git a/plugins/usrbg/plugin.json b/plugins/usrbg/plugin.json new file mode 100644 index 0000000..a06b9e2 --- /dev/null +++ b/plugins/usrbg/plugin.json @@ -0,0 +1,5 @@ +{ + "name": "usrbg", + "author": "Yellowsink", + "description": "Loads usrbgs in an efficient and stable manner." +}