Skip to content

Commit 728bb19

Browse files
authored
Update diff files toggle button placement
Place the diff files toggle button in the `diff-layout > div.pr-toolbar > div.diffbar > div.pr-review-tools` section.
1 parent 7f68a14 commit 728bb19

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

github-diff-file-toggle.user.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,32 @@
2525

2626
const setToggleStyle = state => {
2727
const mainToggle = $(".ghdt-toggle");
28-
mainToggle.classList.toggle("ghdt-selected", state);
29-
mainToggle.style = state
30-
? "background-color: var(--color-btn-selected-bg);"
31-
: "";
28+
if (mainToggle) {
29+
mainToggle.classList.toggle("ghdt-selected", state);
30+
mainToggle.style = state ? "background-color: var(--color-btn-selected-bg);" : "";
31+
}
3232
};
3333

34-
const buildButton = () => {
34+
const init = () => {
3535
if (!$(".ghdt-toggle")) {
36-
const button = make({
36+
const toggleButton = make({
3737
el: "button",
3838
className: "btn btn-sm ghdt-toggle tooltipped tooltipped-s float-right",
3939
text: "Toggle viewed",
4040
attrs: {
4141
"aria-label": "Toggle all viewed files"
4242
}
4343
});
44-
on(button, "click", event => {
44+
on(toggleButton, "click", event => {
4545
toggle(document, !event.target.classList.contains("ghdt-selected"));
4646
});
47-
$("#files.diff-view")?.prepend(button);
47+
const diffBarItem = make({
48+
el: "div",
49+
className: "diffbar-item js-batched-reviewed mr-3",
50+
}, [toggleButton]);
51+
$("diff-layout > div.pr-toolbar > div.diffbar > div.pr-review-tools")?.prepend(diffBarItem);
4852
}
49-
// Update toggle button state after initialized; timer for progressive
50-
// loading
53+
// Update toggle button state after initialized; timer for progressive loading
5154
clearTimeout(timer);
5255
timer = setTimeout(() => {
5356
if ($$(".js-reviewed-checkbox").every(el => el.checked)) {
@@ -77,12 +80,6 @@
7780
}
7881
};
7982

80-
const init = () => {
81-
if ($("#files.diff-view") || $(".pr-toolbar")) {
82-
buildButton();
83-
}
84-
};
85-
8683
on(document, "ghmo:container ghmo:diff", init);
8784
on(document, "click", debounce(handleChange));
8885
on(document, "keydown", debounce(handleChange));

0 commit comments

Comments
 (0)