Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

perf(web): 悬停扫格子先把下一格取回来再换上去

longmeidao5be8b4c2de29
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index b044f1e31..fb5e5d1cd 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -7125,6 +7125,17 @@ class WebUiSourceTests(unittest.TestCase):
# 待删卡片的灰化要连这一层一起,否则悬停时整卡「复活」成正常色。
self.assertIn(".card.pending-delete .hvframes{", css)
+ def test_the_next_frame_is_loaded_before_it_is_shown(self):
+ """下一格先拉到手再换上去,没拉到就停在当前这格。
+
+ 直接把 src 指过去,图片在解码完成前是空的:网盘那边一格要几百毫秒,
+ 430 毫秒一跳的节奏下,看到的是一连串黑白闪烁。慢的时候少跳一格,比跳
+ 过去闪一下好。取图失败也要把闸放开,否则一次 404 之后这张卡再也不动。
+ """
+ self.assertPageContains("if(!layer||loading)return;")
+ self.assertPageContains("pre.onload=()=>{if(layer){layer.src=pre.src;i=next}loading=false}")
+ self.assertPageContains("pre.onerror=()=>{loading=false}")
+
def test_detail_close_returns_to_the_collection_that_opened_it(self):
self.assertPageContains("detailReturnPath='/'")
self.assertPageContains("if(push)detailReturnPath=location.pathname+location.search")
diff --git a/web/app.js b/web/app.js
index 6fe0b8427..f76dd00e1 100644
--- a/web/app.js
+++ b/web/app.js
@@ -2314,7 +2314,7 @@ function wireHover(el,it){
这一层用 contain 加黑底:大图版式的容器是 0.75 的竖比例,16:9 的接触印相格子
在里面居中、上下留黑,和本地视频的 `.hv` 同一个口径。 */
if(!it.has_thumb)return; // 没有接触印相就没有可扫的格子
- let t=null,i=4,layer=null;
+ let t=null,i=4,layer=null,loading=false;
el.addEventListener('mouseenter',()=>{
if(selectMode||censorOn())return;armLong();
if(!layer){
@@ -2324,7 +2324,13 @@ function wireHover(el,it){
pic.appendChild(layer);
}
clearInterval(t);
- t=setInterval(()=>{i=(i+1)%9;layer.src=`/poster?id=${it.id}&c=${i}`},430);
+ t=setInterval(()=>{
+ if(!layer||loading)return;
+ const next=(i+1)%9, pre=new Image(); loading=true;
+ pre.onload=()=>{if(layer){layer.src=pre.src;i=next}loading=false};
+ pre.onerror=()=>{loading=false};
+ pre.src=`/poster?id=${it.id}&c=${next}`;
+ },430);
});
const stop=()=>{clearLong();clearInterval(t);t=null;
if(layer){layer.remove();layer=null}i=4};