Skip to content

Instantly share code, notes, and snippets.

@Necroforger
Created September 5, 2018 01:36
Show Gist options
  • Save Necroforger/daf4c02d8551cd7f210e8972afee8e17 to your computer and use it in GitHub Desktop.
Save Necroforger/daf4c02d8551cd7f210e8972afee8e17 to your computer and use it in GitHub Desktop.
(function () {
// Number of pages to attempt to scroll
const pages = 1;
// sleep duration between scrolls in milliseconds.
// adjust to compensate for network speed.
const sleepDuration = 500;
/**
* Sleep for duration milliseconds
* @param {number} duration
* @returns {Promise<void>}
*/
function sleep(duration) {
return new Promise((resolve) => {
setTimeout(resolve, duration);
})
}
/**
* copies a string to the clipboard
* @param {string} value
* @returns {string}
*/
function copyToClipboard(value) {
let inp = document.createElement("input");
document.body.appendChild(inp);
inp.value = JSON.stringify(urls);
inp.focus();
inp.select();
try {
document.execCommand("copy");
} catch (e) {
console.log(e);
}
document.body.removeChild(inp);
}
let urls = [];
// Obtain the channel messages pane
(async () => {
let msgs = document.querySelector("div[class*='messages'][class*='scroller']");
if (!msgs) {
console.log("could not find message pane");
return;
}
function findImages() {
msgs.querySelectorAll("img").forEach(x => {
if (!urls.includes(x.src)) {
urls.push(x.src);
}
});
}
if (pages == 1) {
findImages();
} else {
for (let i = 0; i < pages; i++) {
findImages();
msgs.scrollTop = 0;
await sleep(sleepDuration);
}
}
copyToClipboard(JSON.stringify(urls));
})();
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment