GitHub Toggle Expanders

A userscript that toggles all expanders when one expander is shift-clicked

As of 2016-09-18. See the latest version.

// ==UserScript==
// @name          GitHub Toggle Expanders
// @version       1.0.0
// @description   A userscript that toggles all expanders when one expander is shift-clicked
// @license       https://creativecommons.org/licenses/by-sa/4.0/
// @namespace     https://github.com/Mottie
// @include       https://github.com/*
// @run-at        document-idle
// @author        Rob Garrison
// ==/UserScript==
/* jshint esnext:true, unused:true */
(() => {
	"use strict";

	function toggle(el) {
		const selector = ".commits-list-item, .js-details-container",
			state = closest(el, selector).classList.contains("open");
		Array.from(document.querySelectorAll(selector)).forEach(el => {
			el.classList[state ? "add" : "remove"]("open");
		});
	}

	function closest(el, selector) {
		while (el && el.nodeName !== "BODY" && !el.matches(selector)) {
			el = el.parentNode;
		}
		return el && el.matches(selector) ? el : [];
	}

	document.body.addEventListener("click", event => {
		const target = event.target;
		if (
			target && event.getModifierState("Shift") &&
			target.matches(".ellipsis-expander")
		) {
			// give GitHub time to add the class
			setTimeout(() => {
				toggle(target);
			}, 100);
		}
	});

})();
长期地址
遇到问题?请前往 GitHub 提 Issues。