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

MediaWiki:Common.js:修订间差异

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


//页面摘要功能
//页面摘要功能
console.log('COMMON.JS LOADED');
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {
     console.log('wikipage.content triggered');
     console.log('wikipage.content triggered');
第40行: 第38行:
         if (!excerptDiv) return;
         if (!excerptDiv) return;


         // REST API(和维基百科一致)
         // API 地址(extracts + pageimages)
         var url = '/rest.php/v1/page/summary/' + encodeURIComponent(title);
         var url = '/api.php?action=query' +
                  '&titles=' + encodeURIComponent(title) +
                  '&prop=extracts|pageimages' +
                  '&exchars=' + (card.dataset.length || 200) +
                  '&explaintext=1' +
                  '&piprop=thumbnail&pithumbsize=300&format=json';


         fetch(url)
         fetch(url)
             .then(function (res) {
             .then(function (res) {
                 if (!res.ok) throw new Error('HTTP ' + res.status);
                 if (!res.ok) throw new Error('HTTP ' + res.status + ': ' + res.statusText);
                 return res.json();
                 return res.json();
             })
             })
             .then(function (data) {
             .then(function (data) {
                if (!data.query || !data.query.pages) throw new Error('No pages in response');


                 /* ===== 摘要 ===== */
                 for (var id in data.query.pages) {
                if (data.extract) {
                    if (data.query.pages.hasOwnProperty(id)) {
                    excerptDiv.textContent = data.extract;
                        var page = data.query.pages[id];
                } else {
 
                    excerptDiv.textContent = '(无摘要)';
                        // 摘要
                }
                        excerptDiv.textContent = page.extract || '(无摘要)';
 
                        // 概述图
                        if (imageDiv && page.thumbnail && page.thumbnail.source) {
                            imageDiv.innerHTML = '<img src="' + page.thumbnail.source + '" alt="概述图">';
                        }


                /* ===== 概述图 ===== */
                        break; // 只取第一个页面
                if (
                     }
                     imageDiv &&
                    data.thumbnail &&
                    data.thumbnail.source
                ) {
                    imageDiv.innerHTML =
                        '<img src="' +
                        data.thumbnail.source +
                        '" alt="概述图">';
                 }
                 }
             })
             })
             .catch(function (err) {
             .catch(function (err) {
                 console.warn('Summary load failed:', title, err);
                 console.error('Failed to fetch summary for', title, err);
                 excerptDiv.textContent = '(加载失败)';
                 excerptDiv.textContent = '(加载失败)';
             });
             });