MediaWiki:Common.js
MediaWiki界面页面
更多操作
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
//Microsoft 和 Google 分析
document.head.insertAdjacentHTML('beforeend',`
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-GVZPTSXG1H"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-GVZPTSXG1H');
</script>
`);
document.head.insertAdjacentHTML('beforeend',`
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "uewoetn0au");
</script>
`);
//页面摘要功能
function fillExcerptsPopupLogic() {
document.querySelectorAll('.page-excerpt-popup').forEach(div => {
let title = div.dataset.title;
let length = parseInt(div.dataset.length) || 200;
// 调用 MediaWiki REST API page/summary
fetch('/api/rest_v1/page/summary/' + encodeURIComponent(title))
.then(resp => resp.json())
.then(data => {
let text = data.extract || '';
// 去掉换行和多余空格
text = text.replace(/\s+/g, ' ').trim();
// 截取长度
if (text.length > length) {
text = text.slice(0, length) + '…';
}
div.textContent = text;
})
.catch(err => {
console.error('Failed to fetch excerpt:', err);
div.textContent = '';
});
});
}
document.addEventListener('DOMContentLoaded', fillExcerptsPopupLogic);