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

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
 
(未显示同一用户的22个中间版本)
第11行: 第11行:
</script>
</script>
`);
`);
document.head.insertAdjacentHTML('beforeend',`a
document.head.insertAdjacentHTML('beforeend',`
<script type="text/javascript">
<script type="text/javascript">
     (function(c,l,a,r,i,t,y){
     (function(c,l,a,r,i,t,y){
第20行: 第20行:
</script>
</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 配置
function fillPageCards() {
        var observer = new IntersectionObserver(function(entries) {
    document.querySelectorAll('.page-card').forEach(card => {
            entries.forEach(function(entry) {
        if (card.dataset.filled) return;
                if (entry.isIntersecting && !triggered) {
        const title = card.dataset.title;
                    triggered = true;
         const length = parseInt(card.dataset.length) || 200;
                    startCountAnimation();
                    observer.unobserve(entry.target);
                }
            });
         }, {
            root: null,      // 视口为浏览器窗口
            rootMargin: "0px",
            threshold: 0.3  // 至少 30% 可见才触发
        });


         const excerptDiv = card.querySelector('.page-excerpt');
         // 观察目标元素
        const imgDiv = card.querySelector('.page-card-image');
        observer.observe(document.getElementById('wiki-wordcount-number'));


         // --- 1. 获取摘要 ---
         // 真正执行字数滚动动画
         const excerptUrl = '/api.php?action=query&prop=extracts&exchars=' + length +
         function startCountAnimation() {
                          '&titles=' + encodeURIComponent(title) + '&format=json&explaintext=0';
            new mw.Api().get({
        fetch(excerptUrl)
                action: 'wordcounter',
            .then(r => r.json())
                prop: 'totals',
            .then(data => {
                format: 'json'
                 const pages = data.query.pages;
            }).done(function (data) {
                 let html = '';
                 // --- 修改点:适配您的 API 返回结构 ---
                 for (let pageId in pages) {
                 var total = 0;
                    if (pages.hasOwnProperty(pageId)) {
                 if (data && data.wordcounter && data.wordcounter.totals) {
                        html = pages[pageId].extract || '';
                    total = data.wordcounter.totals.totalWords || 0;
                        break;
                    }
                 }
                 }


                 const temp = document.createElement('div');
                 // 缓动函数(前快后慢)
                 temp.innerHTML = html;
                function easeOutQuad(t) {
                    return t * (2 - t);
                 }


                 // 保留 <a>,删除其他标签
                 var duration = 2000;
                temp.querySelectorAll('*').forEach(node => {
                 var startTime = null;
                    if (node.tagName !== 'A') {
                        node.replaceWith(document.createTextNode(node.textContent));
                    }
                 });


                 // 去掉换行
                 function animate(timestamp) {
                excerptDiv.innerHTML = temp.innerHTML.replace(/[\r\n]+/g, ' ');
                    if (!startTime) startTime = timestamp;
            })
                    var run = timestamp - startTime;
            .catch(err => console.error('Failed to fetch excerpt for', title, err));
                    var progress = Math.min(run / duration, 1);
                    var eased = easeOutQuad(progress);


        // --- 2. 获取第一张图片 ---
                    var currentVal = Math.floor(eased * total);
        const imagesUrl = '/api.php?action=query&titles=' + encodeURIComponent(title) +
                    $el.text(currentVal.toLocaleString());
                          '&prop=images&format=json';
        fetch(imagesUrl)
            .then(r => r.json())
            .then(data => {
                const pages = data.query.pages;
                for (let pageId in pages) {
                    if (pages.hasOwnProperty(pageId)) {
                        const images = pages[pageId].images || [];
                        if (images.length > 0) {
                            const firstImageTitle = images[0].title; // "File:xxx.jpg"


                            // 二次请求获取 URL
                    if (progress < 1) {
                            const imageInfoUrl = '/api.php?action=query&titles=' +
                        requestAnimationFrame(animate);
                                                encodeURIComponent(firstImageTitle) +
                                                '&prop=imageinfo&iiprop=url&format=json';
                            fetch(imageInfoUrl)
                                .then(r => r.json())
                                .then(imgData => {
                                    const imgPages = imgData.query.pages;
                                    for (let imgId in imgPages) {
                                        if (imgPages.hasOwnProperty(imgId)) {
                                            const url = imgPages[imgId].imageinfo?.[0]?.url;
                                            if (url) {
                                                const imgEl = document.createElement('img');
                                                imgEl.src = url;
                                                imgEl.alt = "概述图";
                                                imgDiv.appendChild(imgEl);
                                            }
                                        }
                                    }
                                });
                        }
                        break;
                     }
                     }
                 }
                 }
             })
                requestAnimationFrame(animate);
            .catch(err => console.error('Failed to fetch image for', title, err));
             }).fail(function () {
 
                console.error('字数统计 API 请求失败');
         card.dataset.filled = '1';
            });
         }
     });
     });
}
});
 
// 立即执行
fillPageCards();
 
// 监听 DOM 变化(可选)
const observer = new MutationObserver(fillPageCards);
observer.observe(document.body, { childList: true, subtree: true });
 
console.log('COMMON.JS LOADED');

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 请求失败');
            });
        }
    });
});