Skip to content

Commit

Permalink
I swear it almost works
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazza-231 committed Oct 24, 2023
1 parent 8c34be3 commit ef0e7f8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions addons/math-in-inputs/userscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default async function ({ addon }) {
return true;
} else if (el.matches("[class*=sa-onion-settings]" + type)) {
// All inputs in the onion-skinning settings
return true;
}
return false;
};
Expand Down Expand Up @@ -117,7 +118,6 @@ export default async function ({ addon }) {
if (!e.target.value) return;
const newValue = parseMath(e.target.value);
Object.getOwnPropertyDescriptor(e.target.constructor.prototype, "value").set.call(e.target, newValue.toString());
console.log(loseFocus);
if (loseFocus) e.target.blur();
}
document.addEventListener(
Expand Down Expand Up @@ -155,15 +155,26 @@ export default async function ({ addon }) {
}
}

function traverseAndHandleElements(node) {
if (isSupportedElement(node, true)) {
handleInputTypeChanges(node);
}

node.childNodes.forEach((child) => {
traverseAndHandleElements(child);
});
}

var observer = new MutationObserver(function (mutationsList) {
mutationsList.forEach(function (mutation) {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function (el) {
if (isSupportedElement(el, true)) handleInputTypeChanges(el); // Elements that need to have their type set to "text"
// Start the recursive traversal from the newly added element
traverseAndHandleElements(el);
});
}
});
});
}, true);

const observerConfig = { childList: true, subtree: true };
observer.observe(document.body, observerConfig);
Expand Down

0 comments on commit ef0e7f8

Please sign in to comment.