MediaWiki:RecentChangesShow.js

From Isekai Wiki
Revision as of 16:57, 12 June 2020 by 落雨枫 (talk | contribs) (Created page with "var api = new mw.Api(); api.get({ action: 'query', list: 'recentchanges', rctype: 'edit', rcnamespace: 0, rclimit: 10, }).done((data) => { if(data.query){ //有成功取...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press 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);
	}
});