#32 Changed Configuration adapter and switched to callbacks where the configuration is used
This commit is contained in:
parent
1bbca43444
commit
d0ace4b1d2
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue