2023-02-02 15:57:09 -05:00
|
|
|
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]
|
2023-02-07 14:01:47 -05:00
|
|
|
if (!searchBox) {
|
|
|
|
return
|
|
|
|
}
|
2023-02-02 15:57:09 -05:00
|
|
|
searchBox.onkeyup = e => {
|
|
|
|
claim++
|
|
|
|
const myClaim = claim
|
|
|
|
setTimeout(() => {
|
2023-02-07 14:01:47 -05:00
|
|
|
if (claim !== myClaim) {
|
2023-02-02 15:57:09 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
const ol = getClassNameElementsArray('search-results')[0]?.firstChild
|
|
|
|
sortChildren(ol)
|
|
|
|
claim = 0
|
|
|
|
}, 1000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addFix(sortSearchResult)
|