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

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第25行: 第25行:


mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {
    console.log('wikipage.content triggered');


     var cards = document.querySelectorAll('.page-card');
     var cards = document.querySelectorAll('.page-card');
     for (var i = 0; i < cards.length; i++) {
     for (var i = 0; i < cards.length; i++) {
        var card = cards[i];
        if (card.getAttribute('data-done')) continue;


         var title = card.getAttribute('data-title');
         (function (card) {
        var div = card.querySelector('.page-excerpt');
            if (card.getAttribute('data-done')) return;
        if (!div || !title) continue;


        var url = '/api.php?action=query&prop=extracts&exchars=200&explaintext=1'
            var title = card.getAttribute('data-title');
            var div = card.querySelector('.page-excerpt');
            if (!div || !title) return;
 
            var url = '/api.php?action=query&prop=extracts&exchars=200&explaintext=1'
                 + '&titles=' + encodeURIComponent(title)
                 + '&titles=' + encodeURIComponent(title)
                 + '&format=json';
                 + '&format=json';


        fetch(url)
            fetch(url)
            .then(function (r) { return r.json(); })
                .then(function (r) { return r.json(); })
            .then(function (data) {
                .then(function (data) {
                if (!data.query || !data.query.pages) return;
                    if (!data.query || !data.query.pages) return;
                for (var id in data.query.pages) {
                    for (var id in data.query.pages) {
                    if (data.query.pages.hasOwnProperty(id)) {
                        if (data.query.pages.hasOwnProperty(id)) {
                        div.textContent = data.query.pages[id].extract || '(无摘要)';
                            div.textContent = data.query.pages[id].extract || '(无摘要)';
                        break;
                            break;
                        }
                     }
                     }
                 }
                 });
             });
 
             card.setAttribute('data-done', '1');
 
        })(cards[i]); // 👈 关键:立即执行函数,锁住 card/div


        card.setAttribute('data-done', '1');
     }
     }
});
});

2025年12月14日 (日) 21:23的版本

//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>
`);

//页面摘要功能
console.log('COMMON.JS LOADED');

mw.hook('wikipage.content').add(function () {

    var cards = document.querySelectorAll('.page-card');
    for (var i = 0; i < cards.length; i++) {

        (function (card) {
            if (card.getAttribute('data-done')) return;

            var title = card.getAttribute('data-title');
            var div = card.querySelector('.page-excerpt');
            if (!div || !title) return;

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

            fetch(url)
                .then(function (r) { return r.json(); })
                .then(function (data) {
                    if (!data.query || !data.query.pages) return;
                    for (var id in data.query.pages) {
                        if (data.query.pages.hasOwnProperty(id)) {
                            div.textContent = data.query.pages[id].extract || '(无摘要)';
                            break;
                        }
                    }
                });

            card.setAttribute('data-done', '1');

        })(cards[i]); // 👈 关键:立即执行函数,锁住 card/div

    }
});