@@ -59,6 +59,40 @@ function App() {
5959 const { t } = useTranslation ( ) ;
6060 const pageTabIdRef = useRef ( 0 ) ;
6161
62+ // 只随 script 数量和启动状态而改变的state
63+ const normalEnables = useMemo ( ( ) => {
64+ // 返回字串让 React 比对 state 有否改动
65+ return scriptList . map ( ( script ) => ( script . enable ? 1 : 0 ) ) . join ( "," ) ;
66+ } , [ scriptList ] ) ;
67+
68+ // 只随 script 数量和启动状态而改变的state
69+ const backEnables = useMemo ( ( ) => {
70+ // 返回字串让 React 比对 state 有否改动
71+ return backScriptList . map ( ( script ) => ( script . enable ? 1 : 0 ) ) . join ( "," ) ;
72+ } , [ backScriptList ] ) ;
73+
74+ const normalScriptCounts = useMemo ( ( ) => {
75+ // 拆回array
76+ const enables = normalEnables . split ( "," ) ;
77+ // 计算已开启了的数量
78+ const running = enables . reduce ( ( p , c ) => p + ( + c ? 1 : 0 ) , 0 ) ;
79+ return {
80+ running,
81+ total : enables . length , // 总数
82+ } ;
83+ } , [ normalEnables ] ) ;
84+
85+ const backScriptCounts = useMemo ( ( ) => {
86+ // 拆回array
87+ const enables = backEnables . split ( "," ) ;
88+ // 计算已开启了的数量
89+ const running = enables . reduce ( ( p , c ) => p + ( + c ? 1 : 0 ) , 0 ) ;
90+ return {
91+ running,
92+ total : enables . length , // 总数
93+ } ;
94+ } , [ backEnables ] ) ;
95+
6296 const urlHost = useMemo ( ( ) => {
6397 let url : URL | undefined ;
6498 try {
@@ -443,7 +477,7 @@ function App() {
443477 style = { { maxWidth : 640 , maxHeight : 500 , overflow : "auto" } }
444478 >
445479 < CollapseItem
446- header = { t ( "current_page_scripts" ) }
480+ header = { ` ${ t ( "current_page_scripts" ) } ( ${ normalScriptCounts . running } / ${ normalScriptCounts . total } )` }
447481 name = "script"
448482 style = { { padding : "0" } }
449483 contentStyle = { { padding : "0" } }
@@ -457,7 +491,7 @@ function App() {
457491 </ CollapseItem >
458492
459493 < CollapseItem
460- header = { t ( "enabled_background_scripts" ) }
494+ header = { ` ${ t ( "enabled_background_scripts" ) } ( ${ backScriptCounts . running } / ${ backScriptCounts . total } )` }
461495 name = "background"
462496 style = { {
463497 padding : "0" ,
0 commit comments