From de075b321d3f731c5f0aef6ce66b6b33b8aeb4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 12 Apr 2022 17:06:27 +0300 Subject: [PATCH] Add guardian.com image gallery fixer --- guardian.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 guardian.js diff --git a/guardian.js b/guardian.js new file mode 100644 index 0000000..900d44e --- /dev/null +++ b/guardian.js @@ -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();