利用者:Atmark-chan/custom/revisionCounter.js
表示
お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。
多くの Windows や Linux のブラウザ
- Ctrl を押しながら F5 を押す。
Mac における Safari
Mac における Chrome や Firefox
- ⌘ Cmd と ⇧ Shift を押しながら R を押す。
詳細についてはWikipedia:キャッシュを消すをご覧ください。
//===========================================================================
// [[de:MediaWiki:Gadget-revisionCounter.js]] [[de:special:permalink/145008152|ID 145008152 版]]を一部改変
//===========================================================================
if (mw.config.get('wgNamespaceNumber') >= 0) {
$( function() {
if ( mw.config.get( 'revisionCounter.checkOnlyOnHistory', true ) && mw.config.get('wgAction') !== "history" ) {
return;
}
var api = new mw.Api;
var revisionCount = 0, revisionCountUser = 0;
var queryParams = {
action: 'query',
prop: 'revisions',
pageids: mw.config.get('wgArticleId'),
rvprop: 'user',
rvlimit: 'max',
requestid: mw.config.get('wgCurRevisionId') //Break client caching, when page has been edited
};
var doQuery = function( api, queryParams, continueParams ) {
api.get(
$.extend( {}, queryParams, continueParams || { 'continue': '' } )
).then( function( data ) {
queryResult( api, data );
} ).fail( function( code, data ) {
var extraText;
if ( code === 'http' && data ) {
extraText = ( data.xhr && data.xhr.status ? '[' + data.xhr.status + ']' : '' )
+ ( data.textStatus ? '' + data.textStatus + ( data.exception ? ': ' : '' ) : '' )
+ ( data.exception ? '' + data.exception : '' );
} else {
extraText = code + ( data && data.error && data.error.info ? ': ' + data.error.info : '' );
}
mw.notify(
'RevisionCounter: Fehler beim Ermitteln der Anzahl an Versionen' +
' (' + extraText + ')',
{ tag: 'revisionCounter-error' }
);
} );
};
doQuery( api, queryParams );
var queryResult = function( api, res)
{
var pageId = mw.config.get('wgArticleId');
if (!res['query'] || !res['query']['pages'] ||
!res['query']['pages'][pageId] || !res['query']['pages'][pageId]['revisions']) return;
var revs = res['query']['pages'][pageId]['revisions'];
revisionCount += revs.length;
var username = mw.config.get( 'wgUserName' );
for (var i = 0; i < revs.length; i++)
if (revs[i]['user'] === username) revisionCountUser++;
revisionPercent = Math.round(revisionCountUser / revisionCount * 100 * 100) / 100;
addStr = "(" + revisionCountUser + "/" + revisionCount + ", " + revisionPercent + "%)";
if (res && res['continue'])
{
doQuery( api, queryParams, res['continue'] );
}
else
{
var selector;
if (mw.config.get('skin') === 'minerva')
{
selector = "#section_0";
addStr = ' <span style="font-size:80%">' + addStr + "</span>";
}
else
{
selector = "#ca-history a";
addStr = " <small>" + addStr + "</small>";
}
$(selector).html(function(index, curText) {
return curText + addStr;
});
}
};
});
}