darkreader 4.9.84 → 4.9.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/darkreader.js +87 -24
  2. package/package.json +12 -11
package/darkreader.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Dark Reader v4.9.84
2
+ * Dark Reader v4.9.85
3
3
  * https://darkreader.org/
4
4
  */
5
5
 
@@ -1041,12 +1041,14 @@
1041
1041
  escapedSelector = escapedSelector.replaceAll(/\s+/g, "\\s*");
1042
1042
  escapedSelector = escapedSelector.replaceAll(/::/g, "::?");
1043
1043
  const regexp = new RegExp(
1044
- `${escapedSelector}\\s*{[^}]*?${shorthand}:\\s*([^;}]+)`
1044
+ `${escapedSelector}\\s*{[^}]*${shorthand}:\\s*([^;}]+)`
1045
1045
  );
1046
1046
  const match = sourceCSSText.match(regexp);
1047
1047
  if (match) {
1048
1048
  iterate(shorthand, match[1]);
1049
1049
  }
1050
+ } else if (shorthand === "background") {
1051
+ iterate("background-color", "#ffffff");
1050
1052
  }
1051
1053
  }
1052
1054
  }
@@ -1069,9 +1071,11 @@
1069
1071
  }
1070
1072
  function replaceCSSRelativeURLsWithAbsolute($css, cssBasePath) {
1071
1073
  return $css.replace(cssURLRegex, (match) => {
1072
- const pathValue = getCSSURLValue(match);
1073
1074
  try {
1074
- return `url('${getAbsoluteURL(cssBasePath, pathValue)}')`;
1075
+ const url = getCSSURLValue(match);
1076
+ const absoluteURL = getAbsoluteURL(cssBasePath, url);
1077
+ const escapedURL = absoluteURL.replaceAll("'", "\\'");
1078
+ return `url('${escapedURL}')`;
1075
1079
  } catch (err) {
1076
1080
  return match;
1077
1081
  }
@@ -2105,11 +2109,38 @@
2105
2109
  return modifyBackgroundColor(rgb, theme);
2106
2110
  }
2107
2111
 
2112
+ const excludedSelectors = [
2113
+ "pre",
2114
+ "pre *",
2115
+ "code",
2116
+ '[aria-hidden="true"]',
2117
+ '[class*="fa-"]',
2118
+ ".fa",
2119
+ ".fab",
2120
+ ".fad",
2121
+ ".fal",
2122
+ ".far",
2123
+ ".fas",
2124
+ ".fass",
2125
+ ".fasr",
2126
+ ".fat",
2127
+ ".icofont",
2128
+ '[style*="font-"]',
2129
+ '[class*="icon"]',
2130
+ '[class*="Icon"]',
2131
+ '[class*="symbol"]',
2132
+ '[class*="Symbol"]',
2133
+ ".glyphicon",
2134
+ '[class*="material-symbol"]',
2135
+ '[class*="material-icon"]',
2136
+ "mu",
2137
+ '[class*="mu-"]',
2138
+ ".typcn",
2139
+ '[class*="vjs-"]'
2140
+ ];
2108
2141
  function createTextStyle(config) {
2109
2142
  const lines = [];
2110
- lines.push(
2111
- '*:not(pre, pre *, code, .far, .fa, .glyphicon, [class*="vjs-"], .fab, .fa-github, .fas, .material-icons, .icofont, .typcn, mu, [class*="mu-"], .glyphicon, .icon) {'
2112
- );
2143
+ lines.push(`*:not(${excludedSelectors.join(", ")}) {`);
2113
2144
  if (config.useFont && config.fontFamily) {
2114
2145
  lines.push(` font-family: ${config.fontFamily} !important;`);
2115
2146
  }
@@ -3520,7 +3551,11 @@
3520
3551
  };
3521
3552
  }
3522
3553
  getModifierForVarDependant(property, sourceValue) {
3523
- if (sourceValue.match(/^\s*(rgb|hsl)a?\(/)) {
3554
+ const isConstructedColor = sourceValue.match(/^\s*(rgb|hsl)a?\(/);
3555
+ const isSimpleConstructedColor = sourceValue.match(
3556
+ /^rgba?\(var\(--[\-_A-Za-z0-9]+\)(\s*,?\/?\s*0?\.\d+)?\)$/
3557
+ );
3558
+ if (isConstructedColor && !isSimpleConstructedColor) {
3524
3559
  const isBg = property.startsWith("background");
3525
3560
  const isText = isTextColorProperty(property);
3526
3561
  return (theme) => {
@@ -3539,21 +3574,34 @@
3539
3574
  return modifier(value, theme);
3540
3575
  };
3541
3576
  }
3542
- if (property === "background-color") {
3577
+ if (
3578
+ property === "background-color" ||
3579
+ (isSimpleConstructedColor && property === "background")
3580
+ ) {
3543
3581
  return (theme) => {
3582
+ const defaultFallback = tryModifyBgColor(
3583
+ isConstructedColor ? "255, 255, 255" : "#ffffff",
3584
+ theme
3585
+ );
3544
3586
  return replaceCSSVariablesNames(
3545
3587
  sourceValue,
3546
3588
  (v) => wrapBgColorVariableName(v),
3547
- (fallback) => tryModifyBgColor(fallback, theme)
3589
+ (fallback) => tryModifyBgColor(fallback, theme),
3590
+ defaultFallback
3548
3591
  );
3549
3592
  };
3550
3593
  }
3551
3594
  if (isTextColorProperty(property)) {
3552
3595
  return (theme) => {
3596
+ const defaultFallback = tryModifyTextColor(
3597
+ isConstructedColor ? "0, 0, 0" : "#000000",
3598
+ theme
3599
+ );
3553
3600
  return replaceCSSVariablesNames(
3554
3601
  sourceValue,
3555
3602
  (v) => wrapTextColorVariableName(v),
3556
- (fallback) => tryModifyTextColor(fallback, theme)
3603
+ (fallback) => tryModifyTextColor(fallback, theme),
3604
+ defaultFallback
3557
3605
  );
3558
3606
  };
3559
3607
  }
@@ -3906,7 +3954,9 @@
3906
3954
  return input;
3907
3955
  }
3908
3956
  const inputLength = input.length;
3909
- const replacements = matches.map((m) => replacer(m.value));
3957
+ const replacements = matches.map((m) =>
3958
+ replacer(m.value, matches.length)
3959
+ );
3910
3960
  const parts = [];
3911
3961
  parts.push(input.substring(0, matches[0].start));
3912
3962
  for (let i = 0; i < matchesCount; i++) {
@@ -3931,11 +3981,19 @@
3931
3981
  }
3932
3982
  return {name, fallback};
3933
3983
  }
3934
- function replaceCSSVariablesNames(value, nameReplacer, fallbackReplacer) {
3984
+ function replaceCSSVariablesNames(
3985
+ value,
3986
+ nameReplacer,
3987
+ fallbackReplacer,
3988
+ finalFallback
3989
+ ) {
3935
3990
  const matchReplacer = (match) => {
3936
3991
  const {name, fallback} = getVariableNameAndFallback(match);
3937
3992
  const newName = nameReplacer(name);
3938
3993
  if (!fallback) {
3994
+ if (finalFallback) {
3995
+ return `var(${newName}, ${finalFallback})`;
3996
+ }
3939
3997
  return `var(${newName})`;
3940
3998
  }
3941
3999
  let newFallback;
@@ -3979,7 +4037,10 @@
3979
4037
  return value.includes("var(");
3980
4038
  }
3981
4039
  function isConstructedColorVar(value) {
3982
- return value.match(/^\s*(rgb|hsl)a?\(/);
4040
+ return (
4041
+ value.match(/^\s*(rgb|hsl)a?\(/) ||
4042
+ value.match(/^(((\d{1,3})|(var\([\-_A-Za-z0-9]+\))),?\s*?){3}$/)
4043
+ );
3983
4044
  }
3984
4045
  function isTextColorProperty(property) {
3985
4046
  return (
@@ -4023,10 +4084,11 @@
4023
4084
  function tryModifyBorderColor(color, theme) {
4024
4085
  return handleRawColorValue(color, theme, modifyBorderColor);
4025
4086
  }
4026
- function insertVarValues(source, varValues, stack = new Set()) {
4087
+ function insertVarValues(source, varValues, fullStack = new Set()) {
4027
4088
  let containsUnresolvedVar = false;
4028
- const matchReplacer = (match) => {
4089
+ const matchReplacer = (match, count) => {
4029
4090
  const {name, fallback} = getVariableNameAndFallback(match);
4091
+ const stack = count > 1 ? new Set(fullStack) : fullStack;
4030
4092
  if (stack.has(name)) {
4031
4093
  containsUnresolvedVar = true;
4032
4094
  return null;
@@ -4308,9 +4370,7 @@
4308
4370
  }
4309
4371
  const shouldAnalyze = Boolean(
4310
4372
  svg &&
4311
- (svg.role === "img" ||
4312
- svg.parentElement?.role === "img" ||
4313
- svg.getAttribute("class")?.includes("logo") ||
4373
+ (svg.getAttribute("class")?.includes("logo") ||
4314
4374
  svg.parentElement?.getAttribute("class")?.includes("logo"))
4315
4375
  );
4316
4376
  svgAnalysisConditionCache.set(svg, shouldAnalyze);
@@ -4435,7 +4495,7 @@
4435
4495
  }
4436
4496
  if (shouldAnalyzeSVGAsImage(svg)) {
4437
4497
  svgInversionCache.add(svg);
4438
- const handleSVGRoot = () => {
4498
+ const analyzeSVGAsImage = () => {
4439
4499
  let svgString = svg.outerHTML;
4440
4500
  svgString = svgString.replaceAll(
4441
4501
  '<style class="darkreader darkreader--sync" media="screen"></style>',
@@ -4453,13 +4513,16 @@
4453
4513
  "data-darkreader-inline-invert",
4454
4514
  ""
4455
4515
  );
4516
+ } else {
4517
+ svg.removeAttribute(
4518
+ "data-darkreader-inline-invert"
4519
+ );
4456
4520
  }
4457
4521
  });
4458
4522
  };
4459
- if (isReadyStateComplete()) {
4460
- handleSVGRoot();
4461
- } else {
4462
- addReadyStateCompleteListener(handleSVGRoot);
4523
+ analyzeSVGAsImage();
4524
+ if (!isDOMReady()) {
4525
+ addDOMReadyListener(analyzeSVGAsImage);
4463
4526
  }
4464
4527
  return;
4465
4528
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "darkreader",
3
- "version": "4.9.84",
3
+ "version": "4.9.85",
4
4
  "description": "Dark mode for every website",
5
5
  "scripts": {
6
6
  "api": "node --max-old-space-size=3072 tasks/cli.js build --api",
@@ -9,6 +9,7 @@
9
9
  "code-style": "npm run lint",
10
10
  "debug": "node --max-old-space-size=3072 tasks/cli.js build --debug",
11
11
  "debug:watch": "node --max-old-space-size=3072 tasks/cli.js build --debug --watch --chrome --firefox",
12
+ "debug:watch:mv3": "node --max-old-space-size=3072 tasks/cli.js build --debug --watch --chrome-mv3",
12
13
  "dependencies:upgrade": "node tasks/dependencies.js",
13
14
  "lint": "eslint --ignore-pattern '!.eslint-plugin-local.js' -- 'src/**/*.ts' 'src/**/*.tsx' 'tasks/**/*.js' 'tests/[!coverage]**/*.js' 'tests/**/*.ts' '.eslintrc.js' 'index.d.ts'",
14
15
  "lint:bundle": "(node ./tasks/check-exists.js ./build/debug/chrome || node tasks/build.js --debug --api --chrome) && eslint -- 'build/debug/chrome/**/*.js' 'darkreader.js'",
@@ -58,21 +59,21 @@
58
59
  "@rollup/plugin-node-resolve": "15.2.3",
59
60
  "@rollup/plugin-replace": "5.0.5",
60
61
  "@rollup/plugin-typescript": "11.1.6",
61
- "@types/chrome": "0.0.266",
62
- "@types/eslint": "8.56.7",
62
+ "@types/chrome": "0.0.267",
63
+ "@types/eslint": "8.56.10",
63
64
  "@types/jasmine": "5.1.4",
64
65
  "@types/jest": "29.5.12",
65
66
  "@types/karma": "6.3.8",
66
67
  "@types/karma-coverage": "2.0.3",
67
- "@types/node": "20.12.6",
68
+ "@types/node": "20.12.7",
68
69
  "@types/ws": "8.5.10",
69
- "@typescript-eslint/eslint-plugin": "7.6.0",
70
- "@typescript-eslint/parser": "7.6.0",
70
+ "@typescript-eslint/eslint-plugin": "7.7.1",
71
+ "@typescript-eslint/parser": "7.7.1",
71
72
  "chokidar": "3.6.0",
72
73
  "eslint": "8.57.0",
73
74
  "eslint-plugin-compat": "4.2.0",
74
75
  "eslint-plugin-import": "2.29.1",
75
- "eslint-plugin-local": "4.2.1",
76
+ "eslint-plugin-local": "4.2.2",
76
77
  "globby": "14.0.1",
77
78
  "jasmine-core": "5.1.2",
78
79
  "jest": "29.7.0",
@@ -88,14 +89,14 @@
88
89
  "less": "4.2.0",
89
90
  "malevic": "0.20.1",
90
91
  "prettier": "3.2.5",
91
- "puppeteer-core": "22.6.3",
92
- "rollup": "4.14.1",
92
+ "puppeteer-core": "22.7.1",
93
+ "rollup": "4.17.1",
93
94
  "rollup-plugin-istanbul": "5.0.0",
94
95
  "ts-jest": "29.1.2",
95
96
  "tslib": "2.6.2",
96
- "typescript": "5.4.4",
97
+ "typescript": "5.4.5",
97
98
  "web-ext": "7.11.0",
98
- "ws": "8.16.0",
99
+ "ws": "8.17.0",
99
100
  "yazl": "2.5.1"
100
101
  }
101
102
  }