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

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
 
(未显示同一用户的18个中间版本)
第19行: 第19行:
     })(window, document, "clarity", "script", "uewoetn0au");
     })(window, document, "clarity", "script", "uewoetn0au");
</script>
</script>
`);
document.head.insertAdjacentHTML('beforeend',`
<meta name="baidu-site-verification" content="codeva-38vNyP0io6" />
`);
`);


//页面摘要功能
mw.loader.using(['mediawiki.util', 'mediawiki.api']).then(function () {
console.log('COMMON.JS LOADED');
    $(function () {
        var $el = $('#wiki-wordcount-number');
        if (!$el.length) return;


mw.hook('wikipage.content').add(function () {
        // 标记是否已触发过动画
    console.log('wikipage.content triggered');
        var triggered = false;


    var cards = document.querySelectorAll('.page-card');
        // IntersectionObserver 配置
        var observer = new IntersectionObserver(function(entries) {
            entries.forEach(function(entry) {
                if (entry.isIntersecting && !triggered) {
                    triggered = true;
                    startCountAnimation();
                    observer.unobserve(entry.target);
                }
            });
        }, {
            root: null,      // 视口为浏览器窗口
            rootMargin: "0px",
            threshold: 0.3  // 至少 30% 可见才触发
        });


    cards.forEach(function (card) {
        // 观察目标元素
         if (card.dataset.done === '1') return;
         observer.observe(document.getElementById('wiki-wordcount-number'));


         var title = card.dataset.title;
         // 真正执行字数滚动动画
        if (!title) return;
        function startCountAnimation() {
            new mw.Api().get({
                action: 'wordcounter',
                prop: 'totals',
                format: 'json'
            }).done(function (data) {
                // --- 修改点:适配您的 API 返回结构 ---
                var total = 0;
                if (data && data.wordcounter && data.wordcounter.totals) {
                    total = data.wordcounter.totals.totalWords || 0;
                }


        var excerptDiv = card.querySelector('.page-excerpt');
                // 缓动函数(前快后慢)
        var imageDiv  = card.querySelector('.page-card-image');
                function easeOutQuad(t) {
 
                    return t * (2 - t);
        if (!excerptDiv) return;
                }


        // REST API(和维基百科一致)
                var duration = 2000;
        var url = '/rest.php/v1/page/summary/' + encodeURIComponent(title);
                var startTime = null;


        fetch(url)
                function animate(timestamp) {
            .then(function (res) {
                    if (!startTime) startTime = timestamp;
                if (!res.ok) throw new Error('HTTP ' + res.status);
                    var run = timestamp - startTime;
                return res.json();
                    var progress = Math.min(run / duration, 1);
            })
                    var eased = easeOutQuad(progress);
            .then(function (data) {


                /* ===== 摘要 ===== */
                    var currentVal = Math.floor(eased * total);
                if (data.extract) {
                     $el.text(currentVal.toLocaleString());
                     excerptDiv.textContent = data.extract;
                } else {
                    excerptDiv.textContent = '(无摘要)';
                }


                /* ===== 概述图 ===== */
                    if (progress < 1) {
                if (
                         requestAnimationFrame(animate);
                    imageDiv &&
                    }
                    data.thumbnail &&
                    data.thumbnail.source
                ) {
                    imageDiv.innerHTML =
                         '<img src="' +
                        data.thumbnail.source +
                        '" alt="概述图">';
                 }
                 }
 
                requestAnimationFrame(animate);
             })
             }).fail(function () {
            .catch(function (err) {
                 console.error('字数统计 API 请求失败');
                 console.warn('Summary load failed:', title, err);
                excerptDiv.textContent = '(加载失败)';
             });
             });
 
         }
         card.dataset.done = '1';
     });
     });
});
});

2026年1月17日 (六) 17:49的最新版本

//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>
`);
document.head.insertAdjacentHTML('beforeend',`
<meta name="baidu-site-verification" content="codeva-38vNyP0io6" />
`);

mw.loader.using(['mediawiki.util', 'mediawiki.api']).then(function () {
    $(function () {
        var $el = $('#wiki-wordcount-number');
        if (!$el.length) return;

        // 标记是否已触发过动画
        var triggered = false;

        // IntersectionObserver 配置
        var observer = new IntersectionObserver(function(entries) {
            entries.forEach(function(entry) {
                if (entry.isIntersecting && !triggered) {
                    triggered = true;
                    startCountAnimation();
                    observer.unobserve(entry.target);
                }
            });
        }, {
            root: null,      // 视口为浏览器窗口
            rootMargin: "0px",
            threshold: 0.3   // 至少 30% 可见才触发
        });

        // 观察目标元素
        observer.observe(document.getElementById('wiki-wordcount-number'));

        // 真正执行字数滚动动画
        function startCountAnimation() {
            new mw.Api().get({
                action: 'wordcounter',
                prop: 'totals',
                format: 'json'
            }).done(function (data) {
                // --- 修改点:适配您的 API 返回结构 ---
                var total = 0;
                if (data && data.wordcounter && data.wordcounter.totals) {
                    total = data.wordcounter.totals.totalWords || 0;
                }

                // 缓动函数(前快后慢)
                function easeOutQuad(t) {
                    return t * (2 - t);
                }

                var duration = 2000;
                var startTime = null;

                function animate(timestamp) {
                    if (!startTime) startTime = timestamp;
                    var run = timestamp - startTime;
                    var progress = Math.min(run / duration, 1);
                    var eased = easeOutQuad(progress);

                    var currentVal = Math.floor(eased * total);
                    $el.text(currentVal.toLocaleString());

                    if (progress < 1) {
                        requestAnimationFrame(animate);
                    }
                }
                requestAnimationFrame(animate);
            }).fail(function () {
                console.error('字数统计 API 请求失败');
            });
        }
    });
});