|
26 | 26 |
|
27 | 27 | const setToggleStyle = state => {
|
28 | 28 | 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 | + } |
33 | 33 | };
|
34 | 34 |
|
35 |
| - const buildButton = () => { |
| 35 | + const init = () => { |
36 | 36 | if (!$(".ghdt-toggle")) {
|
37 |
| - const button = make({ |
| 37 | + const toggleButton = make({ |
38 | 38 | el: "button",
|
39 | 39 | className: "btn btn-sm ghdt-toggle tooltipped tooltipped-s float-right",
|
40 | 40 | text: "Toggle viewed",
|
41 | 41 | attrs: {
|
42 | 42 | "aria-label": "Toggle all viewed files"
|
43 | 43 | }
|
44 | 44 | });
|
45 |
| - on(button, "click", event => { |
| 45 | + on(toggleButton, "click", event => { |
46 | 46 | toggle(document, !event.target.classList.contains("ghdt-selected"));
|
47 | 47 | });
|
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); |
49 | 53 | }
|
50 |
| - // Update toggle button state after initialized; timer for progressive |
51 |
| - // loading |
| 54 | + // Update toggle button state after initialized; timer for progressive loading |
52 | 55 | clearTimeout(timer);
|
53 | 56 | timer = setTimeout(() => {
|
54 | 57 | if ($$(".js-reviewed-checkbox").every(el => el.checked)) {
|
|
78 | 81 | }
|
79 | 82 | };
|
80 | 83 |
|
81 |
| - const init = () => { |
82 |
| - if ($("#files.diff-view") || $(".pr-toolbar")) { |
83 |
| - buildButton(); |
84 |
| - } |
85 |
| - }; |
86 |
| - |
87 | 84 | on(document, "ghmo:container ghmo:diff", init);
|
88 | 85 | on(document, "click", debounce(handleChange));
|
89 | 86 | on(document, "keydown", debounce(handleChange));
|
|
0 commit comments