Skip to content

Instantly share code, notes, and snippets.

@diamondburned
Created May 4, 2024 06:18
Show Gist options
  • Save diamondburned/3fd716c82cba68a476f47d723e2a0c4e to your computer and use it in GitHub Desktop.
Save diamondburned/3fd716c82cba68a476f47d723e2a0c4e to your computer and use it in GitHub Desktop.
Hypnohub Auto-load Bigger Thumbnails
// ==UserScript==
// @name Hypnohub Auto-load Bigger Thumbnails
// @version 1
// @grant none
// @match *://hypnohub.net/*
// @run-at document-end
// @noframes
// ==/UserScript==
async function urlExists(url) {
const ok = await fetch(url, {method: "GET"}).then(r => r.ok).catch(() => false)
await sleep(50)
return ok
}
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
(async function() {
const imgs = [...document.querySelectorAll(`img.preview:not([alt*="video"])`)]
for (const img of imgs) {
await (async () => {
const attempts = [
(url) => url.replaceAll("thumbnail", "sample"),
(url) => url
.replaceAll("thumbnails", "images")
.replaceAll("thumbnail_", "")
.replace(".jpg", ".jpeg"),
(url) => url
.replaceAll("thumbnails", "images")
.replaceAll("thumbnail_", "")
.replace(".jpg", ".png"),
]
for (const replace of attempts) {
const url = replace(img.src)
if (await urlExists(url)) {
img.src = url
return
}
}
})()
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment