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

Function getDynamicThemeFixesFor

src/generators/dynamic-theme.ts:55–89  ·  view source on GitHub ↗
(url: string, text: string, index: SiteFixesIndex, enabledForPDF: boolean)

Source from the content-addressed store, hash-verified

53}
54
55export function getDynamicThemeFixesFor(url: string, text: string, index: SiteFixesIndex, enabledForPDF: boolean): DynamicThemeFix[] | null {
56 const fixes = getSitesFixesFor(url, text, index, parseDynamicThemeFixes);
57
58 if (fixes.length === 0 || fixes[0].url[0] !== '*') {
59 return null;
60 }
61
62 if (enabledForPDF) {
63 // Copy part of fixes which will be mutated
64 const invert = fixes[0].invert?.slice();
65 const commonFix = {...fixes[0], invert};
66 const pdfFixes: DynamicThemeFix[] = [
67 commonFix,
68 ...fixes.slice(1),
69 ];
70
71 const inversionFix = __CHROMIUM_MV2__ || __CHROMIUM_MV3__ ?
72 '\nembed[type="application/pdf"][src="about:blank"] { filter: invert(100%) contrast(90%); }' :
73 '\nembed[type="application/pdf"] { filter: invert(100%) contrast(90%); }';
74 if (!commonFix.css.endsWith(inversionFix)) {
75 commonFix.css += inversionFix;
76 }
77
78 if (['drive.google.com', 'mail.google.com'].includes(getDomain(url))) {
79 const nestedInversionFix = 'div[role="dialog"] div[role="document"]';
80 if (commonFix.invert.at(-1) !== nestedInversionFix) {
81 commonFix.invert.push(nestedInversionFix);
82 }
83 }
84
85 return pdfFixes;
86 }
87
88 return fixes;
89}

Callers 1

ExtensionClass · 0.90

Calls 2

getSitesFixesForFunction · 0.90
getDomainFunction · 0.90

Tested by

no test coverage detected