Feature/#7 core logic detect page change and refresh #8

Merged
Serraniel merged 4 commits from feature/#7-core-logic-detect-page-change-and-refresh into develop 2020-07-29 11:16:39 +02:00
2 changed files with 10 additions and 5 deletions
Showing only changes of commit 3d309ae88a - Show all commits

View file

@ -1,5 +1,3 @@
const starIcon = "star";
registerScript(node => {
// run the scripts
if (isHtmlElement(node)) {
@ -9,8 +7,10 @@ registerScript(node => {
});
function changeFollowedStarColor(node) {
const starIcon = "star";
// find stars
let followedItems = Array.from(node.querySelectorAll("i")).filter(i => i.innerText == starIcon);
let followedItems = Array.from(node.querySelectorAll("i")).filter(i => i.innerText.trim() === starIcon);
// change color
followedItems.forEach(item => item.style.color = aniBlue);

View file

@ -4,15 +4,20 @@ function registerScript(func) {
__scripts.push(func);
}
function runScripts(node) {
__scripts.forEach(script => script(node));
}
let observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
for (let i = 0; i < mutation.addedNodes.length; i++) {
__scripts.forEach(script => script(mutation.addedNodes[i]));
runScripts(mutation.addedNodes[i]);
}
});
});
observer.observe(document.documentElement || document.body, {
childList: true,
subtree: true
subtree: true,
attributes: true
});