Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions github-toggle-expanders.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name GitHub Toggle Expanders
// @version 1.0.6
// @version 1.1.0
// @description A userscript that toggles all expanders when one expander is shift-clicked
// @license MIT
// @author Rob Garrison
Expand All @@ -14,16 +14,18 @@
(() => {
"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 toggle(el, ctrlKeyPressed) {
const stateNode = closest(".js-details-container", el),
state = stateNode.classList.contains("open"),
parentNode = closest(ctrlKeyPressed ?
".container, .js-discussion" :
".commits-listing, .discussion-item-body, .release-timeline-tags",
stateNode
),
containerNodes = parentNode.querySelectorAll(".js-details-container");

Array.from(containerNodes).forEach(node => {
node.classList.toggle("open", state);
});
}

Expand All @@ -41,11 +43,11 @@
const target = event.target;
if (
target && event.getModifierState("Shift") &&
target.matches(".ellipsis-expander")
target.matches(".js-details-target")
) {
// give GitHub time to add the class
setTimeout(() => {
toggle(target);
toggle(target, event.ctrlKey);
}, 100);
}
});
Expand Down