#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 { 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 {
constructor() {
// website
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();
this.settingsCache = new Map();
}
reloadConfiguration() {
// website
getGlobalStorageProvider().getData('websiteDisplayQuickSearch', this.websiteDisplayQuickSearch, value => this.websiteDisplayQuickSearch = value);
getGlobalStorageProvider().getData('websiteShowNotificationsCountInTab', this.websiteShowNotificationsCountInTab, value => this.websiteShowNotificationsCountInTab = value);
getGlobalStorageProvider().getData('websiteHideUnusedTabs', this.websiteHideUnusedTabs, value => this.websiteHideUnusedTabs = value);
getGlobalStorageProvider().getData('websiteOptimizeListAppearance', this.websiteOptimizeListAppearance, value => this.websiteOptimizeListAppearance = value);
// anime
getGlobalStorageProvider().getData('animeLanguageDisplay', this.animeLanguageDisplay, value => this.animeLanguageDisplay = 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);
getProperty(key, callback) {
if (this.settingsCache.has(key)) {
callback(this.settingsCache.get(key));
}
else {
// 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 => {
this.settingsCache.set(key, value);
callback(value);
});
}
}
}

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

View file

@ -1,10 +1,11 @@
import { getGlobalConfiguration } from '../configuration/configuration';
import { getGlobalConfiguration, SETTINGS_requestBeautifyPage } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore';
import * as color from '../utils/colors';
import * as helper from '../utils/helpers';
export function init() {
if (getGlobalConfiguration().requestBeautifyPage) {
getGlobalConfiguration().getProperty(SETTINGS_requestBeautifyPage, value => {
if (value) {
core.registerScript(node => {
// run the scripts
if (helper.isHtmlElement(node)) {
@ -14,6 +15,7 @@ export function init() {
}
}, "/requests");
}
});
}
function changeFollowedStarColor(node) {

View file

@ -1,8 +1,10 @@
import { getGlobalConfiguration } from '../configuration/configuration';
import { getGlobalConfiguration, SETTINGS_animeLanguageDisplay } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
export function init() {
getGlobalConfiguration().getProperty(SETTINGS_animeLanguageDisplay, value => {
if (value) {
if (getGlobalConfiguration().animeLanguageDisplay) {
core.registerScript(node => {
// run the scripts
@ -12,6 +14,8 @@ export function init() {
}, "^/anime/[0-9]*$");
}
}
});
}
function updateLanguageDisplay(node) {
const listNodeName = 'MD-LIST-ITEM';

View file

@ -1,9 +1,10 @@
import { getGlobalConfiguration } from '../configuration/configuration';
import { getGlobalConfiguration, SETTINGS_websiteShowNotificationsCountInTab } from '../configuration/configuration';
import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
export function init() {
if (getGlobalConfiguration().websiteShowNotificationsCountInTab) {
getGlobalConfiguration().getProperty(SETTINGS_websiteShowNotificationsCountInTab, value => {
if (value) {
core.runAfterLoad(() => {
updateNotificationsInTitle();
}, ".*");
@ -12,6 +13,7 @@ export function init() {
updateNotificationsInTitle();
}, ".*");
}
});
}
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 helper from '../utils/helpers';
@ -6,15 +6,13 @@ const quickSearchID = 'ea-quickSearch';
const quickSearchLink = 'ea-quickSearchLink';
export function init() {
let config = getGlobalConfiguration();
console.log(config);
console.log(config.websiteDisplayQuickSearch);
console.log(getGlobalConfiguration().websiteDisplayQuickSearch)
if (getGlobalConfiguration().websiteDisplayQuickSearch) {
getGlobalConfiguration().getProperty(SETTINGS_websiteDisplayQuickSearch, value => {
if (value) {
core.runAfterLoad(() => {
initSearch();
}, ".*");
}
});
}
function initSearch() {

View file

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