Skip to content

Commit ecb3976

Browse files
committed
Toggle-expanders: Fix resolved comments
1 parent cb7eab6 commit ecb3976

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

github-toggle-expanders.user.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
// ==UserScript==
22
// @name GitHub Toggle Expanders
3-
// @version 2.0.1
3+
// @version 2.1.0
44
// @description A userscript that toggles all expanders when one expander is shift-clicked
55
// @license MIT
66
// @author Rob Garrison
77
// @namespace https://github.com/Mottie
88
// @include https://github.com/*
99
// @run-at document-idle
10+
// @require https://greasyfork.org/scripts/398877-utils-js/code/utilsjs.js?version=1079637
1011
// @icon https://github.githubassets.com/pinned-octocat.svg
11-
// @updateURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-toggle-expanders.user.js
12-
// @downloadURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-toggle-expanders.user.js
1312
// @supportURL https://github.com/Mottie/GitHub-userscripts/issues
1413
// ==/UserScript==
1514
(() => {
15+
/* global $ $$ on */
1616
"use strict";
1717

18+
// Commit history toggle
19+
// https://github.com/torvalds/linux/commits/master
1820
function toggleButton(el, modKey) {
1921
const stateNode = el.closest(".js-details-container");
2022
const state = stateNode && (
@@ -25,9 +27,11 @@
2527
);
2628
const parentNode = stateNode && stateNode.closest(modKey
2729
// shift+ctrl+click = expand all on page
28-
? ".repository-content"
30+
?
31+
".repository-content"
2932
// shift+click = expand all in date
30-
: ".Box--condensed"
33+
:
34+
".Box--condensed"
3135
);
3236

3337
if (parentNode) {
@@ -39,27 +43,37 @@
3943
}
4044
}
4145

46+
// Toggle resolved/outdated comments
47+
// https://github.com/PowerShell/PowerShell/pull/18210
4248
function toggleDetails(el, modKey) {
43-
const state = el && el.open;
44-
const parentNode = el && el.closest(modKey
45-
? "#discussion_bucket" // .js-discussion
46-
: ".discussion-item-body" // .container?
49+
// clicked button has the previous state
50+
const state = el && el.classList.contains("Details-content--closed");
51+
const parentNode = el.closest(modKey
52+
// shift+ctrl+click = expand all on page
53+
?
54+
".js-discussion"
55+
// shift+click = expand all in date
56+
:
57+
".js-timeline-item"
4758
);
59+
4860
if (parentNode) {
49-
const containers = parentNode.querySelectorAll(
50-
".outdated-comment, .js-comment-container"
51-
);
52-
[...containers].forEach(node => {
53-
node.open = state;
61+
$$("turbo-frame", parentNode).forEach(node => {
62+
const details = $("details", node);
63+
if (state) {
64+
details.setAttribute("open", state);
65+
} else {
66+
details.removeAttribute("open");
67+
}
5468
});
5569
}
5670
}
5771

58-
document.body.addEventListener("click", event => {
72+
on($("body"), "click", event => {
5973
const target = event.target;
60-
const mod = event.ctrlKey
61-
|| event.metaKey
62-
|| window.location.pathname.includes("/compare/");
74+
const mod = event.ctrlKey ||
75+
event.metaKey ||
76+
window.location.pathname.includes("/compare/");
6377

6478
if (target && event.getModifierState("Shift")) {
6579
// give GitHub time to update the elements
@@ -69,7 +83,7 @@
6983
} else if (
7084
target.matches(".Details-content--closed, .Details-content--open")
7185
) {
72-
toggleDetails(target.closest("details"), mod);
86+
toggleDetails(target, mod);
7387
}
7488
}, 100);
7589
}

0 commit comments

Comments
 (0)