From fb654844bfaa80134d25d23e6393825f1b05ef67 Mon Sep 17 00:00:00 2001 From: qiqi Date: Fri, 20 Nov 2026 12:19:13 +0800 Subject: [PATCH] =?UTF-8?q?chore(plugin):=20=E5=90=8C=E6=AD=A5=20gallery?= =?UTF-8?q?=201.3.0=20=E4=BA=A7=E7=89=A9=EF=BC=88=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=20+=20=E5=88=B7=E6=96=B0=E6=8C=89=E9=92=AE?= =?UTF-8?q?=20+=20=E5=9D=8F=E5=9B=BE=E4=BF=9D=E6=8A=A4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/index.json | 6 ++-- ...aeb3.js => plugin-gallery.4d7d2d5d9875.js} | 31 +++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) rename plugins/runtime/{plugin-gallery.e9559022aeb3.js => plugin-gallery.4d7d2d5d9875.js} (87%) diff --git a/plugins/index.json b/plugins/index.json index 7c59b73..7a06de4 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -19,9 +19,9 @@ }, { "id": "gallery", - "file": "plugin-gallery.e9559022aeb3.js", - "version": "1.2.1", - "integrity": "sha256-6VWQIq6zXcayLwbA6OVXNxKCMeVdfjeTk1RdFK3UtII=" + "file": "plugin-gallery.4d7d2d5d9875.js", + "version": "1.3.0", + "integrity": "sha256-TX0tXZh1XchHl+UHYZbR1+yOgENgXPBOggYFTOBq84M=" }, { "id": "image-annotate", diff --git a/plugins/runtime/plugin-gallery.e9559022aeb3.js b/plugins/runtime/plugin-gallery.4d7d2d5d9875.js similarity index 87% rename from plugins/runtime/plugin-gallery.e9559022aeb3.js rename to plugins/runtime/plugin-gallery.4d7d2d5d9875.js index 371c7e1..8f2fbb5 100644 --- a/plugins/runtime/plugin-gallery.e9559022aeb3.js +++ b/plugins/runtime/plugin-gallery.4d7d2d5d9875.js @@ -70,9 +70,11 @@ var countEl = el('span', { class: 'iwb-gal-count', text: '0 / 0 张' }) var pickedEl = el('span', { class: 'iwb-gal-sel', text: '' }) var statusEl = el('span', { class: 'iwb-gal-status', text: '' }) + var refreshBtn = el('button', { class: 'iwb-btn iwb-btn-sm', text: '刷新', title: '重新向宿主拉取图库(图床恢复/外部改动后点这里)' }) + refreshBtn.addEventListener('click', function () { load(true) }) var opts = el('div', { class: 'iwb-gal-opts' }) var foot = el('div', { class: 'iwb-gal-foot' }, - el('div', { class: 'iwb-gal-foot-left' }, countEl, pickedEl, statusEl), opts) + el('div', { class: 'iwb-gal-foot-left' }, countEl, pickedEl, statusEl, refreshBtn), opts) var wrap = el('div', { class: 'iwb-history-embedded' }, [head, grid, more, empty, foot]) host.appendChild(wrap) @@ -174,6 +176,8 @@ var img = el('img', { src: url, alt: '', loading: 'lazy', draggable: 'true' }) if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h) img.addEventListener('load', function () { + // naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块 + if (!img.naturalWidth) { tries++; if (tries <= 2) { setTimeout(boot, 400 * tries); return } if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)'); return } if (holder.parentNode === box) box.replaceChild(img, holder) }) img.addEventListener('error', function () { @@ -195,6 +199,7 @@ box.appendChild(img) // 加载成功后再替换占位(避免破图标 + 长 title 占满格子) if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) } + else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } } }).catch(function () { fail('缩略图加载失败(点击重试)') }) } boot() @@ -233,10 +238,12 @@ function render () { renderHead(); renderGrid() } - function load () { + function load (force) { + if (force) setStatus('刷新中…') return Promise.resolve(ctx.gallery.list({ range: cfg.range, limit: limit })).then(function (r) { items = (r && r.items) || [] total = (r && r.total) || items.length + lastLoadAt = Date.now() render() }).catch(function () { items = []; total = 0; render() }) } @@ -258,6 +265,24 @@ if (ro) ro.observe(grid) measure() + // v1.3.0:自动恢复 —— 面板重新可见(切回 tab / 窗口聚焦 / 后台回来)且距上次拉取 >5s 时重拉一次, + // 这样图床恢复、后台补图后不必手动刷新;同时保留底部「刷新」按钮做即时重试。 + var lastLoadAt = 0 + var autoRefresh = function () { + if (Date.now() - lastLoadAt < 5000) return + load() + } + try { + if (typeof IntersectionObserver === 'function') { + var io = new IntersectionObserver(function (entries) { + for (var i = 0; i < entries.length; i++) if (entries[i].isIntersecting) autoRefresh() + }, { threshold: 0.15 }) + io.observe(wrap) + } + document.addEventListener('visibilitychange', function () { if (!document.hidden) autoRefresh() }) + window.addEventListener('focus', autoRefresh) + } catch (e) { /* 环境不支持则只保留手动刷新 */ } + // 先读配置,再拉列表 Promise.resolve(ctx.data && ctx.data.read ? ctx.data.read() : {}).then(function (d) { if (d && d.cfg) cfg = Object.assign({}, DEF, d.cfg) @@ -271,7 +296,7 @@ global.IWBPluginHost.register({ id: 'gallery', name: '图库', - version: '1.2.1', + version: '1.3.0', apiVersion: 1, capabilities: ['panels', 'gallery'], data: { schemaVersion: 1, maxBytes: 65536 },