MCPcopy Index your code
hub / github.com/darkreader/darkreader / getURLMatchesFromIndexedList

Function getURLMatchesFromIndexedList

src/utils/url.ts:493–600  ·  view source on GitHub ↗
(url: string, trie: URLTrie<T>, breakOnFirstMatch = false)

Source from the content-addressed store, hash-verified

491}
492
493export function getURLMatchesFromIndexedList<T>(url: string, trie: URLTrie<T>, breakOnFirstMatch = false): T[] {
494 const found = new Set<T>();
495 const matches: T[] = [];
496
497 const push = (data: T) => {
498 if (!found.has(data)) {
499 found.add(data);
500 matches.push(data);
501 }
502 };
503
504 for (const r of trie.regexps) {
505 if (r.regexp.test(url)) {
506 push(r.data);
507 if (breakOnFirstMatch) {
508 return matches;
509 }
510 }
511 }
512
513 const u = prepareURL(url);
514 if (!u) {
515 return matches;
516 }
517
518 for (const p of trie.hardPatterns) {
519 if (matchPreparedURLPattern(u, p.pattern)) {
520 push(p.data);
521 if (breakOnFirstMatch) {
522 return matches;
523 }
524 }
525 }
526
527 const matchHost = (node: URLTrieNode, index: number) => {
528 const finalHostNode = node.hostNodes.get('');
529 const noMoreHostParts = index === u.hostParts.length;
530 const value = noMoreHostParts ? '' : u.hostParts[index];
531
532 if (
533 finalHostNode && (
534 noMoreHostParts ||
535 node.key === '*' ||
536 (index === u.hostParts.length - 1 && value === 'www')
537 )
538 ) {
539 if (finalHostNode.data) {
540 push(finalHostNode.data);
541 if (breakOnFirstMatch) {
542 return;
543 }
544 }
545 matchPath(finalHostNode, 0);
546 }
547
548 if (noMoreHostParts) {
549 return;
550 }

Callers 2

getSitesFixesForFunction · 0.90
isURLInIndexedListFunction · 0.85

Calls 3

matchPreparedURLPatternFunction · 0.85
matchHostFunction · 0.85
pushFunction · 0.70

Tested by

no test coverage detected