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

Function getSitesFixesFor

src/generators/utils/parse.ts:132–157  ·  view source on GitHub ↗
(url: string, text: string, index: SiteFixesIndex, parse: (text: string) => T[])

Source from the content-addressed store, hash-verified

130const siteFixesCache = new WeakMap<[number, number], any>();
131
132export function getSitesFixesFor<T extends SiteProps>(url: string, text: string, index: SiteFixesIndex, parse: (text: string) => T[]): Array<Readonly<T>> {
133 const matches = getURLMatchesFromIndexedList(url, index);
134
135 const fixes = matches.map((offset) => {
136 const cache = siteFixesCache.get(offset);
137 if (cache) {
138 return cache;
139 }
140 const [start, length] = offset;
141 const block = text.slice(start, start + length);
142 const fix = parse(block)[0];
143 siteFixesCache.set(offset, fix);
144 return fix;
145 });
146
147 if (fixes.length > 0) {
148 const commonFixIndex = fixes.findIndex((f) => f.url?.[0] === '*');
149 if (commonFixIndex > 0) {
150 const commonFix = fixes[commonFixIndex];
151 fixes.splice(commonFixIndex, 1);
152 fixes.unshift(commonFix);
153 }
154 }
155
156 return fixes;
157}

Callers 5

getDetectorHintsForFunction · 0.90
getDynamicThemeFixesForFunction · 0.90
createStaticStylesheetFunction · 0.90
getInversionFixesForFunction · 0.90
parse.tests.tsFile · 0.90

Calls 4

getMethod · 0.65
setMethod · 0.65
parseFunction · 0.50

Tested by

no test coverage detected