Sort repo search results.
Prioritizes shared project repos and the current user's repos before other users'
This commit is contained in:
parent
92fc3dd021
commit
bee9f4e2b2
|
@ -56,7 +56,7 @@ const getClass = (text, keywords) => {
|
||||||
return 'hl-variable'
|
return 'hl-variable'
|
||||||
}
|
}
|
||||||
|
|
||||||
const getKeywords = () => keywordMap[getFileName().replace(/.*\./g, '')] || keywordMap.none
|
const getKeywords = () => keywordMap[getFileName()?.replace(/.*\./g, '')] || keywordMap.none
|
||||||
|
|
||||||
const commentSpan = innerText => {
|
const commentSpan = innerText => {
|
||||||
const span = document.createElement('span')
|
const span = document.createElement('span')
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const fixCSharpStrings = () => {
|
const fixCSharpStrings = () => {
|
||||||
const hasCSharpFileName = getFileName().endsWith('.cs')
|
const hasCSharpFileName = getFileName()?.endsWith('.cs')
|
||||||
if (!hasCSharpFileName) {
|
if (!hasCSharpFileName) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "ADD Git NoFork",
|
"name": "Sage's BitBucket Addon",
|
||||||
"description": "Ensure searches don't include forks",
|
"description": "Ensure searches don't include forks (and other enhancements)",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"browser_specific_settings": {
|
"browser_specific_settings": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
|
@ -25,8 +25,9 @@
|
||||||
"matches": ["*://git.add123.com/*"],
|
"matches": ["*://git.add123.com/*"],
|
||||||
"js": [
|
"js": [
|
||||||
"utils.js",
|
"utils.js",
|
||||||
"csharp-quotes.js",
|
|
||||||
"backtick-comments.js",
|
"backtick-comments.js",
|
||||||
|
"csharp-quotes.js",
|
||||||
|
"repo-search-sorter.js",
|
||||||
"var-highlighter.js"
|
"var-highlighter.js"
|
||||||
],
|
],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
const compareResults = currentUser => (a, b) => {
|
||||||
|
return ['/projects/', currentUser]
|
||||||
|
.some(href => a.children[0].href.includes(href)) ? -1 : 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortChildren = ol => {
|
||||||
|
const children = Array.from(ol.children)
|
||||||
|
children.forEach(child => ol.removeChild(child))
|
||||||
|
children
|
||||||
|
.sort(compareResults(getCurrentUser()))
|
||||||
|
.forEach(child => ol.appendChild(child))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Re-order the search results to list projects and the current user first
|
||||||
|
let claim = 0
|
||||||
|
const sortSearchResult = () => {
|
||||||
|
const searchBox = Array.from(document.getElementsByTagName('input'))
|
||||||
|
.filter(input => input.name === 'repository-search')[0]
|
||||||
|
searchBox.onkeyup = e => {
|
||||||
|
claim++
|
||||||
|
const myClaim = claim
|
||||||
|
setTimeout(() => {
|
||||||
|
if (claim != myClaim) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const ol = getClassNameElementsArray('search-results')[0]?.firstChild
|
||||||
|
sortChildren(ol)
|
||||||
|
claim = 0
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addFix(sortSearchResult)
|
6
utils.js
6
utils.js
|
@ -2,7 +2,7 @@ const NEW_PAGE_DELAY = 1000
|
||||||
const CURRENT_PAGE_DELAY = 300
|
const CURRENT_PAGE_DELAY = 300
|
||||||
|
|
||||||
const getClassNameElementsArray = className =>
|
const getClassNameElementsArray = className =>
|
||||||
Object.values(document.getElementsByClassName(className))
|
Array.from(document.getElementsByClassName(className))
|
||||||
|
|
||||||
// Runs on "complete" load and when https://urlurl.url#this-hash-value changes
|
// Runs on "complete" load and when https://urlurl.url#this-hash-value changes
|
||||||
const addFix = fixFunc => {
|
const addFix = fixFunc => {
|
||||||
|
@ -11,3 +11,7 @@ const addFix = fixFunc => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFileName = () => getClassNameElementsArray('file-breadcrumbs-segment-highlighted').map(e => e.innerText)[0]
|
const getFileName = () => getClassNameElementsArray('file-breadcrumbs-segment-highlighted').map(e => e.innerText)[0]
|
||||||
|
|
||||||
|
const getCurrentUser = () => {
|
||||||
|
return getClassNameElementsArray("user-dropdown-trigger")[0].title.replace(/(.*\()|\)/g, '')
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue