Greasy Fork is available in English.

Github News Feed Filter

Add filters for Github homepage news feed items

Stan na 06-03-2014. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Github News Feed Filter
// @namespace   https://github.com/jerone/UserScripts
// @description Add filters for Github homepage news feed items
// @author      jerone
// @homepage    https://github.com/jerone/UserScripts/tree/master/Github_News_Feed_Filter
// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_News_Feed_Filter
// @include     http*://github.com/
// @version     1
// @grant       none
// ==/UserScript==


(function () {

	function proxy(fn) {
		return function () {
			var that = this;
			return function (e) {
				var args = that.slice(0);  // clone;
				args.unshift(e);  // prepend event;
				fn.apply(this, args);
			};
		}.call([].slice.call(arguments, 1));
	}

	function addFilters() {
		var container;
		if (!(container = document.querySelector(".news"))) return;

		var ul = document.createElement("ul");
		ul.classList.add("dashboard-tabs");
		[{ text: "", icon: "octicon-comment-discussion", filter: ["*"] },
		 { text: "Comments", icon: "octicon-comment", filter: ["issues_comment"] },
		 { text: "Commits", icon: "octicon-git-commit", filter: ["push"] },
		 { text: "Issue actions", icon: "octicon-issue-opened", filter: ["issues_opened", "issues_closed"] }
		].forEach(function (item) {
			var li = document.createElement("li");
			var a = document.createElement("a");
			a.classList.add("js-selected-navigation-item");
			a.setAttribute("href", "/");
			a.setAttribute("title", item.filter.join(" & "));
			var s = document.createElement("span");
			s.classList.add("octicon", item.icon);
			if (item.filter == "*") {
				li.style.cssFloat = "left";
				li.style.width = "49px";
				a.classList.add("selected");
			} else {
				s.style.marginRight = "6px";
			}
			a.appendChild(s);
			a.appendChild(document.createTextNode(item.text));
			a.addEventListener("click", proxy(function (e, filter) {
				e.preventDefault();
				Array.forEach(container.querySelectorAll(".selected"), function (m) {
					m.classList.remove("selected");
				});
				this.classList.add("selected");
				var alerts = container.querySelectorAll(".alert");
				Array.filter(alerts, function (alert) {
					alert.style.display = filter == "*" || filter.some(function (c) {
						return alert.classList.contains(c);
					}) ? "block" : "none";
				});
				return false;
			}, item.filter));
			li.appendChild(a);
			ul.appendChild(li);
		});

		container.insertBefore(ul, container.firstChild);

		// update on clicking "More"-button;
		var event = new Event("click");
		$.pageUpdate(function () {
			window.setTimeout(function () {
				container.querySelector(".selected").dispatchEvent(event);
			}, 1);
		});
	}

	// init;
	addFilters();

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

})();