@@ -102,46 +102,29 @@ export function useSkipSettings(options = {}) {
102102 * 立即应用片头跳过逻辑(用于视频刚开始播放时)
103103 */
104104 const applyIntroSkipImmediate = ( ) => {
105- console . log ( 'applyIntroSkipImmediate 被调用' )
106-
107- if ( ! skipIntroEnabled . value ) {
108- console . log ( '片头跳过未启用' )
109- return
110- }
111-
112- if ( skipIntroApplied . value ) {
113- console . log ( '片头跳过已应用,跳过' )
114- return
105+ if ( ! skipIntroEnabled . value || skipIntroApplied . value ) {
106+ return false
115107 }
116108
117109 const currentTime = getCurrentTime ( )
118110 const now = Date . now ( )
119111
120112 // 检查用户是否正在拖动或刚刚拖动过(3秒内)
121113 if ( userSeeking . value || ( lastUserSeekTime . value > 0 && now - lastUserSeekTime . value < 3000 ) ) {
122- console . log ( '用户正在拖动进度条或刚刚拖动过,跳过自动片头跳过' )
123- return
124- }
125-
126- // 检查是否正在全屏切换或刚刚切换过(2秒内)
127- if ( isFullscreenChanging . value || ( lastFullscreenChangeTime . value > 0 && now - lastFullscreenChangeTime . value < 2000 ) ) {
128- console . log ( '正在全屏切换或刚刚切换过,跳过自动片头跳过' )
129- return
114+ return false
130115 }
131116
132117 // 检查是否正在全屏切换或刚刚切换过(2秒内)
133118 if ( isFullscreenChanging . value || ( lastFullscreenChangeTime . value > 0 && now - lastFullscreenChangeTime . value < 2000 ) ) {
134- console . log ( '正在全屏切换或刚刚切换过,跳过自动片头跳过' )
135- return
119+ return false
136120 }
137121
138122 // 立即跳过模式:如果当前时间很小(小于等于1秒)且在片头跳过范围内,立即跳过
139123 if ( currentTime <= 1 && currentTime <= skipIntroSeconds . value ) {
140- console . log ( `立即跳过片头:从 ${ currentTime } 秒跳转到 ${ skipIntroSeconds . value } 秒 ` )
124+ console . log ( `立即跳过片头:从 ${ currentTime . toFixed ( 1 ) } s 跳转到 ${ skipIntroSeconds . value } s ` )
141125 setCurrentTime ( skipIntroSeconds . value )
142126 skipIntroApplied . value = true
143127 lastSkipTime . value = now
144- console . log ( `已立即跳过片头 ${ skipIntroSeconds . value } 秒` )
145128 return true // 返回 true 表示已执行跳过
146129 }
147130
@@ -152,21 +135,7 @@ export function useSkipSettings(options = {}) {
152135 * 应用片头跳过逻辑
153136 */
154137 const applyIntroSkip = ( ) => {
155- console . log ( 'applyIntroSkip 被调用' , {
156- skipIntroEnabled : skipIntroEnabled . value ,
157- skipIntroApplied : skipIntroApplied . value ,
158- currentTime : getCurrentTime ( ) ,
159- skipIntroSeconds : skipIntroSeconds . value ,
160- userSeeking : userSeeking . value
161- } )
162-
163- if ( ! skipIntroEnabled . value ) {
164- console . log ( '片头跳过未启用' )
165- return
166- }
167-
168- if ( skipIntroApplied . value ) {
169- console . log ( '片头跳过已应用,跳过' )
138+ if ( ! skipIntroEnabled . value || skipIntroApplied . value ) {
170139 return
171140 }
172141
@@ -175,32 +144,25 @@ export function useSkipSettings(options = {}) {
175144
176145 // 检查用户是否正在拖动或刚刚拖动过(3秒内)
177146 if ( userSeeking . value || ( lastUserSeekTime . value > 0 && now - lastUserSeekTime . value < 3000 ) ) {
178- console . log ( '用户正在拖动进度条或刚刚拖动过,跳过自动片头跳过' )
179147 return
180148 }
181149
182150 // 检查是否正在全屏切换或刚刚切换过(2秒内)
183151 if ( isFullscreenChanging . value || ( lastFullscreenChangeTime . value > 0 && now - lastFullscreenChangeTime . value < 2000 ) ) {
184- console . log ( '正在全屏切换或刚刚切换过,跳过自动片头跳过' )
185152 return
186153 }
187154
188155 // 防抖:如果距离上次跳过不足1秒,则忽略(但如果是新视频,lastSkipTime为0,允许跳过)
189- // 减少防抖时间,提高响应速度
190156 if ( lastSkipTime . value > 0 && now - lastSkipTime . value < 1000 ) {
191- console . log ( '防抖限制,跳过' )
192157 return
193158 }
194159
195160 // 如果当前时间在片头跳过范围内,则跳过
196161 if ( currentTime <= skipIntroSeconds . value ) {
197- console . log ( `准备跳过片头 :从 ${ currentTime } 秒跳转到 ${ skipIntroSeconds . value } 秒 ` )
162+ console . log ( `已跳过片头 :从 ${ currentTime . toFixed ( 1 ) } s 跳转到 ${ skipIntroSeconds . value } s ` )
198163 setCurrentTime ( skipIntroSeconds . value )
199164 skipIntroApplied . value = true
200165 lastSkipTime . value = now
201- console . log ( `已跳过片头 ${ skipIntroSeconds . value } 秒` )
202- } else {
203- console . log ( `当前时间 ${ currentTime } 秒已超过片头跳过范围 ${ skipIntroSeconds . value } 秒` )
204166 }
205167 }
206168
@@ -247,19 +209,29 @@ export function useSkipSettings(options = {}) {
247209 applyOutroSkip ( )
248210 }
249211
212+ // 防抖变量
213+ let timeUpdateDebounceTimer = null
214+
250215 /**
251216 * 处理时间更新事件
252217 */
253218 const handleTimeUpdate = ( ) => {
254- // 应用片头跳过(仅在未应用时)
255- if ( skipIntroEnabled . value && ! skipIntroApplied . value ) {
256- applyIntroSkip ( )
219+ // 防抖:减少频繁调用,每200ms最多执行一次
220+ if ( timeUpdateDebounceTimer ) {
221+ clearTimeout ( timeUpdateDebounceTimer )
257222 }
223+
224+ timeUpdateDebounceTimer = setTimeout ( ( ) => {
225+ // 应用片头跳过(仅在未应用时)
226+ if ( skipIntroEnabled . value && ! skipIntroApplied . value ) {
227+ applyIntroSkip ( )
228+ }
258229
259- // 应用片尾跳过(仅在未应用时)
260- if ( skipOutroEnabled . value && ! skipOutroApplied . value ) {
261- applyOutroSkip ( )
262- }
230+ // 应用片尾跳过(仅在未应用时)
231+ if ( skipOutroEnabled . value && ! skipOutroApplied . value ) {
232+ applyOutroSkip ( )
233+ }
234+ } , 200 )
263235 }
264236
265237 /**
0 commit comments