diff --git a/enhanced-aniwatch.code-workspace b/enhanced-aniwatch.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/enhanced-aniwatch.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/enhancements/animeRequests.js b/enhancements/animeRequests.js new file mode 100644 index 0000000..f4f6fbd --- /dev/null +++ b/enhancements/animeRequests.js @@ -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 = `${anime}`; + + // 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); + }); + } +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 33f02aa..7a8508d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,20 +1,29 @@ { - "name": "Enhanced Aniwatch", - "version": "0.1.0.0", - "description": "Contains several enhancments for https://aniwatch.me", - "manifest_version": 2, - "author": "Serraniel", - "homepage_url": "https://github.com/Serraniel/EnhancedAniwatch", - "content_scripts": [ - { - "matches": [ - "*://aniwatch.me/*" - ], - "js": [ - "utils/colors.js", - "utils/aniwatchCore.js" - ], - "run_at": "document_start" - } - ] + "name": "Enhanced Aniwatch", + "version": "0.1.0.0", + "description": "Contains several enhancments for https://aniwatch.me", + "manifest_version": 2, + "author": "Serraniel", + "homepage_url": "https://github.com/Serraniel/EnhancedAniwatch", + "content_scripts": [{ + "matches": [ + "*://aniwatch.me/*" + ], + "js": [ + "utils/colors.js", + "utils/helpers.js", + "utils/aniwatchCore.js" + ], + "run_at": "document_start" + }, + { + "matches": [ + "*://aniwatch.me/*" + ], + "js": [ + "enhancements/animeRequests.js" + ], + "run_at": "document_end" + } + ] } \ No newline at end of file diff --git a/utils/aniwatchCore.js b/utils/aniwatchCore.js index 263247a..fb7587a 100644 --- a/utils/aniwatchCore.js +++ b/utils/aniwatchCore.js @@ -1,10 +1,27 @@ -function executeAfterPreload(func){ - let preLoader = document.getElementById('preloader'); - - let loop = setInterval(() => { - if(preLoader.style.display==="none"){ - clearInterval(loop); - func(); +let __scripts = []; + +function registerScript(func, pattern = '.*') { + __scripts.push({ "function": func, "pattern": pattern }); +} + +function runScripts(node) { + __scripts.forEach(script => { + if (window.location.pathname.match(script.pattern)) { + script.function(node); } - }, 100); -} \ No newline at end of file + }); +} + +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 +}); \ No newline at end of file diff --git a/utils/colors.js b/utils/colors.js index a3c864b..536b09f 100644 --- a/utils/colors.js +++ b/utils/colors.js @@ -1 +1 @@ -const aniBlue = "#348fff"; \ No newline at end of file +const aniBlue = '#348fff'; \ No newline at end of file diff --git a/utils/helpers.js b/utils/helpers.js new file mode 100644 index 0000000..cb18055 --- /dev/null +++ b/utils/helpers.js @@ -0,0 +1,3 @@ +function isHtmlElement(object) { + return object instanceof HTMLElement; +} \ No newline at end of file