Develop #14

Closed
Serraniel wants to merge 19 commits from develop into master
6 changed files with 153 additions and 28 deletions

View file

@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}

View 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 = '&nbsp;';
}
}
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);
});
}
}

View file

@ -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"
}
]
} }

View file

@ -1,10 +1,27 @@
function executeAfterPreload(func){ let __scripts = [];
let preLoader = document.getElementById('preloader');
let loop = setInterval(() => { function registerScript(func, pattern = '.*') {
if(preLoader.style.display==="none"){ __scripts.push({ "function": func, "pattern": pattern });
clearInterval(loop);
func();
}
}, 100);
} }
function runScripts(node) {
__scripts.forEach(script => {
if (window.location.pathname.match(script.pattern)) {
script.function(node);
}
});
}
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
});

View file

@ -1 +1 @@
const aniBlue = "#348fff"; const aniBlue = '#348fff';

3
utils/helpers.js Normal file
View file

@ -0,0 +1,3 @@
function isHtmlElement(object) {
return object instanceof HTMLElement;
}