Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace Wikipedia SVG renders with SVG files
// ==UserScript==
// @name Replace Wikipedia SVG renders with SVG files
// @namespace https://kddlb.com/
// @version 0.1
// @description Replace Wikipedia SVG renders with SVG files.
// @author kevin López Brante
// @match https://*.wikipedia.org/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var images = document.querySelectorAll('[src*="svg"]');
var regex = /(https?)?\/\/upload.wikimedia.org\/(.*)\/(.*)\/thumb\/([0-9a-z]\/[0-9a-z]{2})\/(.*)\/(.*)/gm;
images.forEach(function (element, index) {
element.removeAttribute("srcset");
const str = element.getAttribute("src");
const subst = `https://upload.wikimedia.org/$2/$3/$4/$5`;
const result = str.replace(regex, subst);
element.setAttribute("src", result);
});
console.log(images);
})();
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.