(url: string, text: string, index: SiteFixesIndex, enabledForPDF: boolean)
| 53 | } |
| 54 | |
| 55 | export 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 | } |
no test coverage detected