#35 rewrite code to modules

This commit is contained in:
Serraniel 2020-08-26 20:31:56 +02:00
parent 329031aff3
commit 0cb210dd4b
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
6 changed files with 65 additions and 35 deletions

View file

@ -2,14 +2,16 @@ import * as core from '../utils/aniwatchCore';
import * as color from '../utils/colors';
import * as helper from '../utils/helpers';
core.registerScript(node => {
// run the scripts
if (helper.isHtmlElement(node)) {
changeFollowedStarColor(node);
changeBorderColorOwnRequests(node);
removeUnknownUsers(node);
}
}, "/requests");
export function init() {
core.registerScript(node => {
// run the scripts
if (helper.isHtmlElement(node)) {
changeFollowedStarColor(node);
changeBorderColorOwnRequests(node);
removeUnknownUsers(node);
}
}, "/requests");
}
function changeFollowedStarColor(node) {
const starIcon = 'star';

View file

@ -1,12 +1,14 @@
import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
core.registerScript(node => {
// run the scripts
if (helper.isHtmlElement(node)) {
addListHorizontalSeparators(node)
}
}, ".*");
export function init() {
core.registerScript(node => {
// run the scripts
if (helper.isHtmlElement(node)) {
addListHorizontalSeparators(node)
}
}, ".*");
}
function addListHorizontalSeparators(node) {
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case

View file

@ -4,11 +4,14 @@ import * as helper from '../utils/helpers';
const quickSearchID = 'ea-quickSearch';
const quickSearchLink = 'ea-quickSearchLink';
core.runAfterLoad(() => {
initSearch();
}, ".*");
export function init() {
core.runAfterLoad(() => {
initSearch();
}, ".*");
}
function initSearch() {
console.log("INITSEARCH")
let entry = document.createElement('li');
entry.setAttribute('ng-repeat', 'item in navbar');
entry.setAttribute('ng-class', '{\'anime-indicator\': item[\'@attributes\'].title==\'Anime\'}');

19
src/javascript/index.js Normal file
View file

@ -0,0 +1,19 @@
// core
import { initCore } from './utils/aniwatchCore';
// helper
import { initHelpers } from './utils/helpers';
// enhancements
import { init as animeRequests } from './enhancements/animeRequests';
import { init as lists } from './enhancements/lists';
import { init as quickSearch } from './enhancements/quickSearch';
// core
initCore();
//helper
initHelpers();
// enhancements
animeRequests();
lists();
quickSearch();

View file

@ -1,6 +1,24 @@
let __scripts = [];
let __afterLoadScripts = [];
export function initCore() {
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
});
document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false);
}
export function registerScript(func, pattern = '.*') {
__scripts.push({ "function": func, "pattern": pattern });
}
@ -13,20 +31,6 @@ export function runScripts(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
});
function findPreloader() {
return document.getElementById('preloader');
}
@ -40,8 +44,6 @@ export function runAfterLoad(func, pattern = '.*') {
}
}
document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false);
function awaitPageLoaded() {
let preLoader = findPreloader();

View file

@ -5,8 +5,10 @@ export function isHtmlElement(object) {
return object instanceof HTMLElement;
}
document.addEventListener('keydown', event => handleKeyDown(event));
document.addEventListener('keyup', event => handleKeyUp(event));
export function initHelpers() {
document.addEventListener('keydown', event => handleKeyDown(event));
document.addEventListener('keyup', event => handleKeyUp(event));
}
function handleKeyDown(event) {
handleKeyToggle(event, true);