Thành viên:NguoiDungKhongDinhDanh/OneClickDeleter.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.

$(function() {
	var pn = mw.config.get('wgPageName').replace(/_/g, ' ');
	
	if (!pn.match(/Thành viên:NguoiDungKhongDinhDanh\/Danh sách\/\d+/)) {
		return;
	}
	
	mw.util.addPortletLink(
		'p-cactions', 'javascript:void(0)',
		'OCD', 'pt-ocd',
		'Initialize OneClickDeleter'
	);
	
	var api = new mw.Api();
	
	$('#pt-ocd').click(function() {
		$('.ocdel > a').click(function(e) {
			e.preventDefault();
			
			api.postWithToken('csrf', {
				action: 'delete',
				title: $(this).text(),
				reason: 'Xoá bài dịch chất lượng kém và trang thảo luận',
				deletetalk: true,
				format: 'json',
				formatversion: 2
			}).then(function() {
				mw.notify('Đã xoá!', {
					type: 'success',
					autoHide: true,
					autoHideSeconds: 3
				});
			}).fail(function(_, data) {
				mw.notify(api.getErrorMessage(data), {
					type: 'error',
					title: 'Xoá thất bại!',
					autoHide: true,
					autoHideSeconds: 3
				});
			});
		});
	});
});