Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created December 15, 2022 19:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderberry/5c10ba13bb78388488f95189b18e96ed to your computer and use it in GitHub Desktop.
Save coderberry/5c10ba13bb78388488f95189b18e96ed to your computer and use it in GitHub Desktop.
Inserts a button that can toggle the "viewed" checkboxes when reviewing a PR on Github.
const url = document.URL;
class ReviewToggle {
insertButton() {
const parentElement = document.querySelector(".pr-review-tools");
let button = document.querySelector('#boost-toggle-checkboxes');
if (!button) {
button = document.createElement("button");
button.id = "boost-toggle-checkboxes";
}
button.onclick = this.toggleAll.bind(this);
button.title = "Toggle Viewed";
button.setAttribute('data-turbo-permanent', true);
["diffbar-item", "btn", "btn-sm", "js-details-target", "d-inline-block", "float-none", "m-0", "mr-md-0"].forEach((c) => {
button.classList.add(c);
});
button.style = "color: white; background-color: #24292f; font-weight: 200; font-size: 18px; padding-left: 6px; padding-right: 6px; margin-left: 6px !important;";
button.innerHTML = '☑';
parentElement.appendChild(button);
}
toggleAll() {
document.querySelectorAll(".js-reviewed-checkbox").forEach((elem => {
let clickEvent = new MouseEvent("click");
elem.dispatchEvent(clickEvent);
}));
}
}
function displayButton() {
if (url.match(/https:\/\/github.com\/.*\/.*\/pull\/\d+\/files/)) {
new ReviewToggle().insertButton();
}
}
document.addEventListener('turbo:load', (event) => {
displayButton();
});
displayButton();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment