Compare commits

..

No commits in common. "f7276dcb3d170760d7c60f1f449b0bd66c8e4031" and "92fc3dd021a72c57005513b81f417e7cbab7d646" have entirely different histories.

8 changed files with 27 additions and 179 deletions

View File

@ -1,4 +1,4 @@
all: *.json *.js img/* *.md *.txt
bitbucket-fork-redirect.zip: *.json *.js img/* *.md *.txt
zip -r bitbucket-fork-redirect.zip * -x .git/* -x img/screenshot.png -x .gitignore -x Makefile
clean:

View File

@ -44,24 +44,24 @@ const keywordMap = {
const bookendedWith = (text, bookend) => text.startsWith(bookend) && text.endsWith(bookend)
const getClass = (text, prefix, keywords) => {
const getClass = (text, keywords) => {
if (keywords.has(text)) {
return prefix + 'keyword'
return 'hl-keyword'
}
if (bookendedWith(text, '"')) {
return prefix + 'string'
return 'hl-string'
}
return prefix + 'variable'
return 'hl-variable'
}
const getKeywords = () => keywordMap[getFileName()?.replace(/.*\./g, '')] || keywordMap.none
const getKeywords = () => keywordMap[getFileName().replace(/.*\./g, '')] || keywordMap.none
const commentSpan = (innerText, prefix) => {
const commentSpan = innerText => {
const span = document.createElement('span')
span.innerText = innerText
span.classList.add(prefix + 'comment')
span.classList.add('hl-comment')
return span
}
@ -69,29 +69,24 @@ const colorCodeInComment = (codeStart = '`', codeEnd) => {
codeEnd ??= codeStart
const processed = new Set()
const keywords = getKeywords()
const comments = [...getClassNameElementsArray('hl-comment'), ...getClassNameElementsArray('cm-comment')]
comments.forEach(element => {
const codeStartIndex = element.innerText?.indexOf(codeStart)
if (codeStartIndex === -1 || processed.has(element)) {
getClassNameElementsArray('hl-comment').forEach(element => {
if (!element.innerText?.startsWith(codeStart) || processed.has(element)) {
return
}
const prefix = element.classList.contains('hl-comment') ? 'hl-' : 'cm-'
const endOfCodeStart = codeStartIndex + codeStart.length
const codeStartText = element.innerText.substring(0, endOfCodeStart)
const codeStartElement = commentSpan(codeStartText, prefix)
element.innerText = element.innerText.substring(endOfCodeStart, element.innerText.length)
const codeStartElement = commentSpan(codeStart)
element.replaceWith(codeStartElement, element)
element.innerText = element.innerText.replace(codeStart, '')
while (element) {
if (!element.classList.contains('hl-comment') && !element.classList.contains('cm-comment')) {
if (!element.classList.contains('hl-comment')) {
break
}
processed.add(element)
element.classList.remove(`${prefix}comment`)
element.classList.remove('hl-comment')
const text = element.innerText.replaceAll(codeStart, '').replaceAll(codeEnd, '')
element.classList.add(getClass(text, prefix, keywords))
element.classList.add(getClass(text, keywords))
const codeEndIndex = element.innerText.indexOf(codeEnd)
if (codeEndIndex > -1) {
const codeEndElement = commentSpan(element.innerText.substring(codeEndIndex), prefix)
const codeEndElement = commentSpan(element.innerText.substring(codeEndIndex))
element.innerText = element.innerText.substring(0, codeEndIndex)
element.replaceWith(element, codeEndElement)
break

View File

@ -1,5 +1,5 @@
const fixCSharpStrings = () => {
const hasCSharpFileName = getFileName()?.endsWith('.cs')
const hasCSharpFileName = getFileName().endsWith('.cs')
if (!hasCSharpFileName) {
return
}

View File

@ -1,79 +0,0 @@
const getChangeHeader = () => getClassNameElementsArray('change-header')[0]
const getFileElements = () => querySelectorAllArray('.file,.icon-folder-closed')
const getSelectedFile = () => getClassNameElementsArray('file-selected')[0]
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')
}
hint.innerText = `${prefix} ${decodeURIComponent(fileElement.firstElementChild?.href?.split('#')[1] || 'In Folder...')}`
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) {
breadcrumbs.prepend(buildHint(fileElements[index - 1], 'Prev:', '1.4em'))
}
if (index < fileElements.length - 1) {
breadcrumbs.appendChild(buildHint(fileElements[index + 1], 'Next:'))
}
}
const changeFile = (e, noRecurse) => {
const selectedFile = getSelectedFile()
const fileElements = getFileElements()
const up = e.wheelDelta ? e.wheelDelta > 0 : e.deltaY < 0
const index = fileElements.indexOf(selectedFile)
const nextElement =
(up && index > 0) ? fileElements[index - 1] :
(!up && index < (fileElements.length - 1)) ? fileElements[index + 1] :
null
const isFolder = !nextElement?.firstElementChild
const toClick = nextElement?.firstElementChild ?? nextElement
toClick?.focus()
toClick?.click()
if (isFolder) {
changeFile(e)
}
}
let styled = false
addFix(() => {
const header = getChangeHeader()
header.onwheel = changeFile
styled || addStyle(`
.sages-extra-breadcrumbs {
color: rgba(0, 0, 0, 0) !important;
margin-top: -1.6em !important;
/*margin-bottom: -1em !important;*/
float: left !important;
position: absolute;
font-size: 11px;
margin-left: 20%;
}
.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
})
window.addEventListener('load', () => setTimeout(addScrollHints, NEW_PAGE_DELAY))
addEventListener('hashchange', () => setTimeout(addScrollHints, 200))

View File

@ -1,12 +1,11 @@
{
"name": "Sage's BitBucket Addon",
"description": "Ensure searches don't include forks (and other enhancements)",
"version": "1.0.13",
"name": "ADD Git NoFork",
"description": "Ensure searches don't include forks",
"version": "1.0.2",
"manifest_version": 2,
"browser_specific_settings": {
"gecko": {
"id": "svaillancourt@add123.com",
"update_url": "https://bb-addon.sagev.space/updates.json"
"id": "svaillancourt@add123.com"
}
},
"background": {
@ -26,11 +25,8 @@
"matches": ["*://git.add123.com/*"],
"js": [
"utils.js",
"all-ADD-repos.js",
"backtick-comments.js",
"csharp-quotes.js",
"file-scroll.js",
"repo-search-sorter.js",
"backtick-comments.js",
"var-highlighter.js"
],
"run_at": "document_start"

View File

@ -1,36 +0,0 @@
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]
if (!searchBox) {
return
}
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)

View File

@ -2,25 +2,12 @@ const NEW_PAGE_DELAY = 1000
const CURRENT_PAGE_DELAY = 300
const getClassNameElementsArray = className =>
Array.from(document.getElementsByClassName(className))
Object.values(document.getElementsByClassName(className))
const querySelectorAllArray = selector =>
Array.from(document.querySelectorAll(selector))
/// Runs on "complete" load and when `https://website.tld#this-hash-value` changes
// Runs on "complete" load and when https://urlurl.url#this-hash-value changes
const addFix = fixFunc => {
window.addEventListener('load', () => setTimeout(fixFunc, NEW_PAGE_DELAY))
addEventListener('hashchange', () => setTimeout(fixFunc, CURRENT_PAGE_DELAY))
}
const getFileName = () => getClassNameElementsArray('file-breadcrumbs-segment-highlighted').map(e => e.innerText)[0]
const getCurrentUser = () => {
return getClassNameElementsArray("user-dropdown-trigger")[0].title.replace(/(.*\()|\)/g, '')
}
const addStyle = css => {
const styleElement = document.createElement('style')
styleElement.innerText = css.replaceAll("\n", " ")
document.head.appendChild(styleElement)
}

View File

@ -1,44 +1,29 @@
const getVarElements = () => [
...getClassNameElementsArray('hl-variable'),
...getClassNameElementsArray('hl-variable-2'),
...getClassNameElementsArray('hl-def'),
...getClassNameElementsArray('hl-attribute'),
...getClassNameElementsArray('hl-property'),
...getClassNameElementsArray('hl-tag'),
...getClassNameElementsArray('hl-string'),
...getClassNameElementsArray('hl-string-2'),
...getClassNameElementsArray('hl-type')
]
const selectedClass = 'sages-selected-variable'
let currentSelected
const cleanVarName = varName => {
if (varName.startsWith('/') && varName.endsWith('>')) {
varName = varName.substring(1, varName.length - 1)
}
varName = varName.replaceAll('"', "'")
return varName
}
const selectVar = varName => {
if (!varName) {
return
}
varName = cleanVarName(varName)
// Clear existing colors
getClassNameElementsArray(selectedClass)
.forEach(e => e.classList.remove(selectedClass))
// Color vars with matching text
getVarElements()
.filter(e => cleanVarName(e.innerText) === varName)
.filter(e => e.innerText === varName)
.forEach(e => e.classList.add(selectedClass))
currentSelected = varName
}
const selectedClass = 'sages-selected-variable'
const getTagMatching = (name, matcher) => {
const elements = Object.values(document.getElementsByTagName(name)).filter(matcher)
return elements.length ? elements[0] : null