(url: string, fixes: string, index: SiteFixesIndex)
| 185 | * @param inversionFixes List of inversion fixes. |
| 186 | */ |
| 187 | export function getInversionFixesFor(url: string, fixes: string, index: SiteFixesIndex): InversionFix { |
| 188 | const inversionFixes = getSitesFixesFor(url, fixes, index, parseInversionFixes); |
| 189 | |
| 190 | const common = { |
| 191 | url: inversionFixes[0].url, |
| 192 | invert: inversionFixes[0].invert || [], |
| 193 | noinvert: inversionFixes[0].noinvert || [], |
| 194 | removebg: inversionFixes[0].removebg || [], |
| 195 | css: inversionFixes[0].css || '', |
| 196 | }; |
| 197 | |
| 198 | if (url) { |
| 199 | // Search for match with given URL |
| 200 | const matches = inversionFixes |
| 201 | .slice(1) |
| 202 | .filter((s) => isURLInList(url, s.url)) |
| 203 | .sort((a, b) => b.url[0].length - a.url[0].length); |
| 204 | if (matches.length > 0) { |
| 205 | const found = matches[0]; |
| 206 | return { |
| 207 | url: found.url, |
| 208 | invert: common.invert.concat(found.invert || []), |
| 209 | noinvert: common.noinvert.concat(found.noinvert || []), |
| 210 | removebg: common.removebg.concat(found.removebg || []), |
| 211 | css: [common.css, found.css].filter((s) => s).join('\n'), |
| 212 | }; |
| 213 | } |
| 214 | } |
| 215 | return common; |
| 216 | } |
| 217 | |
| 218 | const inversionFixesCommands: { [key: string]: keyof InversionFix } = { |
| 219 | 'INVERT': 'invert', |
no test coverage detected