Skip to content

Instantly share code, notes, and snippets.

@davidmigloz
Last active February 21, 2023 23:54
Show Gist options
  • Select an option

  • Save davidmigloz/42e3916bd3344b9ba83835dea380a9f8 to your computer and use it in GitHub Desktop.

Select an option

Save davidmigloz/42e3916bd3344b9ba83835dea380a9f8 to your computer and use it in GitHub Desktop.
tampermonkey.net script to mark vendor files as viewed in GitHub PRs
// ==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);
}
@davidmigloz

davidmigloz commented Aug 18, 2022

Copy link
Copy Markdown
Author

The script adds a "Mark Vendor Files" button next to the "Review changes" button. If you don't see it, try refreshing the page.

image

Make sure to scroll down before clicking the button so that all the files in the PR are loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment