|
1 | 1 | // ==UserScript== |
2 | 2 | // @name GitHub Toggle Expanders |
3 | | -// @version 2.0.1 |
| 3 | +// @version 2.1.0 |
4 | 4 | // @description A userscript that toggles all expanders when one expander is shift-clicked |
5 | 5 | // @license MIT |
6 | 6 | // @author Rob Garrison |
7 | 7 | // @namespace https://github.com/Mottie |
8 | 8 | // @include https://github.com/* |
9 | 9 | // @run-at document-idle |
| 10 | +// @require https://greasyfork.org/scripts/398877-utils-js/code/utilsjs.js?version=1079637 |
10 | 11 | // @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 |
13 | 12 | // @supportURL https://github.com/Mottie/GitHub-userscripts/issues |
14 | 13 | // ==/UserScript== |
15 | 14 | (() => { |
| 15 | + /* global $ $$ on */ |
16 | 16 | "use strict"; |
17 | 17 |
|
| 18 | + // Commit history toggle |
| 19 | + // https://github.com/torvalds/linux/commits/master |
18 | 20 | function toggleButton(el, modKey) { |
19 | 21 | const stateNode = el.closest(".js-details-container"); |
20 | 22 | const state = stateNode && ( |
|
25 | 27 | ); |
26 | 28 | const parentNode = stateNode && stateNode.closest(modKey |
27 | 29 | // shift+ctrl+click = expand all on page |
28 | | - ? ".repository-content" |
| 30 | + ? |
| 31 | + ".repository-content" |
29 | 32 | // shift+click = expand all in date |
30 | | - : ".Box--condensed" |
| 33 | + : |
| 34 | + ".Box--condensed" |
31 | 35 | ); |
32 | 36 |
|
33 | 37 | if (parentNode) { |
|
39 | 43 | } |
40 | 44 | } |
41 | 45 |
|
| 46 | + // Toggle resolved/outdated comments |
| 47 | + // https://github.com/PowerShell/PowerShell/pull/18210 |
42 | 48 | 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" |
47 | 58 | ); |
| 59 | + |
48 | 60 | 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 | + } |
54 | 68 | }); |
55 | 69 | } |
56 | 70 | } |
57 | 71 |
|
58 | | - document.body.addEventListener("click", event => { |
| 72 | + on($("body"), "click", event => { |
59 | 73 | 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/"); |
63 | 77 |
|
64 | 78 | if (target && event.getModifierState("Shift")) { |
65 | 79 | // give GitHub time to update the elements |
|
69 | 83 | } else if ( |
70 | 84 | target.matches(".Details-content--closed, .Details-content--open") |
71 | 85 | ) { |
72 | | - toggleDetails(target.closest("details"), mod); |
| 86 | + toggleDetails(target, mod); |
73 | 87 | } |
74 | 88 | }, 100); |
75 | 89 | } |
|
0 commit comments