Fix dynamic img and form

This commit is contained in:
Adrian Vollmer 2022-09-26 17:42:25 +02:00
parent c6c2ffb4a8
commit 6c82664001

View File

@ -89,18 +89,22 @@ var fix_link = function(a) {
} }
}; };
var fix_forms = function() { var fix_form = function(form) {
Array.from(document.querySelectorAll("form")).forEach( form => {
var href = form.getAttribute('action'); var href = form.getAttribute('action');
if (is_virtual(href) && form.getAttribute('method').toLowerCase() == 'get') { if (is_virtual(href) && form.getAttribute('method').toLowerCase() == 'get') {
form.addEventListener('submit', virtual_click); form.addEventListener('submit', virtual_click);
} }
};
var fix_forms = function() {
Array.from(document.querySelectorAll("form")).forEach( form => {
fix_form(form);
}); });
}; };
var embed_img = function() { var embed_img = function(img) {
Array.from(document.querySelectorAll("img")).forEach( img => {
if (img.hasAttribute('src')) { if (img.hasAttribute('src')) {
const src = img.getAttribute('src'); const src = img.getAttribute('src');
if (is_virtual(src)) { if (is_virtual(src)) {
@ -114,6 +118,11 @@ var embed_img = function() {
} }
}; };
}; };
};
var embed_imgs = function() {
Array.from(document.querySelectorAll("img")).forEach( img => {
embed_img(img);
}); });
}; };
@ -166,7 +175,7 @@ var normalize_path = function(path) {
var fix_document = function() { var fix_document = function() {
embed_js(); // This might change the DOM, so do this first embed_js(); // This might change the DOM, so do this first
embed_css(); embed_css();
embed_img(); embed_imgs();
fix_links(); fix_links();
fix_forms(); fix_forms();
}; };
@ -205,7 +214,10 @@ const observer = new MutationObserver((mutationList) => {
fix_link(a); fix_link(a);
}); });
Array.from(mutation.target.querySelectorAll("img")).forEach( img => { Array.from(mutation.target.querySelectorAll("img")).forEach( img => {
// embed_img TODO embed_img(img);
});
Array.from(mutation.target.querySelectorAll("form")).forEach( form => {
fix_form(form);
}); });
} }
}); });