From 01e6016419554eb4ed5dfa220d2391407dff6d43 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Thu, 27 Oct 2022 09:45:30 +0530 Subject: [PATCH] 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. --- github-diff-file-toggle.user.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/github-diff-file-toggle.user.js b/github-diff-file-toggle.user.js index ee081c4..7ab3b38 100644 --- a/github-diff-file-toggle.user.js +++ b/github-diff-file-toggle.user.js @@ -26,15 +26,15 @@ 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", @@ -42,13 +42,16 @@ "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)) { @@ -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));