touch index.html;for f in e/*; do echo "<a href=\"https://divsel.neocities.org/e/$(basename $f)\"><img src=\"$(basename $f)\" alt=\"$(basename $f)\"></a>" >> index.html; done
This is a page I assembled with that line after using the code at the bottom of the page in the Discord console to generate wget commands to get all of these...
// Take note of the warning about not pasting things into the console that you don't understand.
// Paste this into the Discord console
// Then browse discord as normal... Any emote you encounter in chat will be scraped.
const chatContent = document.querySelector('div#app-mount')
function getCommand(e, fType) {
// This is pretty ugly but...
return `wget --output-document "${e.alt.slice(1, e.alt.length - 1)}.${fType}" "${e.src.replace('size=96&', '').replace('size=40&', '').replace('size=44&', '').replace('size=20&', '').replace('size=32&', '')}"`
}
function outputGets(emotes) {
let container = document.createElement('div')
let fType, node, text
for (let e of emotes) {
if (e.src.includes('gif')) fType = 'gif'
else if (e.src.includes('webp')) fType = 'webp'
node = document.createElement('p')
text = document.createTextNode(getCommand(e, fType))
node.appendChild(text)
container.appendChild(node)
}
document.querySelector('html').remove()
document.appendChild(container)
}
function removeDuplicates (arr) {
const firstPass = [...new Map(arr.map(v => [v.src, v])).values()]
return [...new Map(firstPass.map(v => [v.alt, v])).values()]
}
let emotes = []
const observer = new MutationObserver((mutationsList, observer) => {
for(const mutation of mutationsList) {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
for (let n of node.getElementsByTagName('img')) {
if (n.dataset.type === 'emoji' && !n.src.includes('svg')) {
emotes.push(n)
console.log("An emote was found.")
}
}
});
}
}
});
observer.observe(chatContent, {
attributes: true,
childList: true,
subtree: true }
)
function finished() {
outputGets(removeDuplicates(emotes))
}
// When you are finished gathering emotes, type: finished()
// This will unmount the app from the browser and replace it with a list of wget commands. Save it, copy them into sh file, run it.
// This POC is provided as-is without warranty.
// finished()
To be honest, I don't really recommend using this code, not because it doesn't work (at the time of writing this anyway), but because... there isn't much value in downloading every emote that you come across on Discord. You're going to end up with a lot of emotes you don't care about and occasionally some that are offensive. The only way to clear them out is to do it by hand, so... it might just be better to start by hand selecting them to start with.
There are other neat things you can do with the MutationObserver in Discord though... For example this code will remove the placeholders for any messages that come from blocked users, making it as if blocked users were not present at all.
const chatContent = document.querySelector('div#app-mount')
for (let div of document.querySelectorAll('div[role=article]')) {
for (let d of div.getElementsByTagName('div')) {
for (let cls of d.classList) {
if (cls.includes('blocked')) {
div.style.display = 'none'
}
}
}
}
const observer = new MutationObserver((mutationsList, observer) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
for (let n of node.getElementsByTagName('div')) {
for (let cls of d.classList) {
if (cls.includes('blocked')) {
div.style.display = 'none'
}
}
}
});
}
}
});
observer.observe(chatContent, {
attributes: true,
childList: true,
subtree: true }
)