#35 changed javascript to module logic

This commit is contained in:
Serraniel 2020-08-26 18:29:40 +02:00
parent 5b47534c50
commit db6f70600f
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
6 changed files with 25 additions and 15 deletions

View file

@ -1,6 +1,10 @@
registerScript(node => { import * as core from '../utils/aniwatchCore';
import * as color from '../utils/colors';
import * as helper from '../utils/helpers';
core.registerScript(node => {
// run the scripts // run the scripts
if (isHtmlElement(node)) { if (helper.isHtmlElement(node)) {
changeFollowedStarColor(node); changeFollowedStarColor(node);
changeBorderColorOwnRequests(node); changeBorderColorOwnRequests(node);
removeUnknownUsers(node); removeUnknownUsers(node);
@ -14,7 +18,7 @@ function changeFollowedStarColor(node) {
let followedItems = Array.from(node.querySelectorAll('i')).filter(i => i.innerText.trim() === 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 = color.aniBlue);
} }
function changeBorderColorOwnRequests(node) { function changeBorderColorOwnRequests(node) {
@ -25,7 +29,7 @@ function changeBorderColorOwnRequests(node) {
// highlight left border for own request // highlight left border for own request
if (profileLink.length > 0) { if (profileLink.length > 0) {
item.style.borderColor = aniBlue item.style.borderColor = color.aniBlue
} }
} }

View file

@ -1,6 +1,9 @@
registerScript(node => { import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
core.registerScript(node => {
// run the scripts // run the scripts
if (isHtmlElement(node)) { if (helper.isHtmlElement(node)) {
addListHorizontalSeparators(node) addListHorizontalSeparators(node)
} }
}, ".*"); }, ".*");

View file

@ -1,7 +1,10 @@
import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
const quickSearchID = 'ea-quickSearch'; const quickSearchID = 'ea-quickSearch';
const quickSearchLink = 'ea-quickSearchLink'; const quickSearchLink = 'ea-quickSearchLink';
runAfterLoad(() => { core.runAfterLoad(() => {
initSearch(); initSearch();
}, ".*"); }, ".*");
@ -58,7 +61,7 @@ function handleQuickSearch(event) {
} }
function handleSearchForShiftF(event) { function handleSearchForShiftF(event) {
if (isShiftPressed) { if (helper.isShiftPressed) {
if (event.key === 'F') { if (event.key === 'F') {
event.preventDefault(); event.preventDefault();
document.getElementById(quickSearchID).focus(); document.getElementById(quickSearchID).focus();

View file

@ -1,11 +1,11 @@
let __scripts = []; let __scripts = [];
let __afterLoadScripts = []; let __afterLoadScripts = [];
function registerScript(func, pattern = '.*') { export function registerScript(func, pattern = '.*') {
__scripts.push({ "function": func, "pattern": pattern }); __scripts.push({ "function": func, "pattern": pattern });
} }
function runScripts(node) { export function runScripts(node) {
__scripts.forEach(script => { __scripts.forEach(script => {
if (window.location.pathname.match(script.pattern)) { if (window.location.pathname.match(script.pattern)) {
script.function(node); script.function(node);
@ -31,7 +31,7 @@ function findPreloader() {
return document.getElementById('preloader'); return document.getElementById('preloader');
} }
function runAfterLoad(func, pattern = '.*') { export function runAfterLoad(func, pattern = '.*') {
let preloader = findPreloader(); let preloader = findPreloader();
if (typeof preloader !== undefined && preloader.style.display !== "none") { if (typeof preloader !== undefined && preloader.style.display !== "none") {
__afterLoadScripts.push({ "function": func, "pattern": pattern }); __afterLoadScripts.push({ "function": func, "pattern": pattern });

View file

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

View file

@ -1,7 +1,7 @@
var isShiftPressed = false; export var isShiftPressed = false;
var isCtrlPressed = false; export var isCtrlPressed = false;
function isHtmlElement(object) { export function isHtmlElement(object) {
return object instanceof HTMLElement; return object instanceof HTMLElement;
} }