참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
 $( 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();
} );