Skip to content

Commit 01e6016

Browse files
committed
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 575e466 commit 01e6016

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
@@ -26,29 +26,32 @@
2626

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

35-
const buildButton = () => {
35+
const init = () => {
3636
if (!$(".ghdt-toggle")) {
37-
const button = make({
37+
const toggleButton = make({
3838
el: "button",
3939
className: "btn btn-sm ghdt-toggle tooltipped tooltipped-s float-right",
4040
text: "Toggle viewed",
4141
attrs: {
4242
"aria-label": "Toggle all viewed files"
4343
}
4444
});
45-
on(button, "click", event => {
45+
on(toggleButton, "click", event => {
4646
toggle(document, !event.target.classList.contains("ghdt-selected"));
4747
});
48-
$("#files.diff-view")?.prepend(button);
48+
const diffBarItem = make({
49+
el: "div",
50+
className: "diffbar-item js-batched-reviewed mr-3",
51+
}, [toggleButton]);
52+
$("diff-layout > div.pr-toolbar > div.diffbar > div.pr-review-tools")?.prepend(diffBarItem);
4953
}
50-
// Update toggle button state after initialized; timer for progressive
51-
// loading
54+
// Update toggle button state after initialized; timer for progressive loading
5255
clearTimeout(timer);
5356
timer = setTimeout(() => {
5457
if ($$(".js-reviewed-checkbox").every(el => el.checked)) {
@@ -78,12 +81,6 @@
7881
}
7982
};
8083

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

0 commit comments

Comments
 (0)