@@ -57,8 +57,11 @@ <h3 style="display: inline-block; margin-right: 15px;">One Euro Filter 参数设
5757 < span style ="font-size: 12px; color: #666; "> Hz</ span >
5858 </ div >
5959 </ div >
60- < button id ="applyParams " style ="margin-top: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; "> 应用参数</ button >
61- < button id ="resetParams " style ="margin-left: 10px; padding: 8px 16px; background-color: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer; "> 重置默认值</ button >
60+ < div style ="margin-top: 10px; ">
61+ < button id ="applyParams " style ="padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; "> 应用参数</ button >
62+ < button id ="resetParams " style ="margin-left: 10px; padding: 8px 16px; background-color: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer; "> 重置默认值</ button >
63+ < button id ="forceRefresh " style ="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer; " title ="清除缓存并刷新页面,获取最新代码 "> 强制刷新</ button >
64+ </ div >
6265 </ div >
6366 </ div >
6467
@@ -96,6 +99,14 @@ <h3 style="display: inline-block; margin-right: 15px;">One Euro Filter 参数设
9699 navigator . serviceWorker . addEventListener ( 'controllerchange' , ( ) => {
97100 window . location . reload ( ) ;
98101 } ) ;
102+
103+ // 监听Service Worker消息
104+ navigator . serviceWorker . addEventListener ( 'message' , ( event ) => {
105+ if ( event . data && event . data . type === 'CACHE_CLEARED' ) {
106+ console . log ( '缓存已清除,正在刷新页面...' ) ;
107+ window . location . reload ( ) ;
108+ }
109+ } ) ;
99110 }
100111
101112 // PWA安装提示
@@ -142,6 +153,41 @@ <h3 style="display: inline-block; margin-right: 15px;">One Euro Filter 参数设
142153 installButton . remove ( ) ;
143154 }
144155 } ) ;
156+
157+ // 强制刷新缓存功能
158+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
159+ const forceRefreshBtn = document . getElementById ( 'forceRefresh' ) ;
160+ if ( forceRefreshBtn ) {
161+ forceRefreshBtn . addEventListener ( 'click' , ( ) => {
162+ if ( confirm ( '这将清除所有缓存并刷新页面,确定要继续吗?' ) ) {
163+ if ( 'serviceWorker' in navigator && navigator . serviceWorker . controller ) {
164+ // 通知Service Worker清除缓存
165+ navigator . serviceWorker . controller . postMessage ( { type : 'FORCE_REFRESH' } ) ;
166+ } else {
167+ // 如果没有Service Worker,直接强制刷新
168+ window . location . reload ( true ) ;
169+ }
170+ }
171+ } ) ;
172+ }
173+ } ) ;
174+
175+ // 键盘快捷键:Ctrl+Shift+R 强制刷新
176+ document . addEventListener ( 'keydown' , ( event ) => {
177+ if ( event . ctrlKey && event . shiftKey && event . key === 'R' ) {
178+ event . preventDefault ( ) ;
179+ if ( 'serviceWorker' in navigator && navigator . serviceWorker . controller ) {
180+ navigator . serviceWorker . controller . postMessage ( { type : 'FORCE_REFRESH' } ) ;
181+ } else {
182+ window . location . reload ( true ) ;
183+ }
184+ }
185+ } ) ;
186+
187+ // 开发模式检测:如果URL包含localhost或127.0.0.1,显示开发提示
188+ if ( window . location . hostname === 'localhost' || window . location . hostname === '127.0.0.1' ) {
189+ console . log ( '开发模式:使用 Ctrl+Shift+R 或点击"强制刷新"按钮来获取最新代码' ) ;
190+ }
145191 </ script >
146192</ body >
147193</ html >
0 commit comments