2023-02-07 14:01:47 -05:00
|
|
|
const getChangeHeader = () => getClassNameElementsArray('change-header')[0]
|
|
|
|
|
2023-12-04 10:04:20 -05:00
|
|
|
const getFileElements = () => querySelectorAllArray('.file,.icon-folder-closed')
|
2023-02-07 14:01:47 -05:00
|
|
|
|
|
|
|
const getSelectedFile = () => getClassNameElementsArray('file-selected')[0]
|
|
|
|
|
2023-02-07 15:04:56 -05:00
|
|
|
const addScrollHints = () => {
|
|
|
|
getClassNameElementsArray('sages-extra-breadcrumbs').forEach(e => e.parentNode.removeChild(e))
|
|
|
|
const buildHint = (fileElement, prefix, top) => {
|
|
|
|
const hint = document.createElement('div', {})
|
|
|
|
hint.classList.add('sages-extra-breadcrumbs')
|
|
|
|
if (fileElement.classList.contains('file-viewed')) {
|
|
|
|
hint.classList.add('sages-extra-breadcrumbs-viewed')
|
|
|
|
}
|
2023-12-04 10:53:33 -05:00
|
|
|
hint.innerText = `${prefix} ${decodeURIComponent(fileElement.firstElementChild?.href?.split('#')[1] || 'In Folder...')}`
|
2023-02-07 15:04:56 -05:00
|
|
|
if (top) {
|
|
|
|
hint.style.top = top
|
|
|
|
}
|
|
|
|
return hint;
|
|
|
|
}
|
|
|
|
const selectedFile = getSelectedFile()
|
|
|
|
const fileElements = getFileElements()
|
|
|
|
const index = fileElements.indexOf(selectedFile)
|
|
|
|
const breadcrumbs = Array.from(getChangeHeader().getElementsByTagName('h4'))[0]
|
|
|
|
console.log({ breadcrumbs })
|
|
|
|
if (index > 0) {
|
2023-02-07 15:14:06 -05:00
|
|
|
breadcrumbs.prepend(buildHint(fileElements[index - 1], 'Prev:', '1.4em'))
|
2023-02-07 15:04:56 -05:00
|
|
|
}
|
|
|
|
if (index < fileElements.length - 1) {
|
|
|
|
breadcrumbs.appendChild(buildHint(fileElements[index + 1], 'Next:'))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-12-04 10:53:33 -05:00
|
|
|
const changeFile = (e, noRecurse) => {
|
2023-02-07 14:01:47 -05:00
|
|
|
const selectedFile = getSelectedFile()
|
|
|
|
const fileElements = getFileElements()
|
2023-02-07 15:04:56 -05:00
|
|
|
|
|
|
|
const up = e.wheelDelta ? e.wheelDelta > 0 : e.deltaY < 0
|
2023-02-07 14:01:47 -05:00
|
|
|
const index = fileElements.indexOf(selectedFile)
|
|
|
|
const nextElement =
|
|
|
|
(up && index > 0) ? fileElements[index - 1] :
|
|
|
|
(!up && index < (fileElements.length - 1)) ? fileElements[index + 1] :
|
|
|
|
null
|
2023-12-04 10:53:33 -05:00
|
|
|
const isFolder = !nextElement?.firstElementChild
|
2023-12-04 10:04:20 -05:00
|
|
|
const toClick = nextElement?.firstElementChild ?? nextElement
|
|
|
|
toClick?.focus()
|
|
|
|
toClick?.click()
|
2023-12-04 10:53:33 -05:00
|
|
|
if (isFolder) {
|
|
|
|
changeFile(e)
|
|
|
|
}
|
2023-02-07 14:01:47 -05:00
|
|
|
}
|
|
|
|
|
2023-02-07 15:04:56 -05:00
|
|
|
let styled = false
|
2023-02-07 14:01:47 -05:00
|
|
|
addFix(() => {
|
|
|
|
const header = getChangeHeader()
|
|
|
|
header.onwheel = changeFile
|
2023-02-07 15:04:56 -05:00
|
|
|
styled || addStyle(`
|
|
|
|
.sages-extra-breadcrumbs {
|
|
|
|
color: rgba(0, 0, 0, 0) !important;
|
2023-02-07 15:14:06 -05:00
|
|
|
margin-top: -1.6em !important;
|
2023-02-07 15:04:56 -05:00
|
|
|
/*margin-bottom: -1em !important;*/
|
|
|
|
float: left !important;
|
|
|
|
position: absolute;
|
|
|
|
font-size: 11px;
|
2023-02-07 15:14:06 -05:00
|
|
|
margin-left: 20%;
|
2023-02-07 15:04:56 -05:00
|
|
|
}
|
|
|
|
.diff-meta:hover h4 .sages-extra-breadcrumbs {
|
|
|
|
color: rgba(0, 0, 0, 0.35) !important;
|
|
|
|
}
|
|
|
|
.diff-meta:hover h4 .sages-extra-breadcrumbs-viewed {
|
|
|
|
color: rgba(0, 0, 0, 0.2) !important;
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
styled = true
|
2023-02-07 14:01:47 -05:00
|
|
|
})
|
2023-02-07 15:04:56 -05:00
|
|
|
|
|
|
|
window.addEventListener('load', () => setTimeout(addScrollHints, NEW_PAGE_DELAY))
|
2023-12-04 10:04:20 -05:00
|
|
|
addEventListener('hashchange', () => setTimeout(addScrollHints, 200))
|