From 1c3856c5e05b222639a5a4a377a58bf997d71650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Malard?= Date: Thu, 15 Jun 2017 17:30:22 +0200 Subject: [PATCH] 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 --- github-toggle-expanders.user.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/github-toggle-expanders.user.js b/github-toggle-expanders.user.js index 4f5663b..45846e3 100644 --- a/github-toggle-expanders.user.js +++ b/github-toggle-expanders.user.js @@ -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 @@ -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); }); } @@ -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); } });