Github Commit Whitespace

Adds button to hide whitespaces from commit

03.02.2024 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name             Github Commit Whitespace
// @namespace        https://github.com/jerone/UserScripts
// @description      Adds button to hide whitespaces from commit
// @author           jerone
// @copyright        2014+, jerone (https://github.com/jerone)
// @license          CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @license          GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @homepage         https://github.com/jerone/UserScripts/tree/master/Github_Commit_Whitespace
// @homepageURL      https://github.com/jerone/UserScripts/tree/master/Github_Commit_Whitespace
// @supportURL       https://github.com/jerone/UserScripts/issues
// @contributionURL  https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
// @icon             https://github.githubassets.com/pinned-octocat.svg
// @include          https://github.com/*
// @version          1.5.4
// @grant            none
// ==/UserScript==

// cSpell:ignore tooltipped, diffbar

(function () {
	function addButton() {
		var e;
		if (
			(/\/commit\//.test(location.href) ||
				/\/compare\//.test(location.href)) &&
			(e = document.getElementById("toc"))
		) {
			let r = e.querySelector(".GithubCommitWhitespaceButton");
			if (r) {
				r.parentElement.removeChild(r);
			}

			let on = /w=/.test(location.search); // Any occurrence results in enabling

			let b = e.querySelector(".toc-diff-stats");

			let a = document.createElement("a");
			a.classList.add("btn", "btn-sm", "tooltipped", "tooltipped-n");
			if (on) {
				a.classList.add("selected");
			}
			a.setAttribute("href", url(on));
			a.setAttribute("rel", "nofollow");
			a.setAttribute(
				"aria-label",
				on ? "Show commit whitespace" : "Hide commit whitespace",
			);
			a.appendChild(document.createTextNode("\u2423"));

			let g = document.createElement("div");
			g.classList.add("GithubCommitWhitespaceButton", "float-right");
			g.style.margin = "0 10px 0 0"; // Give us some room
			g.appendChild(a);

			b.parentNode.insertBefore(g, b);
		} else if (
			/\/pull\/\d*\/(files|commits)/.test(location.href) &&
			(e = document.querySelector(
				"#files_bucket .pr-toolbar .diffbar > .pr-review-tools",
			))
		) {
			let r = e.querySelector(".GithubCommitWhitespaceButton");
			if (r) {
				r.parentElement.removeChild(r);
			}

			let on = /w=/.test(location.search); // Any occurrence result in enabling

			let a = document.createElement("a");
			a.classList.add(
				"btn",
				"btn-sm",
				"btn-outline",
				"tooltipped",
				"tooltipped-s",
			);
			a.setAttribute("href", url(on));
			a.setAttribute("rel", "nofollow");
			a.setAttribute(
				"aria-label",
				on ? "Show commit whitespace" : "Hide commit whitespace",
			);
			a.appendChild(document.createTextNode("\u2423"));

			let g = document.createElement("div");
			g.classList.add("GithubCommitWhitespaceButton", "diffbar-item");
			g.appendChild(a);

			e.insertBefore(g, e.firstChild);
		}
	}

	function url(on) {
		var searches = location.search
			.replace(/^\?/, "")
			.split("&")
			.filter(function (item) {
				return item && !/w=.*/.test(item);
			});
		if (!on) {
			searches.push("w=1");
		}
		return (
			location.href
				.replace(location.search, "")
				.replace(location.hash, "") +
			(searches.length > 0 ? "?" + searches.join("&") : "") +
			location.hash
		);
	}

	// Init
	addButton();

	// Pjax
	document.addEventListener("pjax:end", addButton);
})();