Created
September 5, 2018 01:36
-
-
Save Necroforger/daf4c02d8551cd7f210e8972afee8e17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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