MediaWiki:RecentChangesShow.js

来自科幻设定百科

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
var api = new mw.Api();
api.get({
	action: 'query',
	list: 'recentchanges',
	rctype: 'edit',
	rcnamespace: 0,
	rclimit: 10,
}).done((data) => {
	if(data.query){ //有成功取到数据
		var pageList = [];
		var pageLinkList = document.createElement('ul');
		data.query.recentchanges.forEach((one) => {
			if(pageList.indexOf(one.title) < 0){
				pageList.push(one.title);
			}
		});
		pageList.forEach((one) => {
			var a = document.createElement('a');
			a.href = mw.util.getUrl(one);
			a.title = one;
			a.innerText = one;
			var li = document.createElement('li');
			li.appendChild(a);
			pageLinkList.appendChild(li);
		});
		$('.recent-changes.edit').html('').append(pageLinkList);
	}
});

api.get({
	action: 'query',
	list: 'recentchanges',
	rctype: 'new',
	rcnamespace: 0,
	rclimit: 10,
}).done((data) => {
	if(data.query){ //有成功取到数据
		var pageList = [];
		var pageLinkList = document.createElement('ul');
		data.query.recentchanges.forEach((one) => {
			if(pageList.indexOf(one.title) < 0){
				pageList.push(one.title);
			}
		});
		pageList.forEach((one) => {
			var a = document.createElement('a');
			a.href = mw.util.getUrl(one);
			a.title = one;
			a.innerText = one;
			var li = document.createElement('li');
			li.appendChild(a);
			pageLinkList.appendChild(li);
		});
		$('.recent-changes.add').html('').append(pageLinkList);
	}
});