Jump to content

User:Writ Keeper/Scripts/g10viewer.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
mw.hook("wikipage.content").add( function()
{
	if($("#delete-criterion").text() == "G10")
	{
		var blankBox = $('td.mbox-text>a[href$="Wikipedia:Deletion_policy#Courtesy_blanking"]').parent();
		blankBox.html(blankBox.html() + " <span id='g10ViewerButton' style='font-weight:bold;cursor:pointer;'>[show page]</span>");
		$("#g10ViewerButton").click(function() 
		{
			mw.loader.using(["mediawiki.api"]).then(function() 
			{
				const api = new mw.Api();
				if($("#g10Viewer").length == 0)
				{
					var params  = 
					{
						action: 'query',
						prop: 'revisions',
						titles: mw.config.get("wgPageName"),
						rvlimit: '2',
						rvprop: 'ids',
						format: 'json'
					};
				
					api.get(params).done(function(data) 
					{
						var revid = data.query.pages[mw.config.get("wgArticleId")].revisions[1].revid;
						params = 
						{
							action: 'parse',
							oldid: revid,
							format:'json'
						};
						api.get(params).done(function(data) 
						{
							blankBox.parents("table.ombox-notice").after("<div id='g10Viewer'>"+data.parse.text['*'] + "</div>");
							$("#g10ViewerButton").text("[hide page]");
						});
					});
				}
				else if($("#g10ViewerButton").text() == "[show page]")
				{
					$("#g10Viewer").show();
					$("#g10ViewerButton").text("[hide page]");
				}
				else if($("#g10ViewerButton").text() == "[hide page]")
				{
					$("#g10Viewer").hide();
					$("#g10ViewerButton").text("[show page]");
				}
			});
		});
		
	}
});