diff options
author | 2022-11-04 12:29:36 +0700 | |
---|---|---|
committer | 2022-11-04 12:29:36 +0700 | |
commit | 075de6a90511ed7ba3ef551763f60a487ebc792d (patch) | |
tree | 30c2461fac44f2ffdeabc421e79df9ca06ab9329 /source/features/clean-repo-filelist-actions.tsx | |
parent | 5315d387f8fd164b92d7db2e13af394985ebf1e3 (diff) | |
download | refined-github-075de6a90511ed7ba3ef551763f60a487ebc792d.tar.gz refined-github-075de6a90511ed7ba3ef551763f60a487ebc792d.tar.zst refined-github-075de6a90511ed7ba3ef551763f60a487ebc792d.zip |
Meta: Safer text node targeting (#6076)
Co-authored-by: Flo Edelmann <florian-edelmann@online.de>
Diffstat (limited to 'source/features/clean-repo-filelist-actions.tsx')
-rw-r--r-- | source/features/clean-repo-filelist-actions.tsx | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/source/features/clean-repo-filelist-actions.tsx b/source/features/clean-repo-filelist-actions.tsx index 19461ece..37695717 100644 --- a/source/features/clean-repo-filelist-actions.tsx +++ b/source/features/clean-repo-filelist-actions.tsx @@ -4,7 +4,7 @@ import * as pageDetect from 'github-url-detection'; import {PlusIcon, SearchIcon, CodeIcon} from '@primer/octicons-react'; import observe from '../helpers/selector-observer'; -import {wrap} from '../helpers/dom-utils'; +import {assertNodeContent, removeTextNodeContaining, wrap} from '../helpers/dom-utils'; import features from '../feature-manager'; /** Add tooltip on a wrapper to avoid breaking dropdown functionality */ @@ -27,8 +27,9 @@ function cleanFilelistActions(searchButton: Element): void { if (addFileDropdown) { addFileDropdown.parentElement!.classList.replace('d-md-flex', 'd-md-block'); - // Replace "Add file" with icon - addFileDropdown.previousSibling!.replaceWith(<PlusIcon/>); + // Replace label with icon + assertNodeContent(addFileDropdown.previousSibling, 'Add file') + .replaceWith(<PlusIcon/>); addTooltipToSummary(addFileDropdown, 'Add file'); } @@ -40,11 +41,10 @@ function cleanFilelistActions(searchButton: Element): void { // Users with Codespaces enabled already have an icon in the button https://github.com/refined-github/refined-github/pull/5074#issuecomment-983251719 const codeIcon = select('.octicon-code', codeDropdownButton); if (codeIcon) { - // Remove "Code" text - codeIcon.nextSibling!.remove(); + removeTextNodeContaining(codeIcon.nextSibling!, 'Code'); } else { - // Replace "Code" text with icon - codeDropdownButton.firstChild!.replaceWith(<CodeIcon/>); + removeTextNodeContaining(codeDropdownButton.firstChild!, 'Code'); + codeDropdownButton.prepend(<CodeIcon/>); } } } |