-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add usrbg, i expected that to be harder, neat
- Loading branch information
1 parent
95d6852
commit e587ea1
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})`, | ||
}); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} |