@@ -1260,6 +1260,22 @@ <h2 data-i18n="summary">切换摘要</h2>
12601260
12611261 const el = ( id ) => document . getElementById ( id ) ;
12621262 const t = ( key ) => copy [ state . lang ] [ key ] || copy . en [ key ] || key ;
1263+ let toastTimer = null ;
1264+
1265+ function showToast ( message , { duration = 4000 } = { } ) {
1266+ const node = el ( "toast" ) ;
1267+ if ( toastTimer ) {
1268+ window . clearTimeout ( toastTimer ) ;
1269+ toastTimer = null ;
1270+ }
1271+ node . textContent = message || "" ;
1272+ if ( message && duration > 0 ) {
1273+ toastTimer = window . setTimeout ( ( ) => {
1274+ node . textContent = "" ;
1275+ toastTimer = null ;
1276+ } , duration ) ;
1277+ }
1278+ }
12631279
12641280 function optionsFor ( platform ) {
12651281 return state . accountOptions [ platform ] && state . accountOptions [ platform ] . length
@@ -2663,7 +2679,7 @@ <h2 data-i18n="summary">切换摘要</h2>
26632679
26642680 async function dispatchSwitch ( ) {
26652681 if ( ! state . auth . allowed ) return ;
2666- el ( "toast" ) . textContent = t ( "dispatching" ) ;
2682+ showToast ( t ( "dispatching" ) , { duration : 0 } ) ;
26672683 try {
26682684 const response = await fetch ( "/api/switch" , {
26692685 method : "POST" ,
@@ -2672,10 +2688,10 @@ <h2 data-i18n="summary">切换摘要</h2>
26722688 } ) ;
26732689 const payload = await response . json ( ) ;
26742690 if ( ! response . ok || ! payload . ok ) throw new Error ( payload . error || t ( "dispatchFailed" ) ) ;
2675- el ( "toast" ) . textContent = t ( "dispatched" ) ;
2691+ showToast ( t ( "dispatched" ) , { duration : 4000 } ) ;
26762692 if ( payload . actions_url ) window . open ( payload . actions_url , "_blank" , "noopener,noreferrer" ) ;
26772693 } catch ( error ) {
2678- el ( "toast" ) . textContent = `${ t ( "dispatchFailed" ) } : ${ error . message } ` ;
2694+ showToast ( `${ t ( "dispatchFailed" ) } : ${ error . message } ` , { duration : 12000 } ) ;
26792695 }
26802696 }
26812697
@@ -2798,9 +2814,9 @@ <h2 data-i18n="summary">切换摘要</h2>
27982814 el ( "copy-button" ) . addEventListener ( "click" , async ( ) => {
27992815 try {
28002816 await navigator . clipboard . writeText ( summaryText ( ) ) ;
2801- el ( "toast" ) . textContent = t ( "copied" ) ;
2817+ showToast ( t ( "copied" ) , { duration : 3000 } ) ;
28022818 } catch {
2803- el ( "toast" ) . textContent = summaryText ( ) ;
2819+ showToast ( summaryText ( ) , { duration : 0 } ) ;
28042820 }
28052821 } ) ;
28062822
0 commit comments