diff --git a/.dist/localuser.js b/.dist/localuser.js index 97ec9f7..745d945 100644 --- a/.dist/localuser.js +++ b/.dist/localuser.js @@ -11,6 +11,7 @@ import { Settings } from "./settings.js"; import { MarkDown } from "./markdown.js"; const wsCodesRetry = new Set([4000, 4003, 4005, 4007, 4008, 4009]); class Localuser { + badges = new Map(); lastSequence = null; token; userinfo; diff --git a/.dist/user.js b/.dist/user.js index 46ef539..d0537f0 100644 --- a/.dist/user.js +++ b/.dist/user.js @@ -121,6 +121,32 @@ class User { async resolvemember(guild) { return await Member.resolveMember(this, guild); } + async getUserProfile() { + return (await fetch(`${this.info.api}/users/${this.id.replace("#clone", "")}/profile?with_mutual_guilds=true&with_mutual_friends=true`, { + headers: this.localuser.headers + })).json(); + } + resolving = false; + async getBadge(id) { + console.log(id, ":3"); + if (this.localuser.badges.has(id)) { + return this.localuser.badges.get(id); + } + else { + if (this.resolving) { + await this.resolving; + return this.localuser.badges.get(id); + } + const prom = await this.getUserProfile(); + this.resolving = prom; + const badges = prom.badges; + this.resolving = false; + for (const thing of badges) { + this.localuser.badges.set(thing.id, thing); + } + return this.localuser.badges.get(id); + } + } buildpfp() { const pfp = document.createElement('img'); pfp.src = this.getpfpsrc(); @@ -235,6 +261,26 @@ class User { this.setstatus("online"); div.classList.add("hypoprofile", "flexttb"); } + const badgediv = document.createElement("div"); + badgediv.classList.add("badges"); + (async () => { + console.log(this.badge_ids, ":3"); + if (!this.badge_ids) + return; + for (const id of this.badge_ids) { + const badgejson = await this.getBadge(id); + const badge = document.createElement("a"); + badge.classList.add("badge"); + const img = document.createElement("img"); + img.src = badgejson.icon; + badge.append(img); + const span = document.createElement("span"); + span.textContent = badgejson.description; + badge.append(span); + badge.href = badgejson.link; + badgediv.append(badge); + } + })(); { const pfp = await this.buildstatuspfp(); div.appendChild(pfp); @@ -246,6 +292,7 @@ class User { const usernamehtml = document.createElement("h2"); usernamehtml.textContent = this.username; userbody.appendChild(usernamehtml); + userbody.appendChild(badgediv); const discrimatorhtml = document.createElement("h3"); discrimatorhtml.classList.add("tag"); discrimatorhtml.textContent = this.username + "#" + this.discriminator; diff --git a/webpage/localuser.ts b/webpage/localuser.ts index 6ab9684..446aaf7 100644 --- a/webpage/localuser.ts +++ b/webpage/localuser.ts @@ -15,6 +15,7 @@ import { MarkDown } from "./markdown.js"; const wsCodesRetry=new Set([4000,4003,4005,4007,4008,4009]); class Localuser{ + badges:Map=new Map(); lastSequence:number|null=null; token:string; userinfo:Specialuser; diff --git a/webpage/style.css b/webpage/style.css index 0757095..ba785c8 100644 --- a/webpage/style.css +++ b/webpage/style.css @@ -1925,3 +1925,27 @@ form div{ border-radius:.1in; height:17px; } +.badge{ + display:flex; + color:white; + width:fit-content; + img{ + width: .1in; + height: .1in; + } + background: var(--profile-bg); + padding: .04in; + border-radius: .07in; + font-size: .12in; + align-items: center; + border: solid .01in var(--black); + box-sizing: border-box; +} +.badges{ + width:fit-content; + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: flex-start; + align-items: center; +} \ No newline at end of file diff --git a/webpage/user.ts b/webpage/user.ts index 6415ad7..1d33677 100644 --- a/webpage/user.ts +++ b/webpage/user.ts @@ -25,7 +25,7 @@ class User{ premium_since: string; premium_type: number; theme_colors: string; - badge_ids: string; + badge_ids: string[]; members: WeakMap>=new WeakMap(); private status:string; clone(){ @@ -121,6 +121,34 @@ class User{ async resolvemember(guild:Guild){ return await Member.resolveMember(this,guild); } + + async getUserProfile(){ + return (await fetch(`${this.info.api}/users/${this.id.replace("#clone","")}/profile?with_mutual_guilds=true&with_mutual_friends=true`,{ + headers:this.localuser.headers + })).json() + } + resolving:false|Promise=false; + async getBadge(id:string){ + console.log(id,":3") + if(this.localuser.badges.has(id)){ + return this.localuser.badges.get(id); + }else{ + if(this.resolving) + { + await this.resolving; + return this.localuser.badges.get(id); + } + + const prom=await this.getUserProfile(); + this.resolving=prom; + const badges=prom.badges; + this.resolving=false; + for(const thing of badges){ + this.localuser.badges.set(thing.id,thing); + } + return this.localuser.badges.get(id); + } + } buildpfp(){ const pfp=document.createElement('img'); pfp.src=this.getpfpsrc(); @@ -236,7 +264,25 @@ class User{ this.setstatus("online"); div.classList.add("hypoprofile","flexttb"); } - + const badgediv=document.createElement("div"); + badgediv.classList.add("badges"); + (async ()=>{ + console.log(this.badge_ids,":3") + if(!this.badge_ids) return; + for(const id of this.badge_ids){ + const badgejson=await this.getBadge(id); + const badge=document.createElement("a"); + badge.classList.add("badge") + const img=document.createElement("img"); + img.src=badgejson.icon; + badge.append(img); + const span=document.createElement("span"); + span.textContent=badgejson.description; + badge.append(span); + badge.href=badgejson.link; + badgediv.append(badge); + } + })() { const pfp=await this.buildstatuspfp(); div.appendChild(pfp); @@ -248,7 +294,7 @@ class User{ const usernamehtml=document.createElement("h2"); usernamehtml.textContent=this.username; userbody.appendChild(usernamehtml); - + userbody.appendChild(badgediv); const discrimatorhtml=document.createElement("h3"); discrimatorhtml.classList.add("tag"); discrimatorhtml.textContent=this.username+"#"+this.discriminator;