MCPcopy Create free account
hub / github.com/Tampermonkey/tampermonkey / onSubtree

Function onSubtree

src/content.js:767–803  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

765 };
766
767 var onSubtree = function(e) {
768 // console.log(eDOMATTRMODIFIED + " onSubtree: ");
769 // console.log(e.target);
770 // console.log(that);
771
772 // was the event send for the element we're watching?
773 if (e.target == that) {
774 // create <div class="foo" /> from outerHTML
775 var n = e.target.outerHTML.split('>')[0] + ' />';
776 // cmp strings
777 if (old != n) {
778 // console.log(eDOMATTRMODIFIED + " changes!!!!");
779
780 // create real HTMLElements
781 var od = document.createElement('div');
782 od.innerHTML = old;
783 var oe = od.childNodes[0];
784 var nd = document.createElement('div');
785 nd.innerHTML = n;
786 var ne = nd.childNodes[0];
787
788 // determine all attributes from outerHTML
789 var a = getAttrsFromString(old, getAttrsFromString(n));
790
791 for (var k in a) {
792 if (!a.hasOwnProperty(k)) continue;
793 var ov = oe.getAttribute(k);
794 var nv = ne.getAttribute(k);
795 // send event in case some attributes differ
796 if (ov != nv) sendEvent(that, k, ov, nv);
797 }
798
799 // store new outerHTML
800 old = n;
801 }
802 }
803 };
804
805 useObserver = false;
806 if (!logged) console.log('content: WARN unable to use MutationObserver -> fallback to DOMSubtreeModified event');

Callers

nothing calls this directly

Calls 2

getAttrsFromStringFunction · 0.85
sendEventFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…