Created
May 4, 2024 06:18
-
-
Save diamondburned/3fd716c82cba68a476f47d723e2a0c4e to your computer and use it in GitHub Desktop.
Hypnohub Auto-load Bigger Thumbnails
This file contains hidden or 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
// ==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