Add LA Times and rework data_srcset.js to use srcset attribute

This commit is contained in:
Juhani Krekelä 2022-03-08 15:31:42 +02:00
parent e4dfd0f6c0
commit 52202fb45c
1 changed files with 13 additions and 5 deletions

View File

@ -4,15 +4,23 @@
// @grant none // @grant none
// @match https://kotaku.com/* // @match https://kotaku.com/*
// @match https://*.gizmodo.com/* // @match https://*.gizmodo.com/*
// @match https://www.latimes.com/*
// ==/UserScript== // ==/UserScript==
function fixSrcset(element) {
let srcSet = element.getAttribute('data-srcset');
console.log(srcSet);
if (srcSet) {
element.setAttribute('srcset', srcSet);
}
}
function fixImages() { function fixImages() {
for (let img of document.getElementsByTagName('img')) { for (let img of document.getElementsByTagName('img')) {
let srcSet = img.getAttribute('data-srcset'); fixSrcset(img);
if (srcSet) { }
let imgUrl = srcSet.split(', ').slice(-1)[0].split(' ')[0]; for (let img of document.getElementsByTagName('source')) {
img.setAttribute('src', imgUrl); fixSrcset(img);
}
} }
} }