Skip to content

Instantly share code, notes, and snippets.

@jgusta
Last active August 13, 2022 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgusta/0d88f95288ce126e34c80d498c1d9f80 to your computer and use it in GitHub Desktop.
Save jgusta/0d88f95288ce126e34c80d498c1d9f80 to your computer and use it in GitHub Desktop.
Run in console of Discord browser app to get a list of all users in the room.
(function () {
return new Promise(async (final) => {
const list = await new Promise((res) => {
let l = document.querySelectorAll("[aria-label=Members]")[0]
.parentElement;
l.scrollTo({ top: 0, left: 0, behavior: "instant" });
setTimeout(() => res(l), 500);
});
let names = [];
const height = list.scrollHeight - window.innerHeight;
const movement = 200
for (i = 0; i < height; i += movement) {
perc = ((i / height) * 100).toFixed(2);
console.log(`scanning names ...${perc}%`);
await new Promise((res) => {
list.scrollBy(0, movement);
setTimeout(()=>{res();}, 500);
});
newnames = await new Promise((res) => {
let elems = Array.from(
document.querySelectorAll(
"[data-list-item-id^=members] [class^=name-] > span > span"
)
);
elems = elems.map((x) => x.innerHTML);
res(elems);
});
names = await new Promise((res) => {
let x = [...names, ...newnames].reduce(
(prev, item) => (prev.includes(item) ? prev : [item, ...prev]),
[]
);
res(x);
});
}
console.log(`done ...100%`);
final(names);
});
})().then(console.log)
@jgusta
Copy link
Author

jgusta commented Aug 13, 2022

One-liner:

new Promise((async e=>{const n=await new Promise((e=>{let n=document.querySelectorAll("[aria-label=Members]")[0].parentElement;n.scrollTo({top:0,left:0,behavior:"instant"}),setTimeout((()=>e(n)),500)}));let o=[];const t=n.scrollHeight-window.innerHeight;for(i=0;i<t;i+=200)perc=(i/t*100).toFixed(2),console.log(`scanning names ...${perc}%`),await new Promise((e=>{n.scrollBy(0,200),setTimeout((()=>{e()}),500)})),newnames=await new Promise((e=>{let n=Array.from(document.querySelectorAll("[data-list-item-id^=members] [class^=name-] > span > span"));n=n.map((e=>e.innerHTML)),e(n)})),o=await new Promise((e=>{e([...o,...newnames].reduce(((e,n)=>e.includes(n)?e:[n,...e]),[]))}));console.log("done ...100%"),e(o)})).then(console.log);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment