Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions github-diff-file-toggle.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,32 @@

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",
attrs: {
"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)) {
Expand Down Expand Up @@ -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));
Expand Down