darkreader 4.9.82 → 4.9.83

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 +37 -19
  2. package/package.json +9 -9
package/darkreader.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Dark Reader v4.9.82
2
+ * Dark Reader v4.9.83
3
3
  * https://darkreader.org/
4
4
  */
5
5
 
@@ -212,6 +212,10 @@
212
212
  });
213
213
  return dataURL;
214
214
  }
215
+ async function loadAsText(url, mimeType, origin) {
216
+ const response = await getOKResponse(url, mimeType, origin);
217
+ return await response.text();
218
+ }
215
219
 
216
220
  const throwCORSError = async (url) => {
217
221
  return Promise.reject(
@@ -785,6 +789,15 @@
785
789
  }
786
790
  return matches;
787
791
  }
792
+ function getHashCode(text) {
793
+ const len = text.length;
794
+ let hash = 0;
795
+ for (let i = 0; i < len; i++) {
796
+ const c = text.charCodeAt(i);
797
+ hash = ((hash << 5) - hash + c) & 4294967295;
798
+ }
799
+ return hash;
800
+ }
788
801
  function escapeRegExpSpecialChars(input) {
789
802
  return input.replaceAll(/[\^$.*+?\(\)\[\]{}|\-\\]/g, "\\$&");
790
803
  }
@@ -2255,8 +2268,7 @@
2255
2268
  const analysis = analyzeImage(image);
2256
2269
  resolve({
2257
2270
  src: url,
2258
- blob,
2259
- dataURL,
2271
+ dataURL: analysis.isLarge ? "" : dataURL,
2260
2272
  width: image.width,
2261
2273
  height: image.height,
2262
2274
  ...analysis
@@ -2509,7 +2521,8 @@
2509
2521
  if (!isBlobURLSupported) {
2510
2522
  return null;
2511
2523
  }
2512
- let blobURL = dataURLBlobURLs.get(dataURL);
2524
+ const hash = getHashCode(dataURL);
2525
+ let blobURL = dataURLBlobURLs.get(hash);
2513
2526
  if (blobURL) {
2514
2527
  return blobURL;
2515
2528
  }
@@ -2519,7 +2532,7 @@
2519
2532
  blob = await response.blob();
2520
2533
  }
2521
2534
  blobURL = URL.createObjectURL(blob);
2522
- dataURLBlobURLs.set(dataURL, blobURL);
2535
+ dataURLBlobURLs.set(hash, blobURL);
2523
2536
  return blobURL;
2524
2537
  }
2525
2538
  function cleanImageProcessingCache() {
@@ -2693,7 +2706,7 @@
2693
2706
  );
2694
2707
  lines.push("}");
2695
2708
  }
2696
- if (isCSSColorSchemePropSupported && !isIFrame && theme.mode === 1) {
2709
+ if (isCSSColorSchemePropSupported && theme.mode === 1) {
2697
2710
  lines.push("html {");
2698
2711
  lines.push(` color-scheme: dark !important;`);
2699
2712
  lines.push("}");
@@ -4602,6 +4615,13 @@
4602
4615
  const asyncQueue = createAsyncTasksQueue();
4603
4616
  function createStyleSheetModifier() {
4604
4617
  let renderId = 0;
4618
+ function getStyleRuleHash(rule) {
4619
+ let cssText = rule.cssText;
4620
+ if (isMediaRule(rule.parentRule)) {
4621
+ cssText = `${rule.parentRule.media.mediaText} { ${cssText} }`;
4622
+ }
4623
+ return getHashCode(cssText);
4624
+ }
4605
4625
  const rulesTextCache = new Set();
4606
4626
  const rulesModCache = new Map();
4607
4627
  const varTypeChangeCleaners = new Set();
@@ -4631,23 +4651,17 @@
4631
4651
  iterateCSSRules(
4632
4652
  rules,
4633
4653
  (rule) => {
4634
- let cssText = rule.cssText;
4654
+ const hash = getStyleRuleHash(rule);
4635
4655
  let textDiffersFromPrev = false;
4636
- notFoundCacheKeys.delete(cssText);
4637
- if (isMediaRule(rule.parentRule)) {
4638
- cssText += `;${rule.parentRule.media.mediaText}`;
4639
- }
4640
- if (isLayerRule(rule.parentRule)) {
4641
- cssText += `;${rule.parentRule.name}`;
4642
- }
4643
- if (!rulesTextCache.has(cssText)) {
4644
- rulesTextCache.add(cssText);
4656
+ notFoundCacheKeys.delete(hash);
4657
+ if (!rulesTextCache.has(hash)) {
4658
+ rulesTextCache.add(hash);
4645
4659
  textDiffersFromPrev = true;
4646
4660
  }
4647
4661
  if (textDiffersFromPrev) {
4648
4662
  rulesChanged = true;
4649
4663
  } else {
4650
- modRules.push(rulesModCache.get(cssText));
4664
+ modRules.push(rulesModCache.get(hash));
4651
4665
  return;
4652
4666
  }
4653
4667
  if (rule.style.all === "revert") {
@@ -4681,7 +4695,7 @@
4681
4695
  };
4682
4696
  modRules.push(modRule);
4683
4697
  }
4684
- rulesModCache.set(cssText, modRule);
4698
+ rulesModCache.set(hash, modRule);
4685
4699
  },
4686
4700
  () => {
4687
4701
  hasNonLoadedLink = true;
@@ -5539,11 +5553,15 @@
5539
5553
  if (url.startsWith("data:")) {
5540
5554
  return await (await fetch(url)).text();
5541
5555
  }
5556
+ const parsedURL = new URL(url);
5557
+ if (parsedURL.origin === location.origin) {
5558
+ return await loadAsText(url, "text/css", location.origin);
5559
+ }
5542
5560
  return await bgFetch({
5543
5561
  url,
5544
5562
  responseType: "text",
5545
5563
  mimeType: "text/css",
5546
- origin: window.location.origin
5564
+ origin: location.origin
5547
5565
  });
5548
5566
  }
5549
5567
  async function replaceCSSImports(cssText, basePath, cache = new Map()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "darkreader",
3
- "version": "4.9.82",
3
+ "version": "4.9.83",
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",
@@ -58,16 +58,16 @@
58
58
  "@rollup/plugin-node-resolve": "15.2.3",
59
59
  "@rollup/plugin-replace": "5.0.5",
60
60
  "@rollup/plugin-typescript": "11.1.6",
61
- "@types/chrome": "0.0.263",
62
- "@types/eslint": "8.56.6",
61
+ "@types/chrome": "0.0.266",
62
+ "@types/eslint": "8.56.7",
63
63
  "@types/jasmine": "5.1.4",
64
64
  "@types/jest": "29.5.12",
65
65
  "@types/karma": "6.3.8",
66
66
  "@types/karma-coverage": "2.0.3",
67
- "@types/node": "20.12.2",
67
+ "@types/node": "20.12.6",
68
68
  "@types/ws": "8.5.10",
69
- "@typescript-eslint/eslint-plugin": "7.4.0",
70
- "@typescript-eslint/parser": "7.4.0",
69
+ "@typescript-eslint/eslint-plugin": "7.6.0",
70
+ "@typescript-eslint/parser": "7.6.0",
71
71
  "chokidar": "3.6.0",
72
72
  "eslint": "8.57.0",
73
73
  "eslint-plugin-compat": "4.2.0",
@@ -88,12 +88,12 @@
88
88
  "less": "4.2.0",
89
89
  "malevic": "0.20.1",
90
90
  "prettier": "3.2.5",
91
- "puppeteer-core": "22.6.1",
92
- "rollup": "4.13.2",
91
+ "puppeteer-core": "22.6.3",
92
+ "rollup": "4.14.1",
93
93
  "rollup-plugin-istanbul": "5.0.0",
94
94
  "ts-jest": "29.1.2",
95
95
  "tslib": "2.6.2",
96
- "typescript": "5.4.3",
96
+ "typescript": "5.4.4",
97
97
  "web-ext": "7.11.0",
98
98
  "ws": "8.16.0",
99
99
  "yazl": "2.5.1"