MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第25行: | 第25行: | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
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++) { | ||
(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) | + '&titles=' + encodeURIComponent(title) | ||
+ '&format=json'; | + '&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 | |||
} | } | ||
}); | }); | ||
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
}
});