Last active
February 23, 2021 20:07
-
-
Save tannermares/51b1962ecc2bbaffb9ba to your computer and use it in GitHub Desktop.
Toggle "NOT READY!" PRs, Toggle +2 PR's
This file contains 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 GitHub Pull Request Enhancements | |
// @namespace http://tannermar.es | |
// @version 1.3 | |
// @description Easily toggle visibility of "NOT READY", +2, and needed review PR's | |
// @match https://github.com/ministrycentered/services/pulls | |
// @require https://code.jquery.com/jquery-3.3.1.min.js | |
// @copyright 2021+, @tannermares | |
// ==/UserScript== | |
function pullRequestListPage() { | |
return !!window.location.href.match(/pulls/) | |
} | |
function hideNotReviewedButtonAlreadyPresent() { | |
return $('.hide-not-reviewed-js').length > 0 | |
} | |
function hideNotReadyButtonAlreadyPresent() { | |
return $('.hide-not-ready-js').length > 0 | |
} | |
function hidePlusTwoButtonAlreadyPresent() { | |
return $('.hide-plus-two-js').length > 0 | |
} | |
function hideNotReadyButton() { | |
if (hideNotReadyButtonAlreadyPresent() || !pullRequestListPage()) return | |
const filteringNotready = window.location.search.match( | |
/\+-label%3A%22NOT\+READY%22/ | |
) | |
const href = filteringNotready | |
? window.location.href.replace(/\+-label%3A%22NOT\+READY%22/, '') | |
: window.location.search.length > 0 | |
? `${window.location.href}+-label%3A"NOT+READY"` | |
: `${window.location.href}?q=is%3Aopen+is%3Apr+-label%3A"NOT+READY"` | |
const $button = $( | |
`<a href=${href} class="subnav-item hide-not-ready-js ${ | |
filteringNotready ? 'selected' : '' | |
}">Not Ready</button>` | |
) | |
$button.appendTo('.subnav-links') | |
} | |
function hidePlusTwoButton() { | |
if (hidePlusTwoButtonAlreadyPresent() || !pullRequestListPage()) return | |
const filteringPlusTwo = window.location.search.match(/\+-label%3A%2B2/) | |
const href = filteringPlusTwo | |
? window.location.href.replace(/\+-label%3A%2B2/, '') | |
: window.location.search.length > 0 | |
? `${window.location.href}+-label%3A%2B2` | |
: `${window.location.href}?q=is%3Aopen+is%3Apr+-label%3A%2B2` | |
const $button = $( | |
`<a href=${href} class="subnav-item hide-plus-two-js ${ | |
filteringPlusTwo ? 'selected' : '' | |
}">+2</button>` | |
) | |
$button.appendTo('.subnav-links') | |
} | |
function hideNotReviewedButton() { | |
if (hideNotReviewedButtonAlreadyPresent() || !pullRequestListPage()) return | |
const filteringNotReviewed = window.location.search.match( | |
/\+-reviewed-by%3A%40me/ | |
) | |
const href = filteringNotReviewed | |
? window.location.href.replace(/\+-reviewed-by%3A%40me/, '') | |
: window.location.search.length > 0 | |
? `${window.location.href}+-reviewed-by%3A%40me` | |
: `${window.location.href}?q=is%3Aopen+is%3Apr+-reviewed-by%3A%40me` | |
const $button = $( | |
`<a href=${href} class="subnav-item hide-not-reviewed-js ${ | |
filteringNotReviewed ? 'selected' : '' | |
}">Not Reviewed</button>` | |
) | |
$button.appendTo('.subnav-links') | |
} | |
function initButtons() { | |
hideNotReviewedButton() | |
hideNotReadyButton() | |
hidePlusTwoButton() | |
} | |
$(() => { | |
initButtons() | |
$(document).on('pjax:end', () => initButtons()) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment