Last active
February 21, 2023 23:54
-
-
Save davidmigloz/42e3916bd3344b9ba83835dea380a9f8 to your computer and use it in GitHub Desktop.
tampermonkey.net script to mark vendor files as viewed in GitHub PRs
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
// ==UserScript== | |
// @name mark_vendor_viewed | |
// @description Mark all vendor files as viewed in PRs | |
// @author David Miguel | |
// @version 1.0 | |
// @namespace https://github.com/davidmigloz | |
// @match *://github.com/*/*/pull/*/files | |
// ==/UserScript== | |
(() => { | |
const markVendorBtn = document.createElement('button') | |
markVendorBtn.textContent = "Mark Vendor Files" | |
markVendorBtn.style.marginLeft = '12px' | |
markVendorBtn.classList.add('btn', 'btn-sm') | |
const toolbar = document.querySelector('.pr-review-tools') | |
toolbar.prepend(markVendorBtn) | |
markVendorBtn.addEventListener('click', () => { | |
const checkboxes = Array.from(document.querySelectorAll("[data-path*='/vendor/'] input[type='checkbox'][name='viewed']")); | |
processCheckboxes(checkboxes); | |
}) | |
})(); | |
function processCheckboxes(arr) { | |
if (arr.length === 0) { | |
return; | |
} | |
const checkbox = arr[0]; | |
if(!checkbox.checked) { | |
checkbox.click(); | |
console.log("Checked!"); | |
} else { | |
console.log("Skipped!"); | |
} | |
const delay = checkbox.checked ? 10 : 300; // To prevent throttling from GitHub API | |
setTimeout(() => processCheckboxes(arr.slice(1)), delay); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script adds a "Mark Vendor Files" button next to the "Review changes" button. If you don't see it, try refreshing the page.
Make sure to scroll down before clicking the button so that all the files in the PR are loaded.