User:NQ/custom-scripts/inlinediffs.js

// WritKeeper's amazing inlinediff script with some style changes. [[User:Writ Keeper/Scripts/commonHistory.js]] [[User:Writ_Keeper/Scripts/inlineDiffDocs]]

diffRequestLocked = "f";
if(typeof inspectText == "undefined")
{
	inspectText = "inspect diff";
}
if(typeof showText == "undefined")
{
	showText = "show diff";
}
if(typeof hideText == "undefined")
{
	hideText = "hide diff";
}
if(	mw.config.get("wgCanonicalSpecialPageName") == "Watchlist" || 
	mw.config.get("wgCanonicalSpecialPageName") == "Recentchanges" || 
	mw.config.get("wgCanonicalSpecialPageName") == "Contributions" ||
	mw.config.get("wgAction") == "history")
{
	function inspectionEachHelper(index, element)
	{
		var findString;
		if(mw.config.get("wgAction") == "history" || $(element).hasClass("mw-enhanced-rc-nested"))
		{
			findString = 'a:contains("prev")';
		}
		else
		{
			findString = 'a:contains("diff")';
		}
		
		var regex;
		
		if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")
		{
			regex = /&oldid=(\d+)$/;
			
		}
		else
		{
			regex = /&diff=(\d+)&oldid=/;
		}
		var diffLink = $(element).find(findString);
		if(diffLink.length > 0 )
		{
			var regexResult = regex.exec(diffLink[0].href);
			if(regexResult != null && regexResult.length >= 2)
			{
				var diffID = regexResult[1];
				var inlineDiffButton;
				if(typeof inlineDiffBigUI === "undefined")
				{ 
					inlineDiffButton = document.createElement("a");
					inlineDiffButton.href = "#";
					inlineDiffButton.innerHTML = '<span style="color:black;"> (</span>'+inspectText+'<span style="color:black;">) </span>';
				}
				else
				{
					inlineDiffButton = document.createElement("input");
					inlineDiffButton.type = "button";
					inlineDiffButton.value = "Inspect edit";
				}
				inlineDiffButton.id = diffID;
				$(inlineDiffButton).click(function(){ return inspectWatchlistDiff(this);});
					if($(element).find("tr:first").length == 0)
				{
					$(inlineDiffButton).insertBefore($(element).children(".mw-changeslist-separator:first"));
				}
				else
				{
					$(element).find("tr:first").append("<td></td>");
					$(element).find("tr:first>td:last").append(inlineDiffButton);
				}
			}
		}
	}
	function addWatchlistInspectionBoxes() {
	
		
		var entries = $("#mw-content-text table.mw-enhanced-rc");
		if(entries.length == 0)
		{
			$("#mw-content-text ul").each(function(ind, el)
			{
				$(el).children("li").each(inspectionEachHelper);
			});
		}
		else
		{
			entries.each(inspectionEachHelper);
			$("td.mw-enhanced-rc-nested").each(inspectionEachHelper);
		}
		mw.loader.load('mediawiki.action.history.diff');
	}
 
	function inspectWatchlistDiff(button)
	{
		if(diffRequestLocked === "t")
		{
			alert("An old request is still being processed, please wait...");
			return false;
		}
		else
		{
			diffRequestLocked = "t";
			var mwApi = new mw.Api();
			mwApi.get( {action : "query", prop : "revisions", format : "json", rvprop : "timestamp", rvdiffto : "prev", revids : button.id}).done(function(response) 
			{
 				if(response == null)
				{
					alert("Request failed!");
					diffRequestLocked = "f";
					return false;
				}

				var diffString = response.query.pages[Object.keys(response.query.pages)[0]].revisions[0].diff["*"];
 
				if(diffString == null)
				{
					alert("Request failed!");
					diffRequestLocked = "f";
					return false;
				}
 
				var newTable = document.createElement("table");
				newTable.className = "diff";
 				$(newTable).html('<colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup>');
 
				$(newTable).append(diffString);
				if($("#"+ button.id).parent("td").length > 0 && !($("#"+ button.id).parent("td").hasClass("mw-enhanced-rc-nested")))
				{
					$("#"+ button.id).parents("table.mw-enhanced-rc:first").after(newTable);
				}
				else
				{
					diffParent = $("#"+button.id).parent();
					diffParent.append(newTable);
				}
				newTable.id = button.id + "display";
	
				$(button).unbind("click");
				if(typeof inlineDiffBigUI === "undefined")
				{
					$(button).html('<span style="color:black;"> (</span>'+hideText+'<span style="color:black;">) </span>');
					$(button).click(function(){ return hideSmallEditInspection(this);});
				}
				else
				{
					$(button).attr("value","Hide edit");
					$(button).click(function(){ return hideEditInspection(this);});
				}
				mwApi.post({action : "setnotificationtimestamp", revids: button.id, token : mw.user.tokens.get("editToken")}).done(function(data)
				{
					if(diffParent != null)
					{
						diffParent.removeClass("mw-changeslist-line-watched");
						diffParent.addClass("mw-changeslist-line-not-watched");
					}
				});
 
				diffRequestLocked = "f";
			});
	
		}
		return false;
	}
 
	function showEditInspection(button)
	{
		$("#"+button.id+"display").css("display", "");
		$(button).attr("value","Hide edit");
		$(button).unbind("click");
		$(button).click(function(){ return hideEditInspection(this);});
		return false;
	}
 
	function hideEditInspection(button)
	{
		$("#"+button.id+"display").css("display", "none");
		$(button).attr("value","Show edit");
		$(button).unbind("click");
		$(button).click(function(){ return showEditInspection(this);});
		return false;
	}

	function showSmallEditInspection(button)
	{
		$("#"+button.id+"display").css("display", "");
		$(button).html('<span style="color:black;"> (</span>'+hideText+'<span style="color:black;">) </span>');
		$(button).unbind("click");
		$(button).click(function(){ return hideSmallEditInspection(this);});
		return false;
	}
		
	function hideSmallEditInspection(button)
	{
		$("#"+button.id+"display").css("display", "none");
		$(button).html('<span style="color:black;"> (</span>'+showText+'<span style="color:black;">) </span>');
		$(button).unbind("click");
		$(button).click(function(){ return showSmallEditInspection(this);});
		return false;
	}

	$(document).ready(addWatchlistInspectionBoxes);
}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.