Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save beccasaurus/eb9e91a877046939b7b548a2dfb57ef0 to your computer and use it in GitHub Desktop.
Save beccasaurus/eb9e91a877046939b7b548a2dfb57ef0 to your computer and use it in GitHub Desktop.
馃悪 GitHub 谈pulls 馃悎 Custom Button (Saved Search)

Screenshot of GitHub pulls page with custom button added

... because I got annoyed that PRs disappear from the dashboard after submitting a review...
... even it the PR is still very active, it's basically out of sight / out of mind ...
... 45 LOC to make my life easier ... 馃

curl -LO https://gist.github.com/beccasaurus/eb9e91a877046939b7b548a2dfb57ef0/archive/master.zip
unzip master.zip

chrome://extensions
馃敇 Developer mode
Load unpacked (directory you unzipped into)

open https://github.com/pulls
/*
* User Configured Additional Tab on /pulls page
*/
const BUTTON_LABEL = "Reviewed"
const BUTTON_DESCRIPTION = "Pull Requests reviewed by you"
const SEARCH_QUERY = "is:open is:pr reviewed-by:beccasaurus archived:false"
// TODO ^ make this configurable with a simple Options Page ^
/*
* Implementation Code Below (make it go!)
*/
const BUTTONS_CONTAINER_SELECTOR = ".page-content .subnav-links"
const BUTTON_ITEMS_SELECTOR = ".page-content .subnav-links > a.subnav-item"
const query = SEARCH_QUERY.replace(" ", "+").replace(":", encodeURIComponent(":"))
const link = "/pulls?q=" + query
var myButton = document.createElement("a");
myButton.href = link;
myButton.innerText = BUTTON_LABEL;
myButton.setAttribute("aria-label", BUTTON_DESCRIPTION);
myButton.setAttribute("role", "tab");
myButton.classList.add("js-selected-navigation-item", "subnav-item");
// Make the search box smaller to make room for extra tab.
// Or else the search box will fall onto a new line (wicked ugly).
document.getElementById("js-issues-search").style.width = "450px";
// Add our button!
var buttonsContainer = document.querySelector(BUTTONS_CONTAINER_SELECTOR);
buttonsContainer.appendChild(myButton);
// If we click any of the tabs, the JS takes over and will re-render tabs,
// removing our custom tab :'(
//
// Instead, let's update all of the links so that they perform a full page
// navigation with a page refresh when clicked (which persists our custom tab)
document.querySelectorAll(BUTTON_ITEMS_SELECTOR).forEach(link => {
link.onclick = _ => {
window.location.href = link.href
return false;
}
});
{
"name": "GitHub /pulls Custom Tab",
"version": "1.0",
"description": "Add a custom tab to your GitHub /pulls page for a saved search!",
"manifest_version": 2,
"content_scripts":
[
{
"run_at": "document_end",
"matches": ["https://github.com/pulls*"],
"js": ["addCustomButton.js"]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment