Chú ý: Sau khi lưu thay đổi trang, bạn phải xóa bộ nhớ đệm của trình duyệt để nhìn thấy các thay đổi. Google Chrome, Firefox, Internet ExplorerSafari: Giữ phím ⇧ Shift và nhấn nút Reload/Tải lại trên thanh công cụ của trình duyệt. Để biết chi tiết và hướng dẫn cho các trình duyệt khác, xem Trợ giúp:Xóa bộ nhớ đệm.

/*** Restorer ***/

// Easily restore an older version of a page
// Documentation at [[User:BrandonXLF/Restorer]]
// By [[User:BrandonXLF]]

$(function() {
	window.restorerSummary = window.restorerSummary || 'Hồi sửa về phiên bản $ID của [[Special:Contributions/$USER|$USER]] ([[w:en:User:BrandonXLF/Restorer|Restorer]])';

	function restore(user, revid) {
		$.post(mw.config.get('wgScriptPath') + '/api.php', {
			action: 'edit',
			pageid: mw.config.get('wgArticleId'),
			undo: mw.config.get('wgCurRevisionId'),
			undoafter: revid,
			summary: window.restorerSummary.replace(/\$ID/g, revid).replace(/\$USER/g, user),
			token: mw.user.tokens.get('csrfToken'),
			format: 'json'
		}).fail(function() {
			mw.notify('Đã xảy ra lỗi khi phục hồi phiên bản.', {type: 'error'});
		}).done(function(result) {
			if (result.error) {
				mw.notify(result.error.info, {type: 'error'});
			} else {
				mw.notify('Phục hồi phiên bản thành công.');
				location.reload();
			}
		});
	}

	function addLink(item) {
		var revid = item.getAttribute('data-mw-revid'),
			user,
			links,
			ele,
			parent;

		if (revid != mw.config.get('wgCurRevisionId')) {
			user = item.getElementsByClassName('mw-userlink')[0].textContent.replace('User:', '');
			links = item.getElementsByClassName('mw-changeslist-links');
			links = links[links.length - 1];
			parent = document.createElement('span');
			ele = document.createElement('a');

			ele.addEventListener('click', function() {
				restore(user, revid);
			});
			
			ele.innerHTML = 'phục hồi';
			parent.appendChild(ele);
			links.appendChild(parent);
		}
	}

	if (location.search.includes('action=history')) {
		var i,
			parents = document.querySelectorAll('li[data-mw-revid]');
		for (i = 0; i < parents.length; i++) {
			addLink(parents[i]);
		}
	}
});