Widget:GF立绘切换:修订间差异
来自OGAS数据中枢
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
(function() { | (function() { | ||
function initSwitcher() { | function initSwitcher() { | ||
| 第5行: | 第4行: | ||
if (box.dataset.switcherReady) return; | if (box.dataset.switcherReady) return; | ||
box.dataset.switcherReady = 'true'; | box.dataset.switcherReady = 'true'; | ||
var container = box.querySelector('.gf-image-container'); | var container = box.querySelector('.gf-image-container'); | ||
var thumbItems = box.querySelectorAll('.gf-thumb-item'); | var thumbItems = box.querySelectorAll('.gf-thumb-item'); | ||
if (!container || thumbItems.length < 2) return; | if (!container || thumbItems.length < 2) return; | ||
thumbItems.forEach(function(item) { | thumbItems.forEach(function(item) { | ||
item.addEventListener('click', function( | item.addEventListener('click', function() { | ||
if (this.classList.contains('active')) return; | if (this.classList.contains('active')) return; | ||
var | // 直接从 data-fullsrc 读取 filepath: 生成的完整URL | ||
if ( | var newSrc = this.dataset.fullsrc; | ||
if (!newSrc) return; | |||
// 淡出 | |||
var oldImg = container.querySelector('img, a img'); | |||
if (oldImg) { | |||
oldImg.style.transition = 'opacity 0.15s ease'; | |||
oldImg.style.opacity = '0'; | |||
} | } | ||
setTimeout(function() { | |||
// 用 <img> 替换原先的wiki File语法渲染结果(<a><img></a>) | |||
container.innerHTML = '<img src="' + newSrc + '" style="max-width:100%;max-height:420px;object-fit:contain;transition:opacity 0.3s ease;opacity:0;">'; | |||
var newImg = container.querySelector('img'); | |||
if (newImg) { | |||
requestAnimationFrame(function() { | |||
// | newImg.style.opacity = '1'; | ||
}); | |||
var | |||
if ( | |||
} | } | ||
}, 150); | |||
thumbItems.forEach(function(t) { t.classList.remove('active'); }); | |||
item.classList.add('active'); | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
} | } | ||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', initSwitcher); | document.addEventListener('DOMContentLoaded', initSwitcher); | ||
| 第97行: | 第48行: | ||
initSwitcher(); | initSwitcher(); | ||
} | } | ||
if (window.mw && mw.hook) { | if (window.mw && mw.hook) { | ||
mw.hook('wikipage.content').add(initSwitcher); | mw.hook('wikipage.content').add(initSwitcher); | ||
} | } | ||
})(); | })(); | ||
2026年5月15日 (五) 20:47的版本
(function() {
function initSwitcher() {
document.querySelectorAll('.gf-infobox-new').forEach(function(box) {
if (box.dataset.switcherReady) return;
box.dataset.switcherReady = 'true';
var container = box.querySelector('.gf-image-container');
var thumbItems = box.querySelectorAll('.gf-thumb-item');
if (!container || thumbItems.length < 2) return;
thumbItems.forEach(function(item) {
item.addEventListener('click', function() {
if (this.classList.contains('active')) return;
// 直接从 data-fullsrc 读取 filepath: 生成的完整URL
var newSrc = this.dataset.fullsrc;
if (!newSrc) return;
// 淡出
var oldImg = container.querySelector('img, a img');
if (oldImg) {
oldImg.style.transition = 'opacity 0.15s ease';
oldImg.style.opacity = '0';
}
setTimeout(function() {
// 用 <img> 替换原先的wiki File语法渲染结果(<a><img></a>)
container.innerHTML = '<img src="' + newSrc + '" style="max-width:100%;max-height:420px;object-fit:contain;transition:opacity 0.3s ease;opacity:0;">';
var newImg = container.querySelector('img');
if (newImg) {
requestAnimationFrame(function() {
newImg.style.opacity = '1';
});
}
}, 150);
thumbItems.forEach(function(t) { t.classList.remove('active'); });
item.classList.add('active');
});
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initSwitcher);
} else {
initSwitcher();
}
if (window.mw && mw.hook) {
mw.hook('wikipage.content').add(initSwitcher);
}
})();