imgfixer/guardian.js

29 lines
665 B
JavaScript

// ==UserScript==
// @name The Guardian gallery fixer
// @version 1
// @grant none
// @match https://www.theguardian.com/*
// ==/UserScript==
function fixGalleries() {
for (let figure of document.getElementsByTagName('figure')) {
const parent = figure.parentElement;
if (parent.nodeName !== 'GU-ISLAND' || !parent.hasAttribute('props')) {
continue;
}
const props = JSON.parse(figure.parentElement.getAttribute('props'));
if (!props['url']) {
continue;
}
let a = document.createElement('a');
a.href = props['url'];
a.innerText = '[gallery]';
parent.replaceChild(a, figure);
}
}
fixGalleries();