Feature/#7 core logic detect page change and refresh #8
8
enhanced-aniwatch.code-workspace
Normal file
8
enhanced-aniwatch.code-workspace
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
|
@ -1,41 +1,42 @@
|
||||||
const starIcon = "star";
|
registerScript(node => {
|
||||||
const scripts = [
|
|
||||||
changeFollowedStarColor,
|
|
||||||
changeOwnBorderColor,
|
|
||||||
]
|
|
||||||
|
|
||||||
executeAfterPreload(initScripts);
|
|
||||||
|
|
||||||
function initScripts() {
|
|
||||||
// run the scripts
|
// run the scripts
|
||||||
runScripts();
|
if (isHtmlElement(node)) {
|
||||||
|
changeFollowedStarColor(node);
|
||||||
|
changeOwnBorderColor(node);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// because of late loading in the request list we have to run the codes each time the list changes
|
function changeFollowedStarColor(node) {
|
||||||
document.querySelector("md-list").addEventListener("DOMNodeInserted", event => runScripts(event), false);
|
const starIcon = "star";
|
||||||
}
|
|
||||||
|
|
||||||
function runScripts() {
|
|
||||||
scripts.forEach(script => script());
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeFollowedStarColor() {
|
|
||||||
// find stars
|
// find stars
|
||||||
let followedItems = Array.from(document.querySelectorAll("i")).filter(i => i.innerText == starIcon);
|
let followedItems = Array.from(node.querySelectorAll("i")).filter(i => i.innerText.trim() === starIcon);
|
||||||
|
|
||||||
// change color
|
// change color
|
||||||
followedItems.forEach(item => item.style.color = aniBlue);
|
followedItems.forEach(item => item.style.color = aniBlue);
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeOwnBorderColor() {
|
function changeOwnBorderColor(node) {
|
||||||
// find items -> all
|
const targetTagName = "MD-LIST-ITEM"; // tagName is upper case
|
||||||
let requestItems = document.querySelectorAll("md-list-item");
|
|
||||||
|
|
||||||
// change border color if profile link is not "false"
|
let updateFunc = item => {
|
||||||
requestItems.forEach(item => {
|
|
||||||
let profileLink = item.querySelectorAll("a[href*='/profile/']:not([href='/profile/false'])");
|
let profileLink = item.querySelectorAll("a[href*='/profile/']:not([href='/profile/false'])");
|
||||||
|
|
||||||
if (profileLink.length > 0) {
|
if (profileLink.length > 0) {
|
||||||
item.style.borderColor = aniBlue
|
item.style.borderColor = aniBlue
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// are we target tag?
|
||||||
|
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,29 +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": [
|
"matches": [
|
||||||
"*://aniwatch.me/requests"
|
"*://aniwatch.me/*"
|
||||||
],
|
],
|
||||||
"js": [
|
"js": [
|
||||||
"enhancements/animeRequests.js"
|
"enhancements/animeRequests.js"
|
||||||
],
|
],
|
||||||
"run_at": "document_end"
|
"run_at": "document_end"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -1,10 +1,23 @@
|
||||||
function executeAfterPreload(func){
|
let __scripts = [];
|
||||||
let preLoader = document.getElementById('preloader');
|
|
||||||
|
|
||||||
let loop = setInterval(() => {
|
function registerScript(func) {
|
||||||
if(preLoader.style.display==="none"){
|
__scripts.push(func);
|
||||||
clearInterval(loop);
|
|
||||||
func();
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runScripts(node) {
|
||||||
|
__scripts.forEach(script => script(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
|
||||||
|
});
|
3
utils/helpers.js
Normal file
3
utils/helpers.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function isHtmlElement(object) {
|
||||||
|
return object instanceof HTMLElement;
|
||||||
|
}
|
Loading…
Reference in a new issue