Feature/#48 migrate to typescript #151

Merged
Serraniel merged 30 commits from feature/#48-migrate-to-typescript into develop 2020-12-30 17:24:49 +01:00
Showing only changes of commit f99034ceb3 - Show all commits

View file

@ -1,14 +1,13 @@
import { getGlobalConfiguration, SETTINGS_requestBeautifyPage } from '../configuration/configuration'; import { getGlobalConfiguration, SETTINGS_requestBeautifyPage } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import * as color from '../utils/colors'; import * as color from '../utils/colors';
import * as helper from '../utils/helpers';
export function init() { export function init(): void {
getGlobalConfiguration().getProperty(SETTINGS_requestBeautifyPage, value => { getGlobalConfiguration().getProperty(SETTINGS_requestBeautifyPage, value => {
if (value) { if (value) {
core.registerScript(node => { core.registerScript(node => {
// run the scripts // run the scripts
if (helper.isHtmlElement(node)) { if (node instanceof HTMLElement) {
changeFollowedStarColor(node); changeFollowedStarColor(node);
changeBorderColorOwnRequests(node); changeBorderColorOwnRequests(node);
removeUnknownUsers(node); removeUnknownUsers(node);
@ -18,20 +17,20 @@ export function init() {
}); });
} }
function changeFollowedStarColor(node) { function changeFollowedStarColor(node: HTMLElement): void {
const starIcon = 'star'; const STAR_ICON = 'star';
// find stars // find stars
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() === STAR_ICON);
// change color // change color
followedItems.forEach(item => item.style.color = color.aniBlue); followedItems.forEach(item => item.style.color = color.aniBlue);
} }
function changeBorderColorOwnRequests(node) { function changeBorderColorOwnRequests(node: HTMLElement): void {
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case const TARGET_TAG_NAME = 'MD-LIST-ITEM'; // tagName is upper case
let updateFunc = item => { let updateFunc = (item: HTMLElement): void => {
let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])'); let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])');
// highlight left border for own request // highlight left border for own request
@ -41,7 +40,7 @@ function changeBorderColorOwnRequests(node) {
} }
// are we target tag? // are we target tag?
if (node.tagName === targetTagName) { if (node.tagName === TARGET_TAG_NAME) {
updateFunc(node); updateFunc(node);
} else { } else {
// find items -> all // find items -> all
@ -49,15 +48,17 @@ function changeBorderColorOwnRequests(node) {
// update borders // update borders
requestItems.forEach(item => { requestItems.forEach(item => {
if (item instanceof HTMLElement) {
updateFunc(item); updateFunc(item);
}
}); });
} }
} }
function removeUnknownUsers(node) { function removeUnknownUsers(node: HTMLElement): void {
const targetTagName = 'MD-LIST-ITEM'; // tagName is upper case const TARGET_TAG_NAME = 'MD-LIST-ITEM'; // tagName is upper case
let updateFunc = item => { let updateFunc = (item: Element) => {
// find user profile link -> own request // find user profile link -> own request
let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])'); let profileLink = item.querySelectorAll('a[href*="/profile/"]:not([href="/profile/false"])');
@ -66,7 +67,7 @@ function removeUnknownUsers(node) {
let lowerDiv = upperDiv.parentElement.nextElementSibling; let lowerDiv = upperDiv.parentElement.nextElementSibling;
// remember Data // remember Data
let anime = lowerDiv.innerText; let anime = lowerDiv.textContent;
let profileData = upperDiv.innerHTML; let profileData = upperDiv.innerHTML;
// add user note if own request // add user note if own request
@ -92,7 +93,7 @@ function removeUnknownUsers(node) {
upperDiv.appendChild(bElement); upperDiv.appendChild(bElement);
} }
if (node.tagName === targetTagName) { if (node.tagName === TARGET_TAG_NAME) {
updateFunc(node); updateFunc(node);
} else { } else {
// find items -> all // find items -> all