Skip to content

Instantly share code, notes, and snippets.

@easrng
Created September 27, 2021 12:32
Show Gist options
  • Save easrng/4471f3a7e496cdb8c5a213635d869ebc to your computer and use it in GitHub Desktop.
Save easrng/4471f3a7e496cdb8c5a213635d869ebc to your computer and use it in GitHub Desktop.
Makes username colors unique and based on user ID
// ==UserScript==
// @name User Colors
// @namespace https://easrng.us.to/
// @match https://discord.com/*
// @grant none
// @version 1.0
// @author easrng
// @description Makes Discord usernames be colored based on userid, not role.
// @run-at document-end
// @inject-into content
// ==/UserScript==
unsafeWindow.wrappedJSObject.eval('('+(async()=>{async function getMod(){console.log("Getting mod");let mod;try{mod=Object.values(webpackJsonp.push([[],{['']:(_,e,r)=>{e.cache=r.c}},[['']]]).cache).find(m=>m.exports&&m.exports.default&&m.exports.default.getUser!==void 0).exports.default;}catch(e){/*console.error(e)*/};if(mod){console.log("got mod");return mod}await new Promise(cb=>setTimeout(cb,200));return getMod()}document.head.appendChild(Object.assign(document.createElement("style"),{textContent:`[class*="username-"][class*="clickable-"]{color:var(--user-id-color)!important;}`}));let mod=await getMod();let realGetUser=mod.getUser.bind(mod);let catchGetUser=false;class GotUserId{constructor(id){this.id=id}}mod.getUser=(...a)=>{if(catchGetUser){throw new GotUserId(a[0])};return realGetUser(...a)};async function recolor(){for(let e of document.querySelectorAll('[class*="username-"][class*="clickable-"]:not([colorized])')){let nu;catchGetUser=true;try{e.__reactProps$.onContextMenu()}catch(e){if(e.constructor==GotUserId){nu=e.id}}catchGetUser=false;let c=new Uint8Array(await crypto.subtle.digest("sha-256",new TextEncoder().encode(nu)));e.style.setProperty("--user-id-color","hsl("+c[0]/255*360+", "+(c[1]/255/2*100+50)+"%, "+(c[2]/255/2*100+50)+"%)");e.dataset.colorized="1"}}recolor();new MutationObserver(function(mutationsList,observer){recolor()}).observe(document.body,{childList:true,subtree:true})}).toString()+")();")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment