#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 color from '../utils/colors';
import * as helper from '../utils/helpers'; import * as helper from '../utils/helpers';
core.registerScript(node => { export function init() {
core.registerScript(node => {
// run the scripts // run the scripts
if (helper.isHtmlElement(node)) { if (helper.isHtmlElement(node)) {
changeFollowedStarColor(node); changeFollowedStarColor(node);
changeBorderColorOwnRequests(node); changeBorderColorOwnRequests(node);
removeUnknownUsers(node); removeUnknownUsers(node);
} }
}, "/requests"); }, "/requests");
}
function changeFollowedStarColor(node) { function changeFollowedStarColor(node) {
const starIcon = 'star'; const starIcon = 'star';

View file

@ -1,12 +1,14 @@
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers'; import * as helper from '../utils/helpers';
core.registerScript(node => { export function init() {
core.registerScript(node => {
// run the scripts // run the scripts
if (helper.isHtmlElement(node)) { if (helper.isHtmlElement(node)) {
addListHorizontalSeparators(node) addListHorizontalSeparators(node)
} }
}, ".*"); }, ".*");
}
function addListHorizontalSeparators(node) { function addListHorizontalSeparators(node) {
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case 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 quickSearchID = 'ea-quickSearch';
const quickSearchLink = 'ea-quickSearchLink'; const quickSearchLink = 'ea-quickSearchLink';
core.runAfterLoad(() => { export function init() {
core.runAfterLoad(() => {
initSearch(); initSearch();
}, ".*"); }, ".*");
}
function initSearch() { function initSearch() {
console.log("INITSEARCH")
let entry = document.createElement('li'); let entry = document.createElement('li');
entry.setAttribute('ng-repeat', 'item in navbar'); entry.setAttribute('ng-repeat', 'item in navbar');
entry.setAttribute('ng-class', '{\'anime-indicator\': item[\'@attributes\'].title==\'Anime\'}'); 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 __scripts = [];
let __afterLoadScripts = []; 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 = '.*') { export function registerScript(func, pattern = '.*') {
__scripts.push({ "function": func, "pattern": 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() { function findPreloader() {
return document.getElementById('preloader'); return document.getElementById('preloader');
} }
@ -40,8 +44,6 @@ export function runAfterLoad(func, pattern = '.*') {
} }
} }
document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false);
function awaitPageLoaded() { function awaitPageLoaded() {
let preLoader = findPreloader(); let preLoader = findPreloader();

View file

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