From 46b873e71d3bdcdd4a54253dc5f09885a5c225d6 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Mon, 4 Dec 2023 10:23:47 -0500 Subject: [PATCH] Add some varName sanitization. --- Makefile | 2 +- manifest.json | 2 +- var-highlighter.js | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ad9ac9c..fc31e3e 100644 --- a/Makefile +++ b/Makefile @@ -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 clean: diff --git a/manifest.json b/manifest.json index efa6192..ed4b6da 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Sage's BitBucket Addon", "description": "Ensure searches don't include forks (and other enhancements)", - "version": "1.0.10", + "version": "1.0.11", "manifest_version": 2, "browser_specific_settings": { "gecko": { diff --git a/var-highlighter.js b/var-highlighter.js index 9fd4eef..858549c 100644 --- a/var-highlighter.js +++ b/var-highlighter.js @@ -6,29 +6,39 @@ const getVarElements = () => [ ...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 => e.innerText === varName) + .filter(e => cleanVarName(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