Skip to content

Commit

Permalink
CSSUtils.ts: make sure to return unique IDs
Browse files Browse the repository at this point in the history
Necessary because bad websites aren't standards compliant.
  • Loading branch information
glacambre committed May 18, 2020
1 parent d251119 commit 85d12f4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/CSSUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ export function guifontsToCSS(guifont: string) {
export function computeSelector(element: HTMLElement) {
function uniqueSelector(e: HTMLElement): string {
// Only matching alphanumeric selectors because others chars might have special meaning in CSS
if (e.id && e.id.match("^[a-zA-Z0-9_-]+$")) { return "#" + e.id; }
if (e.id && e.id.match("^[a-zA-Z0-9_-]+$")) {
const id = "#" + e.id;
if (document.querySelectorAll(id).length === 1) {
return id;
}
}
// If we reached the top of the document
if (!e.parentElement) { return "HTML"; }
// Compute the position of the element
Expand Down

0 comments on commit 85d12f4

Please sign in to comment.