Skip to content

Instantly share code, notes, and snippets.

What would you like to do? - prodScreenshot.user.js
// ==UserScript==
// @name prodScreenshot
// @description Add the corresponding thumbnail inside each link to a prod.
// @include*
// @exclude
// @exclude*
// @include*
// @exclude
// @exclude*
// ==/UserScript==
* 2012.08.24 Tigrou^ind ( ). Original idea and implementation
* 2012.08.24 Mathieu 'p01' Henri ( ). Rewrite working on ALL pages excluding the index which would get too busy.
!(function ()
{ var ext = ['jpg','png','gif'];
var prev = {href:'/* oO */'};
// grab all the links to a prod
var links = document.querySelectorAll('a[href*="prod.php?which="]');
for( var i=0, link=null; link=links[i++]; prev=link)
// look for the prod_id and make sure it's different than the previous link
var id = link.href!=prev.href && (link.href.match(/prod.php\?which=(\d+)/)||['']).pop();
// create a span with multiple background images, thus trying to load the screenshot in the most common image formats.
// NB: uses ETAGs. The servers should not blink despite this rather brutal approach.
var s = document.createElement('span');'display:block;width:100px;height:75px;margin:4px 4px 0 0;'+
'background:no-repeat center center;background-size:contain;background-image:'+{ return 'url("/screenshots/'+id+'.'+v+'")'})+';';

This comment has been minimized.

Copy link

commented Nov 21, 2018

what is this script useful for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.