Skip to content

Instantly share code, notes, and snippets.

@autoxbc autoxbc/match.js
Created Sep 15, 2019

Embed
What would you like to do?
// ==UserScript==
// @name test code
// @version 1.0
// @match *://*/*
// @run-at document-start
// ==/UserScript==
const selector = '*';
function yourFunction(target)
{
// your code here
console.log(target.tagName);
}
function match(target)
{
if( target.matches && target.matches(selector) )
yourFunction(target);
if(target.querySelectorAll)
[...target.querySelectorAll(selector)].forEach( target => yourFunction(target) );
}
addEventListener('DOMContentLoaded', ({ target }) => {
const callback = mttns => mttns.forEach( ({ addedNodes }) => [...addedNodes].forEach( target => match(target) ) );
new MutationObserver(callback).observe( document , { childList: true , subtree: true } );
match(target);
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.