打开/关闭菜单
60
73
29
1.1K
武外梗百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第24行: 第24行:
function fillExcerpts() {
function fillExcerpts() {
     document.querySelectorAll('.page-excerpt').forEach(div => {
     document.querySelectorAll('.page-excerpt').forEach(div => {
         let title = div.dataset.title;
         const title = div.dataset.title;
         let length = parseInt(div.dataset.length) || 200;
         const length = parseInt(div.dataset.length) || 200;


        // 调用标准 MediaWiki API 获取 extracts
         const url = '/api.php?action=query&prop=extracts&exchars=' + length + '&explaintext=1&titles=' + encodeURIComponent(title) + '&format=json';
         const url = '/api.php?action=query&prop=extracts&exchars=' + length + '&explaintext=1&titles=' + encodeURIComponent(title) + '&format=json';


第33行: 第32行:
             .then(resp => resp.json())
             .then(resp => resp.json())
             .then(data => {
             .then(data => {
                 if (!data.query || !data.query.pages) return;
                 const pages = data.query.pages;
 
                let pages = data.query.pages;
                 let text = '';
                 let text = '';
                 for (let pageId in pages) {
                 for (let pageId in pages) {
                     if (pages.hasOwnProperty(pageId)) {
                     if (pages.hasOwnProperty(pageId)) {
                         text = pages[pageId].extract || '';
                         text = pages[pageId].extract || '';
                         break; // 取第一个页面
                         break;
                     }
                     }
                 }
                 }
 
                 div.textContent = text;
                 div.textContent = text || '';
             })
             })
             .catch(err => {
             .catch(err => {
第53行: 第49行:
}
}


// 页面加载完成后执行
// 确保模板渲染后再执行
document.addEventListener('DOMContentLoaded', fillExcerpts);
mw.hook('wikipage.content').add(function() {
    fillExcerpts();
});

2025年12月14日 (日) 16:20的版本

//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 fillExcerpts() {
    document.querySelectorAll('.page-excerpt').forEach(div => {
        const title = div.dataset.title;
        const length = parseInt(div.dataset.length) || 200;

        const url = '/api.php?action=query&prop=extracts&exchars=' + length + '&explaintext=1&titles=' + encodeURIComponent(title) + '&format=json';

        fetch(url)
            .then(resp => resp.json())
            .then(data => {
                const pages = data.query.pages;
                let text = '';
                for (let pageId in pages) {
                    if (pages.hasOwnProperty(pageId)) {
                        text = pages[pageId].extract || '';
                        break;
                    }
                }
                div.textContent = text;
            })
            .catch(err => {
                console.error('Failed to fetch excerpt:', err);
                div.textContent = '';
            });
    });
}

// 确保模板渲染后再执行
mw.hook('wikipage.content').add(function() {
    fillExcerpts();
});