AniwatchPlus/enhancements/animeRequests.js

68 lines
1.9 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-07-29 11:39:09 +02:00
removeUnknownUsers(node);
2020-07-29 10:35:57 +02:00
}
});
2020-04-25 23:23:13 +02:00
2020-07-29 10:35:57 +02:00
function changeFollowedStarColor(node) {
2020-07-29 11:35:51 +02:00
const starIcon = 'star';
2020-07-29 11:14:38 +02:00
// find stars
2020-07-29 11:35:51 +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 11:35:51 +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-07-29 11:35:51 +02:00
let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])');
2020-04-25 22:43:36 +02:00
if (profileLink.length > 0) {
item.style.borderColor = aniBlue
}
2020-07-29 10:44:03 +02:00
}
// are we target tag?
2020-07-29 11:39:09 +02:00
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);
});
}
}
function removeUnknownUsers(node) {
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case
let updateFunc = item => {
let upperDiv = node.querySelector('[layout-align="start center"][flex]')
let lowerDiv = upperDiv.parentElement.nextElementSibling;
let anime = lowerDiv.innerText;
upperDiv.innerHTML = `<b>${anime}</b>`;
lowerDiv.innerHTML = '&nbsp;';
}
2020-07-29 10:44:03 +02:00
if (node.tagName === targetTagName) {
updateFunc(node);
} else {
// find items -> all
2020-07-29 11:35:51 +02:00
let requestItems = node.querySelectorAll('md-list-item');
2020-07-29 10:44:03 +02:00
2020-07-29 11:35:51 +02:00
// change border color if profile link is not 'false'
2020-07-29 10:44:03 +02:00
requestItems.forEach(item => {
updateFunc(item);
});
}
}