GitHub Toggle Expanders

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

Από την 02/07/2019. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        GitHub Toggle Expanders
// @version     1.2.0
// @description A userscript that toggles all expanders when one expander is shift-clicked
// @license     MIT
// @author      Rob Garrison
// @namespace   https://github.com/Mottie
// @include     https://github.com/*
// @run-at      document-idle
// @icon        https://github.githubassets.com/pinned-octocat.svg
// ==/UserScript==
(() => {
	"use strict";

	function toggle(el, modKey) {
		const stateNode = el.closest(".js-details-container, details");
		const state = stateNode.nodeName === "DETAILS" ?
			stateNode.open :
			stateNode.classList.contains("open");
		const parentNode = stateNode.closest(modKey ?
			".container, .js-discussion" :
			".commit-group, .js-timeline-item"
		);
		const containers = parentNode.querySelectorAll(
			".js-details-container, .outdated-comment"
		);

		[...containers].forEach(node => {
			if (node.nodeName === "DETAILS") {
				node.open = state;
			} else {
				node.classList.toggle("open", state);
			}
		});
	}

	document.body.addEventListener("click", event => {
		const target = event.target;
		const mod = event.ctrlKey
			|| event.metaKey
			|| window.location.pathname.includes("/compare/");
		if (target && event.getModifierState("Shift")) {
			// give GitHub time to update the elements
			setTimeout(() => {
				if (target.matches(".js-details-target")) {
					toggle(target, mod);
				} else if (target.matches(".btn-link, .js-toggle-outdated-comments")) {
					toggle(target.closest("details"), mod);
				}
			}, 100);
		}
	});

})();