Last active
December 21, 2020 22:02
-
-
Save NSExceptional/2f95a63decc175315eaaf3454396458c to your computer and use it in GitHub Desktop.
A user script to make product images on BrickLink use a larger image file
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
// ==UserScript== | |
// @name BrickLink high res images | |
// @version 0.1 | |
// @description Make product images on BrickLink use a larger image file | |
// @author Tanner Bennett / @NSExceptional / u/ThePantsThief | |
// @match https://bricklink.com/* | |
// @match https://*.bricklink.com/* | |
// @match https://store.bricklink.com/* | |
// @grant none | |
// ==/UserScript== | |
function observe(selector, imgSelector) { | |
// Call initially just to be safe; | |
// The catalog for example loads instantly | |
resizeProductRows(imgSelector); | |
const observer = new MutationObserver(function(mutationsList, observer) { | |
for(var mutation of mutationsList) { | |
if (mutation.type == 'childList' && mutation.target.lastElementChild.className != 'blLILThumbImageOverlay') { | |
resizeProductRows(imgSelector); | |
break; | |
} | |
} | |
}); | |
const element = $(selector).get(0); | |
if (element) { | |
observer.observe(element, { | |
attributes: false, childList: true, subtree: true | |
}); | |
} | |
} | |
function resizeProductRows(selector) { | |
$(selector).each(function() { | |
const $img = $(this); | |
let orig = $img.attr('src'); | |
let newURL = orig | |
.replace(/\/([A-Z])T\//, '/$1N/') | |
.replace('/Thumb/', '/') | |
.replace(/\.t\d\./, '.'); | |
$img.attr('src', newURL); | |
}); | |
} | |
$(document).ready(function() { | |
observe('.store-content', '.item .image img'); | |
observe('#ItemEditForm table', '.blCatalogImagePopup img'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment