Skip to content

Commit

Permalink
add usrbg, i expected that to be harder, neat
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Jun 29, 2024
1 parent 95d6852 commit e587ea1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 53 additions & 0 deletions plugins/usrbg/index.tsx
Original file line number Diff line number Diff line change
@@ -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<string, string>();
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})`,
});
},
);
}
5 changes: 5 additions & 0 deletions plugins/usrbg/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "usrbg",
"author": "Yellowsink",
"description": "Loads usrbgs in an efficient and stable manner."
}

0 comments on commit e587ea1

Please sign in to comment.