diff --git a/src/javascript/configuration/configuration.js b/src/javascript/configuration/configuration.js index 1a02c28..ec02001 100644 --- a/src/javascript/configuration/configuration.js +++ b/src/javascript/configuration/configuration.js @@ -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); + }); + } } } diff --git a/src/javascript/enhancements/anilyr.js b/src/javascript/enhancements/anilyr.js index 129dbfe..b8036f2 100644 --- a/src/javascript/enhancements/anilyr.js +++ b/src/javascript/enhancements/anilyr.js @@ -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) { - core.registerScript(node => { - if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { - observeScreenshotTooltip(node); - } - }, "^/anime/[0-9]*/[0-9]*$"); - } + 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) { diff --git a/src/javascript/enhancements/animeRequests.js b/src/javascript/enhancements/animeRequests.js index b73ad66..ce86be0 100644 --- a/src/javascript/enhancements/animeRequests.js +++ b/src/javascript/enhancements/animeRequests.js @@ -1,19 +1,21 @@ -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) { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - changeFollowedStarColor(node); - changeBorderColorOwnRequests(node); - removeUnknownUsers(node); - } - }, "/requests"); - } + getGlobalConfiguration().getProperty(SETTINGS_requestBeautifyPage, value => { + if (value) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + changeFollowedStarColor(node); + changeBorderColorOwnRequests(node); + removeUnknownUsers(node); + } + }, "/requests"); + } + }); } function changeFollowedStarColor(node) { diff --git a/src/javascript/enhancements/languageDisplay.js b/src/javascript/enhancements/languageDisplay.js index dddd1d9..cd9bf09 100644 --- a/src/javascript/enhancements/languageDisplay.js +++ b/src/javascript/enhancements/languageDisplay.js @@ -1,16 +1,20 @@ -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() { - if (getGlobalConfiguration().animeLanguageDisplay) { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - updateLanguageDisplay(node) + getGlobalConfiguration().getProperty(SETTINGS_animeLanguageDisplay, value => { + if (value) { + if (getGlobalConfiguration().animeLanguageDisplay) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + updateLanguageDisplay(node) + } + }, "^/anime/[0-9]*$"); } - }, "^/anime/[0-9]*$"); - } + } + }); } function updateLanguageDisplay(node) { diff --git a/src/javascript/enhancements/notifications.js b/src/javascript/enhancements/notifications.js index 34330e3..10df5ff 100644 --- a/src/javascript/enhancements/notifications.js +++ b/src/javascript/enhancements/notifications.js @@ -1,17 +1,19 @@ -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) { - core.runAfterLoad(() => { - updateNotificationsInTitle(); - }, ".*"); + getGlobalConfiguration().getProperty(SETTINGS_websiteShowNotificationsCountInTab, value => { + if (value) { + core.runAfterLoad(() => { + updateNotificationsInTitle(); + }, ".*"); - core.runAfterLocationChange(() => { - updateNotificationsInTitle(); - }, ".*"); - } + core.runAfterLocationChange(() => { + updateNotificationsInTitle(); + }, ".*"); + } + }); } function getNotificationCount() { diff --git a/src/javascript/enhancements/quickSearch.js b/src/javascript/enhancements/quickSearch.js index 92bc5df..dddf15d 100644 --- a/src/javascript/enhancements/quickSearch.js +++ b/src/javascript/enhancements/quickSearch.js @@ -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) { - core.runAfterLoad(() => { - initSearch(); - }, ".*"); - } + getGlobalConfiguration().getProperty(SETTINGS_websiteDisplayQuickSearch, value => { + if (value) { + core.runAfterLoad(() => { + initSearch(); + }, ".*"); + } + }); } function initSearch() { diff --git a/src/javascript/enhancements/watch2getherChat.js b/src/javascript/enhancements/watch2getherChat.js index 96944eb..a3e5dc6 100644 --- a/src/javascript/enhancements/watch2getherChat.js +++ b/src/javascript/enhancements/watch2getherChat.js @@ -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) { - core.runAfterLocationChange(() => { - manipulateChatInput(); - }, "^/watch2gether/.*$"); - } + getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => { + if (value) { + core.runAfterLocationChange(() => { + manipulateChatInput(); + }, "^/watch2gether/.*$"); + } + }); } function manipulateChatInput() {