Skip to content

Commit

Permalink
Change default issue/PR sort to Recently updated (refined-github#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Jan 4, 2018
1 parent 0495336 commit 757c805
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ GitHub Enterprise is also supported. More info in the options.
- 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"
- Changes the default sort order of issues/PRs to "Recently updated"

And [lots](source/content.css) [more...](source/content.js)

Expand Down
2 changes: 2 additions & 0 deletions source/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import embedGistInline from './features/embed-gist-inline';
import expandCollapseOutdatedComments from './features/expand-collapse-outdated-comments';
import addJumpToBottomLink from './features/add-jump-to-bottom-link';
import addQuickReviewButtons from './features/add-quick-review-buttons';
import sortIssuesByUpdateTime from './features/sort-issues-by-update-time';
import shortenLinks from './features/shorten-links';

import * as pageDetect from './libs/page-detect';
Expand Down Expand Up @@ -135,6 +136,7 @@ function ajaxedPagesHandler() {
enableFeature(hideEmptyMeta);
enableFeature(removeUploadFilesButton);
enableFeature(addTitleToEmojis);
enableFeature(sortIssuesByUpdateTime);
enableFeature(shortenLinks);
enableFeature(linkifyCode);

Expand Down
41 changes: 41 additions & 0 deletions source/features/sort-issues-by-update-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import select from 'select-dom';
import {getUsername} from '../libs/utils';

function getDefaultQuery(link) {
// Query-less URLs imply some queries.
// When we explicitly set ?q=* they're overridden,
// so they need to be manually added again.
const queries = [];

// Repo example: is:issue is:open
queries.push(/\/pulls\/?$/.test(link.pathname) ? 'is:pr' : 'is:issue');
queries.push('is:open');

// Header nav example: is:open is:issue author:you archived:false
if (link.pathname === '/issues' || link.pathname === '/pulls') {
queries.push(`author:${getUsername()}`);
queries.push('archived:false');
}
return queries.join(' ');
}

export default function () {
// Get issues links that don't already have a specific sorting applied
for (const link of select.all(`
[href*="/issues"]:not([href*="sort%3A"]):not(.issues-reset-query),
[href*="/pulls" ]:not([href*="sort%3A"]):not(.issues-reset-query)
`)) {
// Pick only links to lists, not single issues
if (/(issues|pulls)\/?$/.test(link.pathname)) {
const search = new URLSearchParams(link.search);
const existingQuery = search.get('q') || getDefaultQuery(link);
search.set('q', `${existingQuery} sort:updated-desc`);
link.search = search;
}
}

// Extra nicety: Avoid GitHub's unnecessary redirect, this is their own bug
for (const link of select.all('[href*="/issues"][href*="is%3Apr"]')) {
link.pathname = link.pathname.replace(/issues\/?$/, 'pulls');
}
}
5 changes: 5 additions & 0 deletions source/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,8 @@ export const groupButtons = buttons => {

return group;
};

export const anySelector = selector => {
const prefix = document.head.style.MozOrient === '' ? 'moz' : 'webkit';
return selector.replace(/:any\(/g, `:-${prefix}-any(`);
};

0 comments on commit 757c805

Please sign in to comment.