-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Github-toggle-expanders: handle PR comments #22
Conversation
Hmm, since you didn't respond, and I had a "little" free time, I started working on this myself. I ended up separating out the review buttons from the ellipses. I also made it so that using Ctrl+Shift+Click would toggle all of the outdated blocks. I haven't had a chance to test your changes, but let me know if this works for you? // ==UserScript==
// @name GitHub Toggle Expanders
// @version 1.1.0
// @description A userscript that toggles all expanders when one expander is shift-clicked
// @license MIT
// @author Rob Garrison
// @namespace https://github.com/Mottie
// @include https://github.com/*
// @run-at document-idle
// @icon https://github.com/fluidicon.png
// @updateURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-toggle-expanders.user.js
// @downloadURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-toggle-expanders.user.js
// ==/UserScript==
(() => {
"use strict";
function toggleEllipses(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);
});
}
// Pull request review blocks (outdated)
function toggleReviews(event) {
const target = event.target,
buttonType = target.classList.contains("show-outdated-button") ?
"show" :
"hide",
// programmically clicking on a "show" button that has content already
// shown would hide the content, so we need to check the state
wrapperState = buttonType === "show" ? ":not(.open)" : ".open",
container = event.ctrlKey ?
// If ctrl key pressed, toggle ALL outdated blocks
document :
// Only the current review block
closest(".discussion-item-body", target),
selector = `.js-details-container${wrapperState} .${buttonType}` +
`-outdated-button`;
if (container) {
Array.from(container.querySelectorAll(selector)).forEach(el => {
if (el !== target) {
el.click();
}
});
}
}
function closest(selector, el) {
while (el && el.nodeType === 1) {
if (el.matches(selector)) {
return el;
}
el = el.parentNode;
}
return null;
}
document.body.addEventListener("click", event => {
const target = event.target;
if (target && event.getModifierState("Shift")) {
if (target.matches(".ellipsis-expander")) {
// give GitHub time to add the class
setTimeout(() => {
toggleEllipses(target);
}, 100);
} else if (target.matches(".outdated-comment-label")) {
setTimeout(() => {
toggleReviews(event);
}, 100);
}
}
});
})(); |
Hey @Mottie, It seems to me that your changes are more complex for the same result. |
ee02572
to
94f83c9
Compare
You're right, I did overly complicate the script. I'll go with what you have here... But, I was just testing the code and I found that using Ctrl+Shift+Click to open all sections also opens the title change form for the PR ( Also, please bump the version number to 1.1.0. Thanks! |
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 Mottie#8
Well spotted 👍 I used
Done 🍻 |
Awesome! Thanks so much! |
To toggle all outdated blocks within a single review : Shift+Click
To toggle all outdated blocks on the page : 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