Last active
April 19, 2022 23:20
-
-
Save brunos3d/5d95a771cc5229c4c75cd5bcdebced81 to your computer and use it in GitHub Desktop.
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 JPG Store Optimizer | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1 | |
| // @description try to take over the world! | |
| // @author You | |
| // @match https://www.jpg.store/collection/unwantedones* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=jpg.store | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| function freeze_gif(i) { | |
| if (!i.src || !i.className.includes("NFTMarketplaceCard")) return; | |
| if (i.className.includes("NFTMarketplaceCard_nftMarketplaceCardPriceIcon")) return; | |
| const nftId = i.src.replace("https://images.jpgstoreapis.com/ipfs/", "") | |
| i.src = `https://cloudflare-ipfs.com/ipfs/${nftId}`; | |
| i.addEventListener('load', (event) => { | |
| var c = document.createElement('canvas'); | |
| var w = c.width = i.width; | |
| var h = c.height = i.height; | |
| c.getContext('2d').drawImage(i, 0, 0, w, h); | |
| try { | |
| i.src = c.toDataURL("image/gif"); // if possible, retain all css aspects | |
| } catch (e) { // cross-domain -- mimic original with all its tag attributes | |
| for (var j = 0, a; a = i.attributes[j]; j++) { | |
| c.setAttribute(a.name, a.value); | |
| } | |
| i.parentNode.replaceChild(c, i); | |
| } | |
| console.log("Optimized", i); | |
| }); | |
| } | |
| var observer = new MutationObserver(function (mutations) { | |
| mutations.forEach(function (mutation) { | |
| mutation.addedNodes.forEach(function (addedNode) { | |
| if (Array.isArray(addedNode)) { | |
| addedNode.map(node => { | |
| freeze_gif(node); | |
| }) | |
| } | |
| else { | |
| freeze_gif(addedNode); | |
| } | |
| }); | |
| }); | |
| }); | |
| observer.observe(document.body, { childList: true, subtree: true }); | |
| [].slice.apply(document.images).map((img) => setTimeout(() => { freeze_gif(img); }, 2000)); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment