forked from Qortal/qortal
Switched to document.querySelectorAll() as otherwise we were only intercepting the first image on the page.
This commit is contained in:
parent
566c6a3f4b
commit
8beffd4dae
@ -318,29 +318,34 @@ else if (document.attachEvent) {
|
||||
* Intercept image loads from the DOM
|
||||
*/
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
let url = document.querySelector('img').src;
|
||||
const newUrl = convertToResourceUrl(url);
|
||||
if (newUrl != null) {
|
||||
document.querySelector('img').src = newUrl;
|
||||
}
|
||||
const imgElements = document.querySelectorAll('img');
|
||||
imgElements.forEach((img) => {
|
||||
let url = img.src;
|
||||
const newUrl = convertToResourceUrl(url);
|
||||
if (newUrl != null) {
|
||||
document.querySelector('img').src = newUrl;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Intercept img src updates
|
||||
*/
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
let img = document.querySelector('img');
|
||||
let observer = new MutationObserver((changes) => {
|
||||
changes.forEach(change => {
|
||||
if (change.attributeName.includes('src')) {
|
||||
const newUrl = convertToResourceUrl(img.src);
|
||||
if (newUrl != null) {
|
||||
document.querySelector('img').src = newUrl;
|
||||
const imgElements = document.querySelectorAll('img');
|
||||
imgElements.forEach((img) => {
|
||||
let observer = new MutationObserver((changes) => {
|
||||
changes.forEach(change => {
|
||||
if (change.attributeName.includes('src')) {
|
||||
const newUrl = convertToResourceUrl(img.src);
|
||||
if (newUrl != null) {
|
||||
document.querySelector('img').src = newUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe(img, {attributes: true});
|
||||
});
|
||||
observer.observe(img, {attributes: true});
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user