Skip to content

Instantly share code, notes, and snippets.

@hadongsoo
Created March 6, 2020 13:16
Show Gist options
  • Save hadongsoo/a9f86acc73eee7aa429e1c69eecdbfeb to your computer and use it in GitHub Desktop.
Save hadongsoo/a9f86acc73eee7aa429e1c69eecdbfeb to your computer and use it in GitHub Desktop.
allset for violentmonkey
// ==UserScript==
// @name allset
// @namespace Violentmonkey Scripts
// @exclude *://*/*
// @grant none
// @version 1.0
// @author dongsoo
// @grant GM_addStyle
// @grant GM_info
// @grant GM_setValue
// @grant GM_getValue
GM_addStyle(`
.style {
width:30px;
height:30px;
}
`);
// start * seconds later
const TIMEOUT = 2;
setTimeout(() => {
}, TIMEOUT * 1000);
const asyncQuerySelector = async (node, query) => {
try {
return await (query ? node.querySelector(query) : node);
} catch (error) {
console.error(`Cannot find ${query ? `${query} in`: ''} ${node}.`, error);
return null;
}
};
// asyncQuerySelector(document, '#sections ytd-guide-section-renderer #items').then('load it, ',console.log);
const waitForElement = (selector) => {
return new Promise((resolve, reject) => {
let element = document.querySelector(selector);
if(element) {
resolve(element);
return;
}
let observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
let nodes = Array.from(mutation.addedNodes);
for(let node of nodes) {
if(node.matches && node.matches(selector)) {
observer.disconnect();
resolve(node);
return;
}
};
});
});
observer.observe(document.documentElement, { childList: true, subtree: true });
});
}
// waitForElement('ul li a')
// .then(el => console.log('load : ', el))
// .then(()=>{
// //working
// })
// .catch(()=>{console.log('fail')})
// https://gist.github.com/PaulKinlan/2d7cd4e78a63a97387137a0a9fb7ee6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment