Add guardian.com image gallery fixer

This commit is contained in:
Juhani Krekelä 2022-04-12 17:06:27 +03:00
parent 02d7b17d44
commit de075b321d
1 changed files with 28 additions and 0 deletions

28
guardian.js Normal file
View File

@ -0,0 +1,28 @@
// ==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();