MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / onElement

Function onElement

src/injected/content/util.js:28–41  ·  view source on GitHub ↗
(tag, cb, arg)

Source from the content-addressed store, hash-verified

26 * @returns {Promise<void>}
27 */
28export const onElement = (tag, cb, arg) => new SafePromise(resolve => {
29 if (elemByTag(tag)) {
30 resolve(cb(arg));
31 } else {
32 const observer = new MutationObserver(() => {
33 if (elemByTag(tag)) {
34 observer.disconnect();
35 resolve(cb(arg));
36 }
37 });
38 // documentElement may be replaced so we'll observe the entire document
39 observer.observe(document, { childList: true, subtree: true });
40 }
41});
42
43export const makeElem = (tag, attrs) => {
44 const el = document::createElementNS('http://www.w3.org/1999/xhtml', tag);

Callers 1

injectScriptsFunction · 0.90

Calls 3

elemByTagFunction · 0.85
resolveFunction · 0.85
cbFunction · 0.50

Tested by

no test coverage detected