AniwatchPlus/enhancements/animeRequests.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-07-29 10:35:57 +02:00
registerScript(node => {
2020-04-25 23:23:13 +02:00
// run the scripts
2020-07-29 10:35:57 +02:00
if (isHtmlElement(node)) {
changeFollowedStarColor(node);
changeOwnBorderColor(node);
}
});
2020-04-25 23:23:13 +02:00
2020-07-29 10:35:57 +02:00
function changeFollowedStarColor(node) {
2020-07-29 11:14:38 +02:00
const starIcon = "star";
// find stars
2020-07-29 11:14:38 +02:00
let followedItems = Array.from(node.querySelectorAll("i")).filter(i => i.innerText.trim() === starIcon);
// change color
followedItems.forEach(item => item.style.color = aniBlue);
2020-04-25 22:43:36 +02:00
}
2020-07-29 10:35:57 +02:00
function changeOwnBorderColor(node) {
2020-07-29 10:44:03 +02:00
const targetTagName = "MD-LIST-ITEM"; // tagName is upper case
2020-04-25 22:43:36 +02:00
2020-07-29 10:44:03 +02:00
let updateFunc = item => {
2020-04-25 22:43:36 +02:00
let profileLink = item.querySelectorAll("a[href*='/profile/']:not([href='/profile/false'])");
if (profileLink.length > 0) {
item.style.borderColor = aniBlue
}
2020-07-29 10:44:03 +02:00
}
// are we target tag?
if (node.tagName === targetTagName) {
updateFunc(node);
} else {
// find items -> all
let requestItems = node.querySelectorAll("md-list-item");
// change border color if profile link is not "false"
requestItems.forEach(item => {
updateFunc(item);
});
}
}