GitHub Toggle Expanders

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

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

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

	function toggle(el) {
		const state = closest(".commits-list-item, .js-details-container", el)
			.classList.contains("open"),
			// target buttons inside commits_bucket - fixes #8
			selectors = `
				.commits-listing .commits-list-item,
				#commits_bucket .js-details-container,
				.release-timeline-tags .js-details-container`;
		Array.from(document.querySelectorAll(selectors)).forEach(el => {
			el.classList.toggle("open", state);
		});
	}

	function closest(selector, el) {
		while (el && el.nodeType === 1) {
			if (el.matches(selector)) {
				return el;
			}
			el = el.parentNode;
		}
		return null;
	}

	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。