@@ -19,6 +19,7 @@ if (!navigator.serviceWorker) {
1919 num = setInterval ( ( ) => postMessage ( "popup-lyric-update-ui" ) , 16.66 ) ;
2020 } else if ( event . data === "popup-lyric-stop-update" ) {
2121 clearInterval ( num ) ;
22+ postMessage ( "popup-lyric-update-ui" ) ;
2223 num = null ;
2324 }
2425 } ;
@@ -41,6 +42,21 @@ function PopupLyrics() {
4142 }
4243 } ;
4344
45+ let workerIsRunning = null ;
46+ document . addEventListener ( "visibilitychange" , ( e ) => {
47+ if ( e . target . hidden ) {
48+ if ( ! workerIsRunning ) {
49+ worker . postMessage ( "popup-lyric-request-update" ) ;
50+ workerIsRunning = true ;
51+ }
52+ } else {
53+ if ( workerIsRunning ) {
54+ worker . postMessage ( "popup-lyric-stop-update" ) ;
55+ workerIsRunning = false ;
56+ }
57+ }
58+ } ) ;
59+
4460 /* TRANSLATOR */
4561 const kuroshiroPath =
4662 "https://cdn.jsdelivr.net/npm/kuroshiro@1.2.0/dist/kuroshiro.min.js" ;
@@ -920,7 +936,7 @@ function PopupLyrics() {
920936
921937 try {
922938 const data = await service . call ( info ) ;
923- console . log ( data ) ;
939+ // console.log(data);
924940
925941 let dataStr ;
926942
@@ -1389,7 +1405,6 @@ function renderLyrics(ctx, lyrics, currentTime) {
13891405 ctx . restore ( ) ;
13901406}
13911407
1392- let workerIsRunning = null ;
13931408let timeout = null ;
13941409
13951410async function tick ( options ) {
@@ -1425,17 +1440,17 @@ async function tick(options) {
14251440 return ;
14261441 }
14271442
1428- if ( document . hidden ) {
1429- if ( ! workerIsRunning ) {
1430- worker . postMessage ( "popup-lyric-request-update" ) ;
1431- workerIsRunning = true ;
1432- }
1433- } else {
1434- if ( workerIsRunning ) {
1435- worker . postMessage ( "popup-lyric-stop-update" ) ;
1436- workerIsRunning = false ;
1437- }
1438-
1443+ if ( ! document . hidden ) {
1444+ // if (!workerIsRunning) {
1445+ // worker.postMessage("popup-lyric-request-update");
1446+ // workerIsRunning = true;
1447+ // }
1448+ // } else {
1449+ // if (workerIsRunning) {
1450+ // worker.postMessage("popup-lyric-stop-update");
1451+ // workerIsRunning = false;
1452+ // }
1453+ //
14391454 requestAnimationFrame ( ( ) => tick ( options ) ) ;
14401455 }
14411456}
@@ -1501,7 +1516,6 @@ button.switch.small {
15011516}
15021517#popup-config-container input {
15031518 width: 100%;
1504- margin-top: 10px;
15051519 padding: 0 5px;
15061520 height: 32px;
15071521 border: 0;
0 commit comments