#32 Changed Configuration adapter and switched to callbacks where the configuration is used

This commit is contained in:
Serraniel 2020-11-07 18:23:00 +01:00
parent 1bbca43444
commit d0ace4b1d2
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
7 changed files with 88 additions and 92 deletions

View file

@ -1,49 +1,36 @@
import { getGlobalStorageProvider } from "../browserApi/storageProvider"; import { getGlobalStorageProvider } from "../browserApi/storageProvider";
import { assigned } from "../utils/helpers"; import { assigned } from "../utils/helpers";
// website
export const SETTINGS_websiteDisplayQuickSearch = 'websiteDisplayQuickSearch'; //
export const SETTINGS_websiteShowNotificationsCountInTab = 'websiteShowNotificationsCountInTab'; //
export const SETTINGS_websiteHideUnusedTabs = 'websiteHideUnusedTabs';
export const SETTINGS_websiteOptimizeListAppearance = 'websiteOptimizeListAppearance';
// anime
export const SETTINGS_animeLanguageDisplay = 'animeLanguageDisplay'; //
// requests
export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage'; //
// player
export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot'; //
// w2g
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter'; //
class Configuration { class Configuration {
constructor() { constructor() {
// website this.settingsCache = new Map();
this.websiteDisplayQuickSearch = true;
this.websiteShowNotificationsCountInTab = true;
this.websiteHideUnusedTabs = true;
this.websiteOptimizeListAppearance = true;
// anime
this.animeLanguageDisplay = true;
// requests
this.requestBeautifyPage = true;
// player
this.playerAutoplayAfterScreenshot = true;
// w2g
this.w2gDisplayCharacterCounter = true;
this.reloadConfiguration();
} }
reloadConfiguration() { getProperty(key, callback) {
// website if (this.settingsCache.has(key)) {
getGlobalStorageProvider().getData('websiteDisplayQuickSearch', this.websiteDisplayQuickSearch, value => this.websiteDisplayQuickSearch = value); callback(this.settingsCache.get(key));
getGlobalStorageProvider().getData('websiteShowNotificationsCountInTab', this.websiteShowNotificationsCountInTab, value => this.websiteShowNotificationsCountInTab = value); }
getGlobalStorageProvider().getData('websiteHideUnusedTabs', this.websiteHideUnusedTabs, value => this.websiteHideUnusedTabs = value); else {
getGlobalStorageProvider().getData('websiteOptimizeListAppearance', this.websiteOptimizeListAppearance, value => this.websiteOptimizeListAppearance = value); // OOOPS // currently all settings are default true. This isn´t a problem but there should be much better soloutions after migration to typescript....
let value = getGlobalStorageProvider().getData(key, true, value => {
// anime this.settingsCache.set(key, value);
getGlobalStorageProvider().getData('animeLanguageDisplay', this.animeLanguageDisplay, value => this.animeLanguageDisplay = value); callback(value);
});
// requests }
getGlobalStorageProvider().getData('requestBeautifyPage', this.requestBeautifyPage, value => this.requestBeautifyPage = value);
// player
getGlobalStorageProvider().getData('playerAutoplayAfterScreenshot', this.playerAutoplayAfterScreenshot, value => this.playerAutoplayAfterScreenshot = value);
// w2g
getGlobalStorageProvider().getData('w2gDisplayCharacterCounter', this.w2gDisplayCharacterCounter, value => this.w2gDisplayCharacterCounter = value);
console.log(this);
} }
} }

View file

@ -1,4 +1,4 @@
import { getGlobalConfiguration } from '../configuration/configuration'; import { getGlobalConfiguration, SETTINGS_playerAutoplayAfterScreenshot } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers'; import * as helper from '../utils/helpers';
@ -6,13 +6,15 @@ const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip';
const PLAYER_ID = 'player'; const PLAYER_ID = 'player';
export function init() { export function init() {
if (getGlobalConfiguration().playerAutoplayAfterScreenshot) { getGlobalConfiguration().getProperty(SETTINGS_playerAutoplayAfterScreenshot, value => {
core.registerScript(node => { if (value) {
if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { core.registerScript(node => {
observeScreenshotTooltip(node); if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) {
} observeScreenshotTooltip(node);
}, "^/anime/[0-9]*/[0-9]*$"); }
} }, "^/anime/[0-9]*/[0-9]*$");
}
});
} }
function observeScreenshotTooltip(tooltip) { function observeScreenshotTooltip(tooltip) {

View file

@ -1,19 +1,21 @@
import { getGlobalConfiguration } 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'; import * as helper from '../utils/helpers';
export function init() { export function init() {
if (getGlobalConfiguration().requestBeautifyPage) { getGlobalConfiguration().getProperty(SETTINGS_requestBeautifyPage, value => {
core.registerScript(node => { if (value) {
// run the scripts core.registerScript(node => {
if (helper.isHtmlElement(node)) { // run the scripts
changeFollowedStarColor(node); if (helper.isHtmlElement(node)) {
changeBorderColorOwnRequests(node); changeFollowedStarColor(node);
removeUnknownUsers(node); changeBorderColorOwnRequests(node);
} removeUnknownUsers(node);
}, "/requests"); }
} }, "/requests");
}
});
} }
function changeFollowedStarColor(node) { function changeFollowedStarColor(node) {

View file

@ -1,16 +1,20 @@
import { getGlobalConfiguration } from '../configuration/configuration'; import { getGlobalConfiguration, SETTINGS_animeLanguageDisplay } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers'; import * as helper from '../utils/helpers';
export function init() { export function init() {
if (getGlobalConfiguration().animeLanguageDisplay) { getGlobalConfiguration().getProperty(SETTINGS_animeLanguageDisplay, value => {
core.registerScript(node => { if (value) {
// run the scripts if (getGlobalConfiguration().animeLanguageDisplay) {
if (helper.isHtmlElement(node)) { core.registerScript(node => {
updateLanguageDisplay(node) // run the scripts
if (helper.isHtmlElement(node)) {
updateLanguageDisplay(node)
}
}, "^/anime/[0-9]*$");
} }
}, "^/anime/[0-9]*$"); }
} });
} }
function updateLanguageDisplay(node) { function updateLanguageDisplay(node) {

View file

@ -1,17 +1,19 @@
import { getGlobalConfiguration } from '../configuration/configuration'; import { getGlobalConfiguration, SETTINGS_websiteShowNotificationsCountInTab } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers'; import * as helper from '../utils/helpers';
export function init() { export function init() {
if (getGlobalConfiguration().websiteShowNotificationsCountInTab) { getGlobalConfiguration().getProperty(SETTINGS_websiteShowNotificationsCountInTab, value => {
core.runAfterLoad(() => { if (value) {
updateNotificationsInTitle(); core.runAfterLoad(() => {
}, ".*"); updateNotificationsInTitle();
}, ".*");
core.runAfterLocationChange(() => { core.runAfterLocationChange(() => {
updateNotificationsInTitle(); updateNotificationsInTitle();
}, ".*"); }, ".*");
} }
});
} }
function getNotificationCount() { function getNotificationCount() {

View file

@ -1,4 +1,4 @@
import { getGlobalConfiguration } from '../configuration/configuration'; import { getGlobalConfiguration, SETTINGS_websiteDisplayQuickSearch } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers'; import * as helper from '../utils/helpers';
@ -6,15 +6,13 @@ const quickSearchID = 'ea-quickSearch';
const quickSearchLink = 'ea-quickSearchLink'; const quickSearchLink = 'ea-quickSearchLink';
export function init() { export function init() {
let config = getGlobalConfiguration(); getGlobalConfiguration().getProperty(SETTINGS_websiteDisplayQuickSearch, value => {
console.log(config); if (value) {
console.log(config.websiteDisplayQuickSearch); core.runAfterLoad(() => {
console.log(getGlobalConfiguration().websiteDisplayQuickSearch) initSearch();
if (getGlobalConfiguration().websiteDisplayQuickSearch) { }, ".*");
core.runAfterLoad(() => { }
initSearch(); });
}, ".*");
}
} }
function initSearch() { function initSearch() {

View file

@ -1,14 +1,15 @@
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { getGlobalConfiguration } from '../configuration/configuration'; import { getGlobalConfiguration, SETTINGS_w2gDisplayCharacterCounter } from '../configuration/configuration';
export function init() { export function init() {
if (getGlobalConfiguration().w2gDisplayCharacterCounter) { getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => {
core.runAfterLocationChange(() => { if (value) {
manipulateChatInput(); core.runAfterLocationChange(() => {
}, "^/watch2gether/.*$"); manipulateChatInput();
} }, "^/watch2gether/.*$");
}
});
} }
function manipulateChatInput() { function manipulateChatInput() {