Develop #14
6 changed files with 153 additions and 28 deletions
8
enhanced-aniwatch.code-workspace
Normal file
8
enhanced-aniwatch.code-workspace
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
88
enhancements/animeRequests.js
Normal file
88
enhancements/animeRequests.js
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
registerScript(node => {
|
||||||
|
// run the scripts
|
||||||
|
if (isHtmlElement(node)) {
|
||||||
|
changeFollowedStarColor(node);
|
||||||
|
changeBorderColor(node);
|
||||||
|
removeUnknownUsers(node);
|
||||||
|
}
|
||||||
|
}, "/requests");
|
||||||
|
|
||||||
|
function changeFollowedStarColor(node) {
|
||||||
|
const starIcon = 'star';
|
||||||
|
|
||||||
|
// find stars
|
||||||
|
let followedItems = Array.from(node.querySelectorAll('i')).filter(i => i.innerText.trim() === starIcon);
|
||||||
|
|
||||||
|
// change color
|
||||||
|
followedItems.forEach(item => item.style.color = aniBlue);
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeBorderColor(node) {
|
||||||
|
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case
|
||||||
|
|
||||||
|
let updateFunc = item => {
|
||||||
|
let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])');
|
||||||
|
|
||||||
|
// highlight left border for own request
|
||||||
|
if (profileLink.length > 0) {
|
||||||
|
item.style.borderColor = aniBlue
|
||||||
|
}
|
||||||
|
|
||||||
|
// add border as horizontal seperator
|
||||||
|
item.style.borderBottom = "1px solid rgba(155,155,155, 0.2)";
|
||||||
|
}
|
||||||
|
|
||||||
|
// are we target tag?
|
||||||
|
if (node.tagName === targetTagName) {
|
||||||
|
updateFunc(node);
|
||||||
|
} else {
|
||||||
|
// find items -> all
|
||||||
|
let requestItems = node.querySelectorAll('md-list-item');
|
||||||
|
|
||||||
|
// update borders
|
||||||
|
requestItems.forEach(item => {
|
||||||
|
updateFunc(item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeUnknownUsers(node) {
|
||||||
|
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case
|
||||||
|
|
||||||
|
let updateFunc = item => {
|
||||||
|
// find user profile link -> own request
|
||||||
|
let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])');
|
||||||
|
|
||||||
|
// find divs
|
||||||
|
let upperDiv = node.querySelector('[layout-align="start center"][flex]')
|
||||||
|
let lowerDiv = upperDiv.parentElement.nextElementSibling;
|
||||||
|
|
||||||
|
// remember Data
|
||||||
|
let anime = lowerDiv.innerText;
|
||||||
|
let profileData = upperDiv.innerHTML;
|
||||||
|
|
||||||
|
// exchange data
|
||||||
|
upperDiv.innerHTML = `<b>${anime}</b>`;
|
||||||
|
|
||||||
|
// add user note if own request
|
||||||
|
if (profileLink.length > 0) {
|
||||||
|
lowerDiv.innerHTML = profileData;
|
||||||
|
}
|
||||||
|
// remove if foreign request.
|
||||||
|
else {
|
||||||
|
lowerDiv.innerHTML = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,29 @@
|
||||||
{
|
{
|
||||||
"name": "Enhanced Aniwatch",
|
"name": "Enhanced Aniwatch",
|
||||||
"version": "0.1.0.0",
|
"version": "0.1.0.0",
|
||||||
"description": "Contains several enhancments for https://aniwatch.me",
|
"description": "Contains several enhancments for https://aniwatch.me",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"author": "Serraniel",
|
"author": "Serraniel",
|
||||||
"homepage_url": "https://github.com/Serraniel/EnhancedAniwatch",
|
"homepage_url": "https://github.com/Serraniel/EnhancedAniwatch",
|
||||||
"content_scripts": [
|
"content_scripts": [{
|
||||||
{
|
"matches": [
|
||||||
"matches": [
|
"*://aniwatch.me/*"
|
||||||
"*://aniwatch.me/*"
|
],
|
||||||
],
|
"js": [
|
||||||
"js": [
|
"utils/colors.js",
|
||||||
"utils/colors.js",
|
"utils/helpers.js",
|
||||||
"utils/aniwatchCore.js"
|
"utils/aniwatchCore.js"
|
||||||
],
|
],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
"matches": [
|
||||||
|
"*://aniwatch.me/*"
|
||||||
|
],
|
||||||
|
"js": [
|
||||||
|
"enhancements/animeRequests.js"
|
||||||
|
],
|
||||||
|
"run_at": "document_end"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -1,10 +1,27 @@
|
||||||
function executeAfterPreload(func){
|
let __scripts = [];
|
||||||
let preLoader = document.getElementById('preloader');
|
|
||||||
|
function registerScript(func, pattern = '.*') {
|
||||||
let loop = setInterval(() => {
|
__scripts.push({ "function": func, "pattern": pattern });
|
||||||
if(preLoader.style.display==="none"){
|
}
|
||||||
clearInterval(loop);
|
|
||||||
func();
|
function runScripts(node) {
|
||||||
|
__scripts.forEach(script => {
|
||||||
|
if (window.location.pathname.match(script.pattern)) {
|
||||||
|
script.function(node);
|
||||||
}
|
}
|
||||||
}, 100);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let observer = new MutationObserver(mutations => {
|
||||||
|
mutations.forEach(mutation => {
|
||||||
|
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
||||||
|
runScripts(mutation.addedNodes[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(document.documentElement || document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
|
attributes: true
|
||||||
|
});
|
|
@ -1 +1 @@
|
||||||
const aniBlue = "#348fff";
|
const aniBlue = '#348fff';
|
3
utils/helpers.js
Normal file
3
utils/helpers.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function isHtmlElement(object) {
|
||||||
|
return object instanceof HTMLElement;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue