MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第28行: | 第28行: | ||
const length = parseInt(div.dataset.length) || 200; | const length = parseInt(div.dataset.length) || 200; | ||
const url = '/api.php?action=query&prop=extracts&exchars=' + length + | |||
const url = '/api.php?action=query&prop=extracts&exchars=' + length + '&titles=' | '&titles=' + encodeURIComponent(title) + '&format=json'; | ||
fetch(url) | fetch(url) | ||
| 第43行: | 第42行: | ||
} | } | ||
} | } | ||
// | |||
// 去掉纯换行符,但保留 HTML <a> 标签(Wiki 内链会自动转换成 <a>) | |||
// 先替换 \n 但不影响 HTML 标签 | |||
text = text.replace(/[\r\n]+/g, ' '); | |||
div.innerHTML = text; | div.innerHTML = text; | ||
div.dataset.filled = '1'; | div.dataset.filled = '1'; | ||
| 第54行: | 第57行: | ||
} | } | ||
// | // 监控异步渲染 | ||
const observer = new MutationObserver(() => fillExcerpts()); | const observer = new MutationObserver(() => fillExcerpts()); | ||
observer.observe(document.body, { childList: true, subtree: true }); | observer.observe(document.body, { childList: true, subtree: true }); | ||