Github Commit Diff

Adds button to show diff (or patch) file for commit

2014-04-03 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        Github Commit Diff
// @namespace   https://github.com/jerone/UserScripts
// @description Adds button to show diff (or patch) file for commit
// @author      jerone
// @homepage    https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
// @include     https://github.com/*
// @version     1.2
// @grant       none
// ==/UserScript==

(function() {

	function addButton() {
		var e;
		if (!/\/commit\//.test(location.href) || !(e = document.querySelector(".explain"))) return;

		var r = e.querySelector(".GithubCommitWhitespaceButton");
		if (r) r.parentElement.removeChild(r);

		function getPatchOrDiffHref(type) {
			return (document.querySelector("link[type='text/plain+" + type + "']")
				|| { href: location.href + "." + type }).href;
		};

		var b = e.querySelector(".minibutton");

		var s = document.createElement("span");
		s.textContent = " ";
		s.classList.add("octicon", "octicon-diff");
		s.style.color = "#333";  // set color because of css selector `p.explain .octicon`;

		var a = document.createElement("a");
		a.classList.add("GithubCommitDiffButton", "minibutton", "tooltipped", "tooltipped-s");
		a.setAttribute("href", getPatchOrDiffHref("diff"));
		a.setAttribute("title", "Show commit diff.\r\nHold Shift to open commit patch.");
		a.setAttribute("rel", "nofollow");
		a.setAttribute("aria-label", a.getAttribute("title"));
		a.style.marginLeft = "10px";  // give us some room;
		a.appendChild(s);
		a.appendChild(document.createTextNode("Diff"));

		b.parentNode.insertBefore(a, b);

		a.addEventListener("click", function(e) {
			if (e.shiftKey) {
				e.preventDefault();
				location.href = getPatchOrDiffHref("patch");
			}
		}, false);
	}

	// init;
	addButton();

	// on pjax;
	unsafeWindow.$(document).on('pjax:success', addButton);

})();