Last active
September 18, 2020 12:31
-
-
Save pedropedruzzi/365fd278393b651a9e6780e7866c469d to your computer and use it in GitHub Desktop.
Greasemonkey script that replaces links on image galleries with direct (faster) image links on MiBACT Antenati website. Instructions: 1. Install Greasemonkey (Firefox) or Tampermonkey (Chrome/Firefox). 2. Click https://gist.github.com/pedrox/365fd278393b651a9e6780e7866c469d/raw/MiBACT-Antenati-direct-image-links.user.js
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 MiBACT Antenati direct image links on galleries | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Replaces links on image galleries with direct (faster) image links | |
// @author Pedro Pedruzzi | |
// @match http://dl.antenati.san.beniculturali.it/v/* | |
// @grant none | |
// @downloadURL https://gist.github.com/pedrox/365fd278393b651a9e6780e7866c469d/raw/MiBACT-Antenati-direct-image-links.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
document.querySelectorAll("img.giThumbnail").forEach(img => { | |
let thumbItemId = img.src.match(/g2_itemId=([0-9]+)/)[1]; | |
let fullImageitemId = (parseInt(thumbItemId, 10) - 1).toString(); | |
let fullImageUrl = img.src.replace(thumbItemId, fullImageitemId); | |
let oldLinkUrl = img.closest("a").href; | |
img.closest("tr").querySelectorAll("a").forEach(link => { | |
if (link.href == oldLinkUrl) { | |
link.href = fullImageUrl; | |
} | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment