Created
December 16, 2018 04:52
-
-
Save kddlb/8faa721eefa6bf930e5b44800f7129b4 to your computer and use it in GitHub Desktop.
Replace Wikipedia SVG renders with SVG files
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 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