forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change default issue/PR sort to Recently updated (refined-github#935)
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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'); | ||
} | ||
} |
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