From 14d1ebbb5364c1ab6542a689d8c569458a0a9b3a Mon Sep 17 00:00:00 2001 From: moshangqi <2509678669@qq.com> Date: Fri, 17 Nov 2023 12:01:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BF=AE=E9=A5=B0?= =?UTF-8?q?=E9=94=AE=E5=92=8C=E5=85=B3=E9=97=AD=E9=80=BB=E8=BE=91=E7=9A=84?= =?UTF-8?q?=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background/core/configManager/wordMark.ts | 12 +++++--- src/components/DisableUrlCard/index.tsx | 2 +- src/components/WordMarkLayout/index.tsx | 5 ++-- src/isomorphic/constant/wordMark.ts | 2 +- src/pages/inject/LevitateBall/app.tsx | 2 +- .../inject/WordMark/Inner/DisableMenu.tsx | 16 +++++++++- src/pages/inject/WordMark/Inner/index.tsx | 29 ++++++++++--------- src/pages/setting/wordMark/index.module.less | 4 +++ src/pages/setting/wordMark/index.tsx | 26 ++++++++++++++++- 9 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/background/core/configManager/wordMark.ts b/src/background/core/configManager/wordMark.ts index 302b94eb..b36684b1 100644 --- a/src/background/core/configManager/wordMark.ts +++ b/src/background/core/configManager/wordMark.ts @@ -26,10 +26,6 @@ class WordMarkConfigManager { ...config, [key]: value, }; - // enable 改变时,将 disable url 全部清空 - if (key === 'enable') { - result.disableUrl = []; - } await Chrome.storage.local.set({ [STORAGE_KEYS.SETTINGS.WORD_MARK_CONFIG]: result, }); @@ -70,6 +66,14 @@ class WordMarkConfigManager { config[key] = defaultWordMarkConfig[key] as never; } + // 由于历史数据可能被写入 string 或者 string[] 如果判断出是这种数据的,将内容置空 + if (key === 'disableUrl') { + const tempValue = config[key]; + if (typeof tempValue === 'string' || typeof tempValue?.[0] === 'string') { + config[key] = []; + } + } + /** * 当缓存中的 toolbars 长度和默认不一致时,说明扩展了 toolbars * 然后将新增的 toolbars 扩展到缓存的最后 diff --git a/src/components/DisableUrlCard/index.tsx b/src/components/DisableUrlCard/index.tsx index d353bfd5..a7bfe4c4 100644 --- a/src/components/DisableUrlCard/index.tsx +++ b/src/components/DisableUrlCard/index.tsx @@ -20,7 +20,7 @@ function DisableUrlCard(props: IDisableUrlCardProps) { return null; } return ( - + {options.map((item, index) => { return ( diff --git a/src/components/WordMarkLayout/index.tsx b/src/components/WordMarkLayout/index.tsx index fb555b51..f5a79dc2 100644 --- a/src/components/WordMarkLayout/index.tsx +++ b/src/components/WordMarkLayout/index.tsx @@ -18,10 +18,11 @@ function WordMarkLayout(props: IWordMarkLayoutProps) { const isEnableWordMark = (config: IWordMarkConfig | null) => { const url = `${window.location.origin}${window.location.pathname}`; - if (config?.evokeWordMarkShortKey) { + if (!config?.enable && config?.evokeWordMarkShortKey) { return true; } - if (!config?.enable || config.disableUrl?.includes(url)) { + const isDisableUrl = config?.disableUrl?.find?.(item => item.origin === url); + if (!config?.enable || !!isDisableUrl) { return false; } return true; diff --git a/src/isomorphic/constant/wordMark.ts b/src/isomorphic/constant/wordMark.ts index 91f13c9a..6801d4d2 100644 --- a/src/isomorphic/constant/wordMark.ts +++ b/src/isomorphic/constant/wordMark.ts @@ -24,7 +24,7 @@ export type IWordMarkConfig = { innerPinList: Array; // 禁用页面的 url - disableUrl: Array; + disableUrl: Array<{ origin: string; icon: string }>; // 剪藏时唤起面板 evokePanelWhenClip: boolean; diff --git a/src/pages/inject/LevitateBall/app.tsx b/src/pages/inject/LevitateBall/app.tsx index d59e9e90..d0bf66e3 100644 --- a/src/pages/inject/LevitateBall/app.tsx +++ b/src/pages/inject/LevitateBall/app.tsx @@ -98,7 +98,7 @@ function App() { > {__i18n('设置')} - {__i18n('开启')} + {__i18n('中开启')} ), diff --git a/src/pages/inject/WordMark/Inner/DisableMenu.tsx b/src/pages/inject/WordMark/Inner/DisableMenu.tsx index d431f07a..d7607151 100644 --- a/src/pages/inject/WordMark/Inner/DisableMenu.tsx +++ b/src/pages/inject/WordMark/Inner/DisableMenu.tsx @@ -2,24 +2,38 @@ import React from 'react'; import { __i18n } from '@/isomorphic/i18n'; import LinkHelper from '@/isomorphic/link-helper'; import { backgroundBridge } from '@/core/bridge/background'; +import { useWordMarkContext } from '@/components/WordMarkLayout/useWordMarkContext'; import styles from './DisableMenu.module.less'; function DisableMenu() { + const { disableUrl } = useWordMarkContext(); const disableForever = () => { backgroundBridge.configManager.update('wordMark', 'enable', false, { notice: true, }); + window._yuque_ext_app.removeWordMark(); }; const disableForPage = () => { + const iconLink = + document.querySelector("link[rel*='icon']") || + document.querySelector("link[rel*='Icon']"); + const iconUrl = (iconLink as HTMLLinkElement)?.href; backgroundBridge.configManager.update( 'wordMark', 'disableUrl', - `${window.location.origin}${window.location.pathname}`, + [ + ...disableUrl, + { + origin: `${window.location.origin}${window.location.pathname}`, + icon: iconUrl, + }, + ], { notice: true, }, ); + window._yuque_ext_app.removeWordMark(); }; const disableOnce = () => { diff --git a/src/pages/inject/WordMark/Inner/index.tsx b/src/pages/inject/WordMark/Inner/index.tsx index 1386c0ad..9b03d8fc 100644 --- a/src/pages/inject/WordMark/Inner/index.tsx +++ b/src/pages/inject/WordMark/Inner/index.tsx @@ -46,10 +46,7 @@ function InnerWordMark(props: InnerWordMarkProps) { } if (pinedTools.length > 3) { return ( - + -
- } - overlayClassName={styles.overlayClassName} - > -
- -
-
+ {(wordMarkContext.enable || !wordMarkContext.evokeWordMarkShortKey) && ( + <> +
+ } + overlayClassName={styles.overlayClassName} + > +
+ +
+
+ + )}
); } diff --git a/src/pages/setting/wordMark/index.module.less b/src/pages/setting/wordMark/index.module.less index f5aa3e10..6df2e957 100644 --- a/src/pages/setting/wordMark/index.module.less +++ b/src/pages/setting/wordMark/index.module.less @@ -37,3 +37,7 @@ .iconWrapper { font-size: @font-size-lg; } + +.disableUrlCard { + margin-top: 18px; +} diff --git a/src/pages/setting/wordMark/index.tsx b/src/pages/setting/wordMark/index.tsx index aba399cb..5fa3f603 100644 --- a/src/pages/setting/wordMark/index.tsx +++ b/src/pages/setting/wordMark/index.tsx @@ -1,5 +1,6 @@ -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { Select, Switch, Row, Col } from 'antd'; +import DisableUrlCard, { IDisableUrlItem } from '@/components/DisableUrlCard'; import { ToolbarItem, toolbars } from '@/pages/inject/WordMark/constants'; import { WordMarkOptionTypeEnum } from '@/isomorphic/constant/wordMark'; import { __i18n } from '@/isomorphic/i18n'; @@ -94,6 +95,16 @@ function WordMark() { onConfigChange('disableFunction', result); }; + const onDelete = useCallback( + (item: IDisableUrlItem) => { + const filterArray = config?.disableUrl?.filter( + d => d.origin !== item.origin, + ); + onConfigChange('disableUrl', filterArray); + }, + [config], + ); + useEffect(() => { backgroundBridge.configManager.get('wordMark').then(res => { setConfig(res); @@ -135,6 +146,19 @@ function WordMark() { />
)} + {!!config.disableUrl?.length && config.enable && ( +
+
+ {__i18n('管理不展示划词工具栏的页面')} +
+
+ +
+
+ )}