Browse Source

Sort milestones by closest due date (#457)

* Changes the default sort order of milestones to "Closest due date"

* Affect all links pointing to milestones
master
Stephan Meijer 7 years ago
committed by Sindre Sorhus
parent
commit
eefdb2c02d
  1. 1
      readme.md
  2. 14
      src/content.js
  3. 6
      src/libs/page-detect.js

1
readme.md

@ -141,6 +141,7 @@ GitHub Enterprise is also supported by [authorizing your own domain in the optio
- Easier copy-pasting from diffs by making +/- signs unselectable
- Automagically expands the news feed when you scroll down
- Shows the reactions popover on hover instead of click
- Changes the default sort order of milestones to "Closest due date"
And [lots](extension/content.css) [more...](src/content.js)

14
src/content.js

@ -473,6 +473,18 @@ function addTitleToEmojis() {
}
}
function sortMilestonesByClosestDueDate() {
for (const a of select.all('a[href$="/milestones"], a[href*="/milestones?"]')) {
const url = new URL(a.href);
// Only if they aren't explicitly sorted differently
if (!url.searchParams.get('direction') && !url.searchParams.get('sort')) {
url.searchParams.set('direction', 'asc');
url.searchParams.set('sort', 'due_date');
a.href = url;
}
}
}
function init() {
if (select.exists('html.refined-github')) {
console.count('Refined GitHub was loaded multiple times: https://github.com/sindresorhus/refined-github/issues/479');
@ -643,6 +655,8 @@ async function onDomReady() {
if (pageDetect.isRepoSettings()) {
addProjectNewLink();
}
sortMilestonesByClosestDueDate(); // Needs to be after addMilestoneNavigation
});
}
}

6
src/libs/page-detect.js

@ -30,8 +30,14 @@ export const isPRFiles = () => isRepo() && /^\/pull\/\d+\/files/.test(getRepoPat
export const isPRCommit = () => isRepo() && /^\/pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(getRepoPath());
export const isMilestoneList = () => isRepo() && /^\/milestones\/?$/.test(getRepoPath());
export const isMilestone = () => isRepo() && /^\/milestone\/\d+/.test(getRepoPath());
export const isLabelList = () => isRepo() && /^\/labels\/?(((?=\?).*)|$)/.test(getRepoPath());
export const isLabel = () => isRepo() && /^\/labels\/\w+/.test(getRepoPath());
export const isCommitList = () => isRepo() && /^\/commits\//.test(getRepoPath());
export const isSingleCommit = () => isRepo() && /^\/commit\/[0-9a-f]{5,40}/.test(getRepoPath());

Loading…
Cancel
Save