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

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第11行: 第11行:
</script>
</script>
`);
`);
document.head.insertAdjacentHTML('beforeend',`
document.head.insertAdjacentHTML('beforeend',`a
<script type="text/javascript">
<script type="text/javascript">
     (function(c,l,a,r,i,t,y){
     (function(c,l,a,r,i,t,y){
第24行: 第24行:
function fillPageCards() {
function fillPageCards() {
     document.querySelectorAll('.page-card').forEach(card => {
     document.querySelectorAll('.page-card').forEach(card => {
        if (card.dataset.filled) return;
         const title = card.dataset.title;
         const title = card.dataset.title;
         if (!title || card.dataset.filled) return;
         const length = parseInt(card.dataset.length) || 200;


         const excerptDiv = card.querySelector('.page-excerpt');
         const excerptDiv = card.querySelector('.page-excerpt');
         const imgTag = card.querySelector('.page-card-image img');
         const imgTag = card.querySelector('.page-card-image img');


         // 1️⃣ 获取摘要
         // --- 1. 获取摘要 ---
         const excerptUrl = '/api.php?action=query&prop=extracts&exchars=200&titles=' +
         const excerptUrl = '/api.php?action=query&prop=extracts&exchars=' + length +
                          encodeURIComponent(title) + '&format=json';
                          '&titles=' + encodeURIComponent(title) + '&format=json&explaintext=0';
         fetch(excerptUrl)
         fetch(excerptUrl)
             .then(resp => resp.json())
             .then(r => r.json())
             .then(data => {
             .then(data => {
                 const pages = data.query.pages;
                 const pages = data.query.pages;
第48行: 第49行:
                 temp.innerHTML = html;
                 temp.innerHTML = html;


                 // 保留 <a>,删除其他标签
                 // 保留 <a>,去掉其他标签
                 temp.querySelectorAll('*').forEach(node => {
                 temp.querySelectorAll('*').forEach(node => {
                     if (node.tagName !== 'A') {
                     if (node.tagName !== 'A') {
第55行: 第56行:
                 });
                 });


                 let textWithLinks = temp.innerHTML.replace(/[\r\n]+/g, ' ');
                 // 去掉换行
                excerptDiv.innerHTML = textWithLinks;
                excerptDiv.innerHTML = temp.innerHTML.replace(/[\r\n]+/g, ' ');
             })
             })
             .catch(err => console.error('Failed to fetch excerpt:', title, err));
             .catch(err => console.error('Failed to fetch excerpt for', title, err));


         // 2️⃣ 获取第一张图片
         // --- 2. 获取第一张图片 ---
         const imageUrl = '/api.php?action=query&titles=' + encodeURIComponent(title) +
         const imagesUrl = '/api.php?action=query&titles=' + encodeURIComponent(title) +
                        '&prop=images&format=json';
                          '&prop=images&format=json';
         fetch(imageUrl)
         fetch(imagesUrl)
             .then(resp => resp.json())
             .then(r => r.json())
             .then(data => {
             .then(data => {
                 const pages = data.query.pages;
                 const pages = data.query.pages;
第73行: 第74行:
                             const firstImageTitle = images[0].title; // "File:xxx.jpg"
                             const firstImageTitle = images[0].title; // "File:xxx.jpg"


                             // 获取图片实际 URL
                             // 二次请求获取 URL
                             const imageInfoUrl = '/api.php?action=query&titles=' +
                             const imageInfoUrl = '/api.php?action=query&titles=' +
                                                 encodeURIComponent(firstImageTitle) +
                                                 encodeURIComponent(firstImageTitle) +
                                                 '&prop=imageinfo&iiprop=url&format=json';
                                                 '&prop=imageinfo&iiprop=url&format=json';
                             fetch(imageInfoUrl)
                             fetch(imageInfoUrl)
                                 .then(resp => resp.json())
                                 .then(r => r.json())
                                 .then(imgData => {
                                 .then(imgData => {
                                     const imgPages = imgData.query.pages;
                                     const imgPages = imgData.query.pages;
第93行: 第94行:
                 }
                 }
             })
             })
             .catch(err => console.error('Failed to fetch image:', title, err));
             .catch(err => console.error('Failed to fetch image for', title, err));


         card.dataset.filled = '1';
         card.dataset.filled = '1';
第101行: 第102行:
// 立即执行
// 立即执行
fillPageCards();
fillPageCards();
// 可选:监听后续 DOM 变化
const observer = new MutationObserver(fillPageCards);
observer.observe(document.body, { childList: true, subtree: true });