MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第24行: | 第24行: | ||
`); | `); | ||
mw.loader.using( ['mediawiki.util', 'mediawiki.api'] | mw.loader.using(['mediawiki.util', 'mediawiki.api']).then(function () { | ||
$(function () { | |||
$( function () { | var $el = $('#wiki-wordcount-number'); | ||
var $el = $( '#wiki-wordcount-number' ); | if (!$el.length) return; | ||
if ( !$el.length ) return; | |||
new mw.Api().get( { | new mw.Api().get({ | ||
action: 'query', | action: 'query', | ||
meta: 'siteinfo', | meta: 'siteinfo', | ||
siprop: 'statistics', | siprop: 'statistics', | ||
format: 'json' | format: 'json' | ||
} ).done( function ( data ) { | }).done(function (data) { | ||
var total = (data.query.statistics['cirrussearch-article-words'] || 0); | |||
return; | // 缓动动画实现 | ||
var start = 0, duration = 1800; | |||
var startTime = null; | |||
function easeOutQuad(t) { | |||
return t * (2 - t); | |||
} | } | ||
function animateCount(timestamp) { | |||
if (!startTime) startTime = timestamp; | |||
var timeElapsed = timestamp - startTime; | |||
var progress = Math.min(timeElapsed / duration, 1); | |||
var eased = easeOutQuad(progress); | |||
var current = Math.floor(eased * total); | |||
current | $el.text(current.toLocaleString()); | ||
if ( | |||
// 触发“放大”样式 | |||
if (progress < 1) { | |||
$el.addClass('animating'); | |||
requestAnimationFrame(animateCount); | |||
} else { | |||
$el.removeClass('animating'); | |||
} | } | ||
} | |||
} ).fail( function ( | requestAnimationFrame(animateCount); | ||
console.error( '字数统计 API 请求失败' | }).fail(function () { | ||
} ); | console.error('字数统计 API 请求失败'); | ||
} ); | }); | ||
} ); | }); | ||
}); | |||
2026年1月17日 (六) 16:28的版本
//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;
new mw.Api().get({
action: 'query',
meta: 'siteinfo',
siprop: 'statistics',
format: 'json'
}).done(function (data) {
var total = (data.query.statistics['cirrussearch-article-words'] || 0);
// 缓动动画实现
var start = 0, duration = 1800;
var startTime = null;
function easeOutQuad(t) {
return t * (2 - t);
}
function animateCount(timestamp) {
if (!startTime) startTime = timestamp;
var timeElapsed = timestamp - startTime;
var progress = Math.min(timeElapsed / duration, 1);
var eased = easeOutQuad(progress);
var current = Math.floor(eased * total);
$el.text(current.toLocaleString());
// 触发“放大”样式
if (progress < 1) {
$el.addClass('animating');
requestAnimationFrame(animateCount);
} else {
$el.removeClass('animating');
}
}
requestAnimationFrame(animateCount);
}).fail(function () {
console.error('字数统计 API 请求失败');
});
});
});