Thành viên:NguoiDungKhongDinhDanh/UndeletePreview.js

Bách khoa toàn thư mở Wikipedia

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.

/* jshint esversion: 6, maxerr: 9999, undef: true, unused: true, quotmark: single */
/* globals $, mw, console */

$(function() {
	var currentUrl = new mw.Uri();
	
	if (
		mw.config.get('wgCanonicalSpecialPageName') !== 'Undelete' ||
		!currentUrl.query.target || !currentUrl.query.timestamp
	) {
		return;
	}
	
	var $link = $('.mw-revdelundel-link > a');
	
	if (!$link.length) {
		return;
	}
	
	var revid = (new mw.Uri($link.attr('href'))).query.ids;
	
	call({
		action: 'query',
		prop: 'deletedrevisions',
		drvprop: 'content',
		drvslots: 'main',
		drvlimit: 1,
		revids: revid,
		format: 'json',
		formatversion: 2
	}, function(response) {
		call({
			action: 'parse',
			prop: 'text',
			title: currentUrl.query.target,
			text: response.query.pages[0].deletedrevisions[0].slots.main.content,
			disableeditsection: true,
			preview: true,
			format: 'json',
			formatversion: 2
		}, function(response) {
			var $text = $(response.parse.text);
			
			// For some reason, action=parse has no option to turn it off.
			$('.ext-discussiontools-init-section-bar', $text).remove();
			
			$('#mw-content-text > .printfooter').before($text);
		});
	});
	
	function call(data, onsuccess) {
		$.ajax({
			url: mw.config.get('wgScriptPath') + '/api.php',
			data: data,
			type: 'POST',
			dataType: 'json',
			success: onsuccess,
			error: function(error, response) {
				console.warn(error, response);
			}
		});
	}
});