Skip to content

Instantly share code, notes, and snippets.

@NSExceptional
Last active December 21, 2020 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NSExceptional/2f95a63decc175315eaaf3454396458c to your computer and use it in GitHub Desktop.
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
// ==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