mirror of
https://github.com/ergosteur/misc-userscripts.git
synced 2026-04-19 04:59:34 -04:00
37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
// ==UserScript==
|
|
// @name Apollo Cafe Image Upgrader
|
|
// @namespace https://github.com/ergosteur/misc-userscripts
|
|
// @author ergosteur
|
|
// @version 1.0.1
|
|
// @description Replace all imagedelivery.net URLs ending in /2x with /4x on apollo.cafe
|
|
// @match https://apollo.cafe/*
|
|
// @match http://apollo.cafe/*
|
|
// @icon https://apollo.cafe/favicon.ico
|
|
// @grant none
|
|
// @downloadURL https://github.com/ergosteur/misc-userscripts/raw/refs/heads/main/apollocafe-image-upgrader.user.js
|
|
// @updateURL https://github.com/ergosteur/misc-userscripts/raw/refs/heads/main/apollocafe-image-upgrader.user.js
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
// Function to replace /2x -> /4x in all <img> tags
|
|
function upgradeImages() {
|
|
document.querySelectorAll('img[src*="imagedelivery.net"]').forEach(img => {
|
|
img.src = img.src.replace(/\/2x$/, '/4x');
|
|
});
|
|
|
|
// Also replace inline HTML / CSS background URLs if needed
|
|
document.querySelectorAll('[style*="imagedelivery.net"]').forEach(el => {
|
|
el.style.backgroundImage = el.style.backgroundImage.replace(/\/2x(['"]?\)?$)/, '/4x$1');
|
|
});
|
|
}
|
|
|
|
// Run once at page load
|
|
upgradeImages();
|
|
|
|
// Run again whenever DOM changes (for infinite scroll, SPA, etc.)
|
|
const observer = new MutationObserver(() => upgradeImages());
|
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
})();
|