Add some varName sanitization.

This commit is contained in:
Sage Vaillancourt 2023-12-04 10:23:47 -05:00
parent ab9f6641f4
commit 46b873e71d
3 changed files with 15 additions and 5 deletions

View File

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

View File

@ -1,7 +1,7 @@
{ {
"name": "Sage's BitBucket Addon", "name": "Sage's BitBucket Addon",
"description": "Ensure searches don't include forks (and other enhancements)", "description": "Ensure searches don't include forks (and other enhancements)",
"version": "1.0.10", "version": "1.0.11",
"manifest_version": 2, "manifest_version": 2,
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {

View File

@ -6,29 +6,39 @@ const getVarElements = () => [
...getClassNameElementsArray('hl-property'), ...getClassNameElementsArray('hl-property'),
...getClassNameElementsArray('hl-tag'), ...getClassNameElementsArray('hl-tag'),
...getClassNameElementsArray('hl-string'), ...getClassNameElementsArray('hl-string'),
...getClassNameElementsArray('hl-string-2'),
...getClassNameElementsArray('hl-type') ...getClassNameElementsArray('hl-type')
] ]
const selectedClass = 'sages-selected-variable'
let currentSelected 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 => { const selectVar = varName => {
if (!varName) { if (!varName) {
return return
} }
varName = cleanVarName(varName)
// Clear existing colors // Clear existing colors
getClassNameElementsArray(selectedClass) getClassNameElementsArray(selectedClass)
.forEach(e => e.classList.remove(selectedClass)) .forEach(e => e.classList.remove(selectedClass))
// Color vars with matching text // Color vars with matching text
getVarElements() getVarElements()
.filter(e => e.innerText === varName) .filter(e => cleanVarName(e.innerText) === varName)
.forEach(e => e.classList.add(selectedClass)) .forEach(e => e.classList.add(selectedClass))
currentSelected = varName currentSelected = varName
} }
const selectedClass = 'sages-selected-variable'
const getTagMatching = (name, matcher) => { const getTagMatching = (name, matcher) => {
const elements = Object.values(document.getElementsByTagName(name)).filter(matcher) const elements = Object.values(document.getElementsByTagName(name)).filter(matcher)
return elements.length ? elements[0] : null return elements.length ? elements[0] : null