feat(content): create content script

This commit is contained in:
wanhose 2020-04-19 15:02:48 +02:00 committed by wanhose
parent cc28cfa703
commit 07903e4c16

38
js/content.js Normal file
View File

@ -0,0 +1,38 @@
if (typeof chrome.app.isInstalled !== 'undefined') {
// Observer
const observer = new MutationObserver((mutations, observer) => {
for (let mutation of mutations) {
if (mutation.type === 'childList') {
observer.disconnect();
doMagic();
observe();
}
}
});
// Inject buttons
const doMagic = () => {
const notRemovableElements = Array.from(document.getElementsByClassName("qc-cmp-ui-showing"));
notRemovableElements.forEach(element => {
element.classList.remove("qc-cmp-ui-showing");
});
const removableElements = Array.from(document.getElementsByClassName("qc-cmp-ui-container"));
removableElements.forEach(element => {
element.remove();
});
};
// Observer starts observe when call this function
const observe = () => {
observer.observe(document.body, {
childList: true,
subtree: true,
//...
});
};
// Then...
doMagic();
observe();
}