From 1bbca434447ced00b4f5a3e0c2694ff9951fa83d Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:48:27 +0100 Subject: [PATCH] #32 added options check for all JS enhancements --- src/javascript/enhancements/anilyr.js | 15 +++++++------ src/javascript/enhancements/animeRequests.js | 21 +++++++++++-------- .../enhancements/languageDisplay.js | 15 +++++++------ src/javascript/enhancements/notifications.js | 15 +++++++------ src/javascript/enhancements/quickSearch.js | 15 +++++++++---- .../enhancements/watch2getherChat.js | 10 +++++---- 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/javascript/enhancements/anilyr.js b/src/javascript/enhancements/anilyr.js index f80ebd8..129dbfe 100644 --- a/src/javascript/enhancements/anilyr.js +++ b/src/javascript/enhancements/anilyr.js @@ -1,3 +1,4 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; @@ -5,11 +6,13 @@ const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip'; const PLAYER_ID = 'player'; export function init() { - core.registerScript(node => { - if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { - observeScreenshotTooltip(node); - } - }, "^/anime/[0-9]*/[0-9]*$"); + if (getGlobalConfiguration().playerAutoplayAfterScreenshot) { + core.registerScript(node => { + if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { + observeScreenshotTooltip(node); + } + }, "^/anime/[0-9]*/[0-9]*$"); + } } function observeScreenshotTooltip(tooltip) { @@ -18,7 +21,7 @@ function observeScreenshotTooltip(tooltip) { // Switched to invisible if (!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') { let player = findPlayer(); - if(typeof player !== 'undefined'){ + if (typeof player !== 'undefined') { resumePlayer(player); } } diff --git a/src/javascript/enhancements/animeRequests.js b/src/javascript/enhancements/animeRequests.js index 171f191..b73ad66 100644 --- a/src/javascript/enhancements/animeRequests.js +++ b/src/javascript/enhancements/animeRequests.js @@ -1,16 +1,19 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as color from '../utils/colors'; import * as helper from '../utils/helpers'; export function init() { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - changeFollowedStarColor(node); - changeBorderColorOwnRequests(node); - removeUnknownUsers(node); - } - }, "/requests"); + if (getGlobalConfiguration().requestBeautifyPage) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + changeFollowedStarColor(node); + changeBorderColorOwnRequests(node); + removeUnknownUsers(node); + } + }, "/requests"); + } } function changeFollowedStarColor(node) { @@ -71,7 +74,7 @@ function removeUnknownUsers(node) { let parsedDocument = parser.parseFromString(profileData, 'text/html'); lowerDiv.innerHTML = ''; - while(parsedDocument.body.hasChildNodes()){ + while (parsedDocument.body.hasChildNodes()) { lowerDiv.appendChild(parsedDocument.body.removeChild(parsedDocument.body.firstChild)); } } diff --git a/src/javascript/enhancements/languageDisplay.js b/src/javascript/enhancements/languageDisplay.js index 124431e..dddd1d9 100644 --- a/src/javascript/enhancements/languageDisplay.js +++ b/src/javascript/enhancements/languageDisplay.js @@ -1,13 +1,16 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; export function init() { - core.registerScript(node => { - // run the scripts - if (helper.isHtmlElement(node)) { - updateLanguageDisplay(node) - } - }, "^/anime/[0-9]*$"); + if (getGlobalConfiguration().animeLanguageDisplay) { + core.registerScript(node => { + // run the scripts + if (helper.isHtmlElement(node)) { + updateLanguageDisplay(node) + } + }, "^/anime/[0-9]*$"); + } } function updateLanguageDisplay(node) { diff --git a/src/javascript/enhancements/notifications.js b/src/javascript/enhancements/notifications.js index e97e530..34330e3 100644 --- a/src/javascript/enhancements/notifications.js +++ b/src/javascript/enhancements/notifications.js @@ -1,14 +1,17 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; export function init() { - core.runAfterLoad(() => { - updateNotificationsInTitle(); - }, ".*"); + if (getGlobalConfiguration().websiteShowNotificationsCountInTab) { + 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 95b31d5..92bc5df 100644 --- a/src/javascript/enhancements/quickSearch.js +++ b/src/javascript/enhancements/quickSearch.js @@ -1,3 +1,4 @@ +import { getGlobalConfiguration } from '../configuration/configuration'; import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; @@ -5,9 +6,15 @@ const quickSearchID = 'ea-quickSearch'; const quickSearchLink = 'ea-quickSearchLink'; export function init() { - core.runAfterLoad(() => { - initSearch(); - }, ".*"); + let config = getGlobalConfiguration(); + console.log(config); + console.log(config.websiteDisplayQuickSearch); + console.log(getGlobalConfiguration().websiteDisplayQuickSearch) + if (getGlobalConfiguration().websiteDisplayQuickSearch) { + core.runAfterLoad(() => { + initSearch(); + }, ".*"); + } } function initSearch() { @@ -68,7 +75,7 @@ function handleSearchForShiftF(event) { if (document.activeElement instanceof HTMLInputElement || document.activeElement.isContentEditable) { return; } - + if (event.code === 'KeyF') { event.preventDefault(); document.getElementById(quickSearchID).focus(); diff --git a/src/javascript/enhancements/watch2getherChat.js b/src/javascript/enhancements/watch2getherChat.js index c173f87..96944eb 100644 --- a/src/javascript/enhancements/watch2getherChat.js +++ b/src/javascript/enhancements/watch2getherChat.js @@ -1,12 +1,14 @@ import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; import { v4 as uuidv4 } from 'uuid'; +import { getGlobalConfiguration } from '../configuration/configuration'; export function init() { - // UPS // runAfterLoad is not what we want...wait for runAfterLocationChange.... - core.runAfterLocationChange(() => { - manipulateChatInput(); - }, "^/watch2gether/.*$"); + if (getGlobalConfiguration().w2gDisplayCharacterCounter) { + core.runAfterLocationChange(() => { + manipulateChatInput(); + }, "^/watch2gether/.*$"); + } } function manipulateChatInput() {