Created
December 15, 2022 19:12
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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