Skip to content

Commit

Permalink
feat: Add a custom Sizzle pseudo-class selector :equal
Browse files Browse the repository at this point in the history
  • Loading branch information
赵思 committed Feb 10, 2023
1 parent d1dac2a commit 220587a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/utils/FindElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ import {
querySelectorDeep,
} from '@/lib/query-selector-shadow-dom';

const specialSelectors = [':contains', ':header', ':parent'];
// Add a custom "Sizzle" pseudo-class selector
// ":contains": element content will be selected as long as it contains text
// ":equal" : element content must be exactly the same as text to be selected
// Example: p.description:equal("cat")
Sizzle.selectors.pseudos.equal = Sizzle.selectors.createPseudo(function (text) {
return function (elem) {
const elemText = elem.textContent || elem.innerText || '';
return elemText.trim() === text;
};
});

const specialSelectors = [':contains', ':header', ':parent', ':equal'];
const specialSelectorsRegex = new RegExp(specialSelectors.join('|'));

class FindElement {
Expand Down

0 comments on commit 220587a

Please sign in to comment.