AniwatchPlus/enhancements/animeRequests.js

88 lines
2.5 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);
2020-07-29 11:55:02 +02:00
changeBorderColor(node);
2020-07-29 11:39:09 +02:00
removeUnknownUsers(node);
2020-07-29 10:35:57 +02:00
}
2020-07-29 12:14:25 +02:00
}, "/requests");
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 11:55:02 +02:00
function changeBorderColor(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
2020-07-29 11:55:02 +02:00
// highlight left border for own request
2020-04-25 22:43:36 +02:00
if (profileLink.length > 0) {
item.style.borderColor = aniBlue
}
2020-07-29 11:55:02 +02:00
// add border as horizontal seperator
item.style.borderBottom = "1px solid rgba(155,155,155, 0.2)";
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');
2020-07-29 11:55:02 +02:00
// update borders
2020-07-29 11:39:09 +02:00
requestItems.forEach(item => {
updateFunc(item);
});
}
}
function removeUnknownUsers(node) {
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case
let updateFunc = item => {
2020-07-29 11:42:11 +02:00
// find user profile link -> own request
let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])');
// find divs
2020-07-29 11:39:09 +02:00
let upperDiv = node.querySelector('[layout-align="start center"][flex]')
let lowerDiv = upperDiv.parentElement.nextElementSibling;
2020-07-29 11:42:11 +02:00
// remember Data
2020-07-29 11:39:09 +02:00
let anime = lowerDiv.innerText;
2020-07-29 11:42:11 +02:00
let profileData = upperDiv.innerHTML;
// exchange data
2020-07-29 11:39:09 +02:00
upperDiv.innerHTML = `<b>${anime}</b>`;
2020-07-29 11:42:11 +02:00
// add user note if own request
if (profileLink.length > 0) {
lowerDiv.innerHTML = profileData;
}
// remove if foreign request.
else {
lowerDiv.innerHTML = '&nbsp;';
}
2020-07-29 11:39:09 +02:00
}
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);
});
}
}