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