Skip to content

Commit

Permalink
Update diff files toggle button placement
Browse files Browse the repository at this point in the history
Place the diff files toggle button in the `diff-layout > div.pr-toolbar > div.diffbar > div.pr-review-tools` section.
  • Loading branch information
Nirmal4G committed Feb 17, 2024
1 parent 575e466 commit 01e6016
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions github-diff-file-toggle.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,32 @@

const setToggleStyle = state => {
const mainToggle = $(".ghdt-toggle");
mainToggle.classList.toggle("ghdt-selected", state);
mainToggle.style = state
? "background-color: var(--color-btn-selected-bg);"
: "";
if (mainToggle) {
mainToggle.classList.toggle("ghdt-selected", state);
mainToggle.style = state ? "background-color: var(--color-btn-selected-bg);" : "";
}
};

const buildButton = () => {
const init = () => {
if (!$(".ghdt-toggle")) {
const button = make({
const toggleButton = make({
el: "button",
className: "btn btn-sm ghdt-toggle tooltipped tooltipped-s float-right",
text: "Toggle viewed",
attrs: {
"aria-label": "Toggle all viewed files"
}
});
on(button, "click", event => {
on(toggleButton, "click", event => {
toggle(document, !event.target.classList.contains("ghdt-selected"));
});
$("#files.diff-view")?.prepend(button);
const diffBarItem = make({
el: "div",
className: "diffbar-item js-batched-reviewed mr-3",
}, [toggleButton]);
$("diff-layout > div.pr-toolbar > div.diffbar > div.pr-review-tools")?.prepend(diffBarItem);
}
// Update toggle button state after initialized; timer for progressive
// loading
// Update toggle button state after initialized; timer for progressive loading
clearTimeout(timer);
timer = setTimeout(() => {
if ($$(".js-reviewed-checkbox").every(el => el.checked)) {
Expand Down Expand Up @@ -78,12 +81,6 @@
}
};

const init = () => {
if ($("#files.diff-view") || $(".pr-toolbar")) {
buildButton();
}
};

on(document, "ghmo:container ghmo:diff", init);
on(document, "click", debounce(handleChange));
on(document, "keydown", debounce(handleChange));
Expand Down

0 comments on commit 01e6016

Please sign in to comment.