Skip to content

Commit 1c3856c

Browse files
committed
Github-toggle-expanders: handle PR comments
To toggle all outdated blocks for the current review : Shift+Click To toggle all outdated blocks in the PR : Ctrl+Shift+Click I had to refactor to match the closest parent. As a consequence, there is no longer the need to support `#commits_bucket` to fix #8
1 parent fdb629f commit 1c3856c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

github-toggle-expanders.user.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name GitHub Toggle Expanders
3-
// @version 1.0.6
3+
// @version 1.1.0
44
// @description A userscript that toggles all expanders when one expander is shift-clicked
55
// @license MIT
66
// @author Rob Garrison
@@ -14,16 +14,18 @@
1414
(() => {
1515
"use strict";
1616

17-
function toggle(el) {
18-
const state = closest(".commits-list-item, .js-details-container", el)
19-
.classList.contains("open"),
20-
// target buttons inside commits_bucket - fixes #8
21-
selectors = `
22-
.commits-listing .commits-list-item,
23-
#commits_bucket .js-details-container,
24-
.release-timeline-tags .js-details-container`;
25-
Array.from(document.querySelectorAll(selectors)).forEach(el => {
26-
el.classList.toggle("open", state);
17+
function toggle(el, ctrlKeyPressed) {
18+
const stateNode = closest(".js-details-container", el),
19+
state = stateNode.classList.contains("open"),
20+
parentNode = closest(ctrlKeyPressed ?
21+
".container, .js-discussion" :
22+
".commits-listing, .discussion-item-body, .release-timeline-tags",
23+
stateNode
24+
),
25+
containerNodes = parentNode.querySelectorAll(".js-details-container");
26+
27+
Array.from(containerNodes).forEach(node => {
28+
node.classList.toggle("open", state);
2729
});
2830
}
2931

@@ -41,11 +43,11 @@
4143
const target = event.target;
4244
if (
4345
target && event.getModifierState("Shift") &&
44-
target.matches(".ellipsis-expander")
46+
target.matches(".js-details-target")
4547
) {
4648
// give GitHub time to add the class
4749
setTimeout(() => {
48-
toggle(target);
50+
toggle(target, event.ctrlKey);
4951
}, 100);
5052
}
5153
});

0 commit comments

Comments
 (0)