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();