Greasy Fork is available in English.
MutationObserver wrapper to wait for the specified CSS selector
As of
ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greasyfork.org/scripts/12228/135916/setMutationHandler.js.
/* 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.5
// ==/UserScript==
function setMutationHandler(baseNode, selector, cb, options) {
var ob = new MutationObserver(function handler(mutations, fromTimer) {
if (mutations.length > 100 && !fromTimer)
return setTimeout(function() { handler(mutations, true) }, 0);
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
n = n.matches(selector) ? [n] : Array.prototype.slice.call(n.querySelectorAll(selector));
if (n.length && !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;
}
});
ob.observe(baseNode, options || {subtree:true, childList:true});
return ob;
}