Add guardian.com image gallery fixer
This commit is contained in:
parent
02d7b17d44
commit
de075b321d
|
@ -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();
|
Loading…
Reference in New Issue