MCPcopy
hub / github.com/darkreader/darkreader / findRelevantFix

Function findRelevantFix

src/inject/dynamic-theme/fixes.ts:14–34  ·  view source on GitHub ↗
(documentURL: string, fixes: DynamicThemeFix[])

Source from the content-addressed store, hash-verified

12 * @returns A single fix constructed from the generic fix and a single most relevant other fix
13 */
14export function findRelevantFix(documentURL: string, fixes: DynamicThemeFix[]): number | null {
15 if (!Array.isArray(fixes) || fixes.length === 0 || fixes[0].url[0] !== '*') {
16 logWarn('selectRelevantFix() failed to construct a single fix', documentURL, fixes);
17 return null;
18 }
19
20 let maxSpecificity = 0;
21 let maxSpecificityIndex: number | null = null;
22 for (let i = 1; i < fixes.length; i++) {
23 if (isURLInList(documentURL, fixes[i].url)) {
24 // Note: this is legacy logic, a bit odd
25 const specificity = fixes[i].url[0].length;
26 if (maxSpecificityIndex === null || maxSpecificity < specificity) {
27 maxSpecificity = specificity;
28 maxSpecificityIndex = i;
29 }
30 }
31 }
32
33 return maxSpecificityIndex;
34}
35
36/**
37 * Constructs a single fix out of multiple fixes, without modifying the original fixes

Callers 2

selectRelevantFixFunction · 0.90
fixes.tests.tsFile · 0.90

Calls 2

logWarnFunction · 0.90
isURLInListFunction · 0.90

Tested by

no test coverage detected