편집 요약 없음 |
편집 요약 없음 |
||
| 1번째 줄: | 1번째 줄: | ||
$ | $( function () { | ||
'use strict'; | |||
var articleNamespaces, talkNamespaces, isArticleTab, limit; | |||
articleNamespaces = $( '.live-recent' ).attr( 'data-article-ns' ); | |||
talkNamespaces = $( '.live-recent' ).attr( 'data-talk-ns' ); | |||
isArticleTab = true; | |||
limit = $( '#live-recent-list' )[ 0 ].childElementCount; | |||
function timeFormat( timestamp ) { | |||
var now = new Date(); | |||
var time = new Date( timestamp ); | |||
var diffInSeconds = Math.floor((now - time) / 1000); | |||
var diffInMinutes = Math.floor(diffInSeconds / 60); | |||
var diffInHours = Math.floor(diffInMinutes / 60); | |||
var diffInDays = Math.floor(diffInHours / 24); | |||
if (diffInSeconds < 60) { | |||
return diffInSeconds + '珥� ��'; | |||
} else if (diffInMinutes < 60) { | |||
return diffInMinutes + '遺� ��'; | |||
} else if (diffInHours < 24) { | |||
}); | return diffInHours + '�쒓컙 ��'; | ||
} else { | |||
return diffInDays + '�� ��'; | |||
} | |||
} | |||
function refreshLiveRecent() { | |||
var getParameter; | |||
if ( !$( '#live-recent-list' ).length || $( '#live-recent-list' ).is( ':hidden' ) ) { | |||
return; | |||
} | |||
getParameter = { | |||
action: 'query', | |||
list: 'recentchanges', | |||
rcprop: 'title|timestamp', | |||
rcshow: '!bot|!redirect', | |||
rctype: 'edit|new', | |||
rclimit: limit, | |||
format: 'json', | |||
rcnamespace: isArticleTab ? articleNamespaces : talkNamespaces, | |||
rctoponly: true | |||
}; | |||
mw.loader.using( 'mediawiki.api' ).then( function () { | |||
var api = new mw.Api(); | |||
api.get( getParameter ).then( function ( data ) { | |||
var recentChanges, html, time, line, text; | |||
recentChanges = data.query.recentchanges; | |||
function cutTitle(title, maxLength) { | |||
let length = 0; | |||
let cutOffIndex = title.length; | |||
for (let i = 0; i < title.length; i++) { | |||
// �곸뼱 �뚰뙆踰녠낵 �レ옄, 怨듬갚�� 1濡� 移댁슫��, 洹� �몃� 2濡� 移댁슫�� | |||
length += title.charCodeAt(i) > 127 ? 2 : 1; | |||
if (length > maxLength) { | |||
cutOffIndex = i; | |||
break; | |||
} | |||
} | |||
// �꾩슂�� 寃쎌슦 "..."�� 異붽� | |||
return title.length > cutOffIndex ? title.slice(0, cutOffIndex) + "..." : title; | |||
} | |||
// �댄썑, �� �⑥닔瑜� �ъ슜�� �쒕ぉ�� 泥섎━ | |||
html = recentChanges.map(function (item) { | |||
time = new Date(item.timestamp); | |||
// cutTitle �⑥닔瑜� �ъ슜�� �쒕ぉ 泥섎━ | |||
var title = cutTitle(item.title, 30); | |||
// �쒕ぉ怨� �쒓컙�� <div>濡� 媛먯떥 媛곴컖 block �붿냼濡� 留뚮뱾�� 以꾨컮轅� �④낵瑜� 以띾땲��. | |||
line = '<li>'; | |||
line += '<a class="recent-item" href="' + mw.util.getUrl(item.title) + '" title="' + item.title + '">'; | |||
line += '<div class="item-title">' + title + '</div>'; // �섏젙�� �쒕ぉ�� �ъ슜 | |||
line += '<div class="item-time">' + timeFormat(time) + '</div>'; // �쒓컙�� �꾪븳 <div> | |||
line += '</a>'; | |||
line += '</li>'; | |||
return line; | |||
}).join('\n'); | |||
$( '#live-recent-list' ).html( html ); | |||
} ) | |||
.catch( function () {} ); | |||
}); | |||
} | |||
$( '#liberty-recent-tab1' ).click( function () { | |||
$( this ).addClass( 'active' ); | |||
$( '#liberty-recent-tab2' ).removeClass( 'active' ); | |||
isArticleTab = true; | |||
refreshLiveRecent(); | |||
} ); | |||
$( '#liberty-recent-tab2' ).click( function () { | |||
$( this ).addClass( 'active' ); | |||
$( '#liberty-recent-tab1' ).removeClass( 'active' ); | |||
isArticleTab = false; | |||
refreshLiveRecent(); | |||
} ); | |||
setInterval( refreshLiveRecent, 5 * 60 * 1000 ); | |||
refreshLiveRecent(); | |||
} ); | |||
2025년 1월 13일 (월) 16:22 판
$( function () {
'use strict';
var articleNamespaces, talkNamespaces, isArticleTab, limit;
articleNamespaces = $( '.live-recent' ).attr( 'data-article-ns' );
talkNamespaces = $( '.live-recent' ).attr( 'data-talk-ns' );
isArticleTab = true;
limit = $( '#live-recent-list' )[ 0 ].childElementCount;
function timeFormat( timestamp ) {
var now = new Date();
var time = new Date( timestamp );
var diffInSeconds = Math.floor((now - time) / 1000);
var diffInMinutes = Math.floor(diffInSeconds / 60);
var diffInHours = Math.floor(diffInMinutes / 60);
var diffInDays = Math.floor(diffInHours / 24);
if (diffInSeconds < 60) {
return diffInSeconds + '珥� ��';
} else if (diffInMinutes < 60) {
return diffInMinutes + '遺� ��';
} else if (diffInHours < 24) {
return diffInHours + '�쒓컙 ��';
} else {
return diffInDays + '�� ��';
}
}
function refreshLiveRecent() {
var getParameter;
if ( !$( '#live-recent-list' ).length || $( '#live-recent-list' ).is( ':hidden' ) ) {
return;
}
getParameter = {
action: 'query',
list: 'recentchanges',
rcprop: 'title|timestamp',
rcshow: '!bot|!redirect',
rctype: 'edit|new',
rclimit: limit,
format: 'json',
rcnamespace: isArticleTab ? articleNamespaces : talkNamespaces,
rctoponly: true
};
mw.loader.using( 'mediawiki.api' ).then( function () {
var api = new mw.Api();
api.get( getParameter ).then( function ( data ) {
var recentChanges, html, time, line, text;
recentChanges = data.query.recentchanges;
function cutTitle(title, maxLength) {
let length = 0;
let cutOffIndex = title.length;
for (let i = 0; i < title.length; i++) {
// �곸뼱 �뚰뙆踰녠낵 �レ옄, 怨듬갚�� 1濡� 移댁슫��, 洹� �몃� 2濡� 移댁슫��
length += title.charCodeAt(i) > 127 ? 2 : 1;
if (length > maxLength) {
cutOffIndex = i;
break;
}
}
// �꾩슂�� 寃쎌슦 "..."�� 異붽�
return title.length > cutOffIndex ? title.slice(0, cutOffIndex) + "..." : title;
}
// �댄썑, �� �⑥닔瑜� �ъ슜�� �쒕ぉ�� 泥섎━
html = recentChanges.map(function (item) {
time = new Date(item.timestamp);
// cutTitle �⑥닔瑜� �ъ슜�� �쒕ぉ 泥섎━
var title = cutTitle(item.title, 30);
// �쒕ぉ怨� �쒓컙�� <div>濡� 媛먯떥 媛곴컖 block �붿냼濡� 留뚮뱾�� 以꾨컮轅� �④낵瑜� 以띾땲��.
line = '<li>';
line += '<a class="recent-item" href="' + mw.util.getUrl(item.title) + '" title="' + item.title + '">';
line += '<div class="item-title">' + title + '</div>'; // �섏젙�� �쒕ぉ�� �ъ슜
line += '<div class="item-time">' + timeFormat(time) + '</div>'; // �쒓컙�� �꾪븳 <div>
line += '</a>';
line += '</li>';
return line;
}).join('\n');
$( '#live-recent-list' ).html( html );
} )
.catch( function () {} );
});
}
$( '#liberty-recent-tab1' ).click( function () {
$( this ).addClass( 'active' );
$( '#liberty-recent-tab2' ).removeClass( 'active' );
isArticleTab = true;
refreshLiveRecent();
} );
$( '#liberty-recent-tab2' ).click( function () {
$( this ).addClass( 'active' );
$( '#liberty-recent-tab1' ).removeClass( 'active' );
isArticleTab = false;
refreshLiveRecent();
} );
setInterval( refreshLiveRecent, 5 * 60 * 1000 );
refreshLiveRecent();
} );