MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第24行: | 第24行: | ||
function fillExcerpts() { | function fillExcerpts() { | ||
document.querySelectorAll('.page-excerpt').forEach(div => { | document.querySelectorAll('.page-excerpt').forEach(div => { | ||
if (div.dataset.filled) return; // 避免重复填充 | |||
const title = div.dataset.title; | const title = div.dataset.title; | ||
const length = parseInt(div.dataset.length) || 200; | const length = parseInt(div.dataset.length) || 200; | ||
| 第41行: | 第42行: | ||
} | } | ||
div.textContent = text; | div.textContent = text; | ||
div.dataset.filled = '1'; | |||
}) | }) | ||
.catch(err => { | .catch(err => { | ||
| 第49行: | 第51行: | ||
} | } | ||
// | // MutationObserver 监控页面内容变化,兼容 PWA / 异步渲染 | ||
const observer = new MutationObserver(() => fillExcerpts()); | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
// 页面首次加载也执行一次 | |||
document.addEventListener('DOMContentLoaded', fillExcerpts); | |||