Greasy Fork is available in English.

setMutationHandler

MutationObserver wrapper to wait for the specified CSS selector

2016-07-20 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/12228/137072/setMutationHandler.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

/* EXAMPLE:
	
	setMutationHandler(document, '.container p.some-child', function(nodes) {
		// single node:
		nodes[0].remove();
		
		// or multiple nodes:
		nodes.forEach(function(node) {
			node.style.display = 'none';
		});

		//this.disconnect(); // disconnect the observer, this is useful for one-time jobs
		return true; // continue enumerating current batch of mutations
	});
*/

// ==UserScript==
// @name          setMutationHandler
// @description   MutationObserver wrapper to wait for the specified CSS selector
// @namespace     wOxxOm.scripts
// @author        wOxxOm
// @grant         none
// @version       2.0.6
// ==/UserScript==

function setMutationHandler(baseNode, selector, cb, options) {
	var queue = [];
	var ob = new MutationObserver(function handler(mutations) {
		if (mutations && mutations.length > 100) {
			if (!queue.length)
				setTimeout(handler, 0);
			queue.push(mutations);
			return;
		}
		do {
			if (!mutations) {
				mutations = queue.shift();
				if (!mutations)
					return;
			}

			for (var i=0, ml=mutations.length, m; (i<ml) && (m=mutations[i]); i++) {
				switch (m.type) {
					case 'childList':
						if (m.addedNodes[0] && m.addedNodes[0].nodeType == 3) { // TEXT_NODE
							if (m.target.matches(selector) && !cb.call(ob, [m.target], m))
								return;
							continue;
						}
						for (var j=0, nodes=m.addedNodes, nl=nodes.length, n; (j<nl) && (n=nodes[j]); j++)
							if (n.nodeType == 1) { // ELEMENT_NODE
								if (n.matches(selector))
									n = [n];
								else if (n.querySelector(selector))
									n = Array.prototype.slice.call(n.querySelectorAll(selector));
								else
									continue;
								if (!cb.call(ob, n, m))
									return;
							}
						break;
					case 'attributes':
						if (m.target.matches(selector) && !cb.call(ob, [m.target], m))
							return;
						break;
					case 'characterData':
						if (m.target.parentNode && m.target.parentNode.matches(selector) && !cb.call(ob, [m.target.parentNode], m))
							return;
						break;
				}
			}
			mutations = null;
		} while (queue.length);
	});
	ob.observe(baseNode, options || {subtree:true, childList:true});
	return ob;
}