darkreader 4.9.44 → 4.9.46

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 +63 -28
  2. package/package.json +43 -49
package/darkreader.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Dark Reader v4.9.44
2
+ * Dark Reader v4.9.46
3
3
  * https://darkreader.org/
4
4
  */
5
5
 
@@ -114,13 +114,12 @@
114
114
 
115
115
  var MessageType = {
116
116
  UI_GET_DATA: 'ui-get-data',
117
- UI_GET_ACTIVE_TAB_INFO: 'ui-get-active-tab-info',
118
117
  UI_SUBSCRIBE_TO_CHANGES: 'ui-subscribe-to-changes',
119
118
  UI_UNSUBSCRIBE_FROM_CHANGES: 'ui-unsubscribe-from-changes',
120
119
  UI_CHANGE_SETTINGS: 'ui-change-settings',
121
120
  UI_SET_THEME: 'ui-set-theme',
122
121
  UI_SET_SHORTCUT: 'ui-set-shortcut',
123
- UI_TOGGLE_URL: 'ui-toggle-url',
122
+ UI_TOGGLE_ACTIVE_TAB: 'ui-toggle-active-tab',
124
123
  UI_MARK_NEWS_AS_READ: 'ui-mark-news-as-read',
125
124
  UI_LOAD_CONFIG: 'ui-load-config',
126
125
  UI_APPLY_DEV_DYNAMIC_THEME_FIXES: 'ui-apply-dev-dynamic-theme-fixes',
@@ -150,6 +149,8 @@
150
149
  CS_FRAME_RESUME: 'cs-frame-resume',
151
150
  CS_EXPORT_CSS_RESPONSE: 'cs-export-css-response',
152
151
  CS_FETCH: 'cs-fetch',
152
+ CS_DARK_THEME_DETECTED: 'cs-dark-theme-detected',
153
+ CS_DARK_THEME_NOT_DETECTED: 'cs-dark-theme-not-detected',
153
154
  };
154
155
 
155
156
  var userAgent = typeof navigator === 'undefined' ? 'some useragent' : navigator.userAgent.toLowerCase();
@@ -413,6 +414,7 @@
413
414
  styleSystemControls: !isCSSColorSchemePropSupported,
414
415
  lightColorScheme: 'Default',
415
416
  darkColorScheme: 'Default',
417
+ immediateModify: false,
416
418
  };
417
419
 
418
420
  function isArrayLike(items) {
@@ -637,12 +639,18 @@
637
639
  }
638
640
  });
639
641
  for (var node = (root.shadowRoot ? walker.currentNode : walker.nextNode()); node != null; node = walker.nextNode()) {
642
+ if (node.classList.contains('surfingkeys_hints_host')) {
643
+ continue;
644
+ }
640
645
  iterator(node);
641
646
  iterateShadowHosts(node.shadowRoot, iterator);
642
647
  }
643
648
  }
644
- function isDOMReady() {
649
+ var isDOMReady = function () {
645
650
  return document.readyState === 'complete' || document.readyState === 'interactive';
651
+ };
652
+ function setIsDOMReady(newFunc) {
653
+ isDOMReady = newFunc;
646
654
  }
647
655
  var readyStateListeners = new Set();
648
656
  function addDOMReadyListener(listener) {
@@ -917,7 +925,7 @@
917
925
  }
918
926
  }
919
927
  var cssURLRegex = /url\((('.+?')|(".+?")|([^\)]*?))\)/g;
920
- var cssImportRegex = /@import\s*(url\()?(('.+?')|(".+?")|([^\)]*?))\)? ?(screen)?;?/g;
928
+ var cssImportRegex = /@import\s*(url\()?(('.+?')|(".+?")|([^\)]*?))\)? ?(screen)?;?/gi;
921
929
  function getCSSURLValue(cssURL) {
922
930
  return cssURL.replace(/^url\((.*)\)$/, '$1').trim().replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1');
923
931
  }
@@ -1392,6 +1400,9 @@
1392
1400
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
1393
1401
  return [key.toLowerCase(), value];
1394
1402
  }));
1403
+ function getSRGBLightness(r, g, b) {
1404
+ return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
1405
+ }
1395
1406
 
1396
1407
  function scale(x, inLow, inHigh, outLow, outHigh) {
1397
1408
  return (x - inLow) * (outHigh - outLow) / (inHigh - inLow) + outLow;
@@ -1715,6 +1726,9 @@
1715
1726
  hx = scale(h, 60, 120, 60, 105);
1716
1727
  }
1717
1728
  }
1729
+ if (hx > 40 && hx < 80) {
1730
+ lx *= 0.75;
1731
+ }
1718
1732
  return { h: hx, s: s, l: lx, a: a };
1719
1733
  }
1720
1734
  function modifyBackgroundColor(rgb, theme) {
@@ -2050,15 +2064,15 @@
2050
2064
  for (y = 0; y < height; y++) {
2051
2065
  for (x = 0; x < width; x++) {
2052
2066
  i = 4 * (y * width + x);
2053
- r = d[i + 0] / 255;
2054
- g = d[i + 1] / 255;
2055
- b = d[i + 2] / 255;
2056
- a = d[i + 3] / 255;
2057
- if (a < TRANSPARENT_ALPHA_THRESHOLD) {
2067
+ r = d[i + 0];
2068
+ g = d[i + 1];
2069
+ b = d[i + 2];
2070
+ a = d[i + 3];
2071
+ if (a / 255 < TRANSPARENT_ALPHA_THRESHOLD) {
2058
2072
  transparentPixelsCount++;
2059
2073
  }
2060
2074
  else {
2061
- l = 0.2126 * r + 0.7152 * g + 0.0722 * b;
2075
+ l = getSRGBLightness(r, g, b);
2062
2076
  if (l < DARK_LIGHTNESS_THRESHOLD) {
2063
2077
  darkPixelsCount++;
2064
2078
  }
@@ -2117,11 +2131,13 @@
2117
2131
  if (index - possibleType.length >= 0) {
2118
2132
  var possibleGradient = value.substring(index - possibleType.length, index);
2119
2133
  if (possibleGradient === possibleType) {
2120
- if (index - possibleType.length - 1 >= 9) {
2121
- if (value[index - possibleType.length - 1] === '-') {
2122
- typeGradient = "repeating-".concat(possibleType, "gradient");
2123
- return true;
2124
- }
2134
+ if (value.slice(index - possibleType.length - 10, index - possibleType.length - 1) === 'repeating') {
2135
+ typeGradient = "repeating-".concat(possibleType, "gradient");
2136
+ return true;
2137
+ }
2138
+ if (value.slice(index - possibleType.length - 8, index - possibleType.length - 1) === '-webkit') {
2139
+ typeGradient = "-webkit-".concat(possibleType, "gradient");
2140
+ return true;
2125
2141
  }
2126
2142
  typeGradient = "".concat(possibleType, "gradient");
2127
2143
  return true;
@@ -2572,7 +2588,21 @@
2572
2588
  if (results.some(function (r) { return r instanceof Promise; })) {
2573
2589
  return Promise.all(results)
2574
2590
  .then(function (asyncResults) {
2575
- return asyncResults.join('');
2591
+ var result = '';
2592
+ var lastWasURL = false;
2593
+ asyncResults.filter(Boolean).forEach(function (asyncResult) {
2594
+ if (lastWasURL) {
2595
+ if (asyncResult) {
2596
+ result += ', ';
2597
+ }
2598
+ lastWasURL = false;
2599
+ }
2600
+ result += asyncResult;
2601
+ if (asyncResult.startsWith('url(')) {
2602
+ lastWasURL = true;
2603
+ }
2604
+ });
2605
+ return result;
2576
2606
  });
2577
2607
  }
2578
2608
  return results.join('');
@@ -4814,9 +4844,13 @@
4814
4844
  var _this = this;
4815
4845
  var getCurrentValue = function () {
4816
4846
  var docSheets = documentStyleSheetsDescriptor.get.call(_this);
4817
- return Object.setPrototypeOf(__spreadArray([], __read(docSheets), false).filter(function (styleSheet) {
4847
+ var filteredSheets = __spreadArray([], __read(docSheets), false).filter(function (styleSheet) {
4818
4848
  return !styleSheet.ownerNode.classList.contains('darkreader');
4819
- }), StyleSheetList.prototype);
4849
+ });
4850
+ filteredSheets.item = function (item) {
4851
+ return filteredSheets[item];
4852
+ };
4853
+ return Object.setPrototypeOf(filteredSheets, StyleSheetList.prototype);
4820
4854
  };
4821
4855
  var elements = getCurrentValue();
4822
4856
  var styleSheetListBehavior = {
@@ -4841,7 +4875,7 @@
4841
4875
  var elements = getCurrentElementValue();
4842
4876
  var nodeListBehavior = {
4843
4877
  get: function (_, property) {
4844
- return getCurrentElementValue()[Number(property)];
4878
+ return getCurrentElementValue()[Number(property) || property];
4845
4879
  }
4846
4880
  };
4847
4881
  elements = new Proxy(elements, nodeListBehavior);
@@ -4917,20 +4951,16 @@
4917
4951
  document.head.insertBefore(textStyle, fallbackStyle.nextSibling);
4918
4952
  setupNodePositionWatcher(textStyle, 'text');
4919
4953
  var invertStyle = createOrUpdateStyle('darkreader--invert');
4920
- var invertStyleContent = '';
4921
4954
  if (fixes && Array.isArray(fixes.invert) && fixes.invert.length > 0) {
4922
- invertStyleContent += [
4955
+ invertStyle.textContent = [
4923
4956
  "".concat(fixes.invert.join(', '), " {"),
4924
4957
  " filter: ".concat(getCSSFilterValue(__assign(__assign({}, filter), { contrast: filter.mode === 0 ? filter.contrast : clamp(filter.contrast - 10, 0, 100) })), " !important;"),
4925
4958
  '}',
4926
- '',
4927
4959
  ].join('\n');
4928
4960
  }
4929
- var imageFilter = getCSSFilterValue(__assign(__assign({}, filter), { mode: FilterMode.light }));
4930
- if (imageFilter) {
4931
- invertStyleContent += "img { filter: ".concat(imageFilter, " !important;\n");
4961
+ else {
4962
+ invertStyle.textContent = '';
4932
4963
  }
4933
- invertStyle.textContent = invertStyleContent;
4934
4964
  document.head.insertBefore(invertStyle, textStyle.nextSibling);
4935
4965
  setupNodePositionWatcher(invertStyle, 'invert');
4936
4966
  var inlineStyle = createOrUpdateStyle('darkreader--inline');
@@ -5119,7 +5149,7 @@
5119
5149
  createDynamicStyleOverrides();
5120
5150
  watchForUpdates();
5121
5151
  }
5122
- if (document.hidden) {
5152
+ if (document.hidden && !filter.immediateModify) {
5123
5153
  watchForDocumentVisibility(runDynamicStyle);
5124
5154
  }
5125
5155
  else {
@@ -5217,6 +5247,11 @@
5217
5247
  ignoredImageAnalysisSelectors = [];
5218
5248
  ignoredInlineSelectors = [];
5219
5249
  }
5250
+ if (filter.immediateModify) {
5251
+ setIsDOMReady(function () {
5252
+ return true;
5253
+ });
5254
+ }
5220
5255
  isIFrame$1 = iframe;
5221
5256
  if (document.head) {
5222
5257
  if (isAnotherDarkReaderInstanceActive()) {
package/package.json CHANGED
@@ -1,29 +1,32 @@
1
1
  {
2
2
  "name": "darkreader",
3
- "version": "4.9.44",
3
+ "version": "4.9.46",
4
4
  "description": "Dark mode for every website",
5
5
  "scripts": {
6
6
  "api": "node tasks/build.js --api",
7
7
  "benchmark-server": "node tests/benchmark-server/index.js",
8
8
  "build": "node tasks/build.js --release",
9
- "code-style": "eslint --ignore-pattern \"!.eslintplugin.js\" --cache --fix \"src/**/*.ts\" \"src/**/*.tsx\" \"tasks/**/*.js\" \"tests/[!coverage]**/*.js\" \"tests/**/*.ts\" \".eslintrc.js\" \"index.d.ts\" \".eslintplugin.js\"",
9
+ "build:all": "node tasks/build.js --debug --release --api",
10
+ "code-style": "eslint --ignore-pattern '!.eslintplugin.js' --cache --fix -- 'src/**/*.ts' 'src/**/*.tsx' 'tasks/**/*.js' 'tests/[!coverage]**/*.js' 'tests/**/*.ts' '.eslintrc.js' 'index.d.ts' '.eslintplugin.js'",
10
11
  "debug": "node tasks/build.js --debug",
11
12
  "debug:watch": "node tasks/build.js --debug --watch",
12
- "lint": "eslint --ignore-pattern \"!.eslintplugin.js\" \"src/**/*.ts\" \"src/**/*.tsx\" \"tasks/**/*.js\" \"tests/**/*.ts\" \"tests/[!coverage]**/*.js\" \"index.d.ts\" \".eslintplugin.js\"",
13
+ "lint": "eslint --ignore-pattern '!.eslintplugin.js' -- 'src/**/*.ts' 'src/**/*.tsx' 'tasks/**/*.js' 'tests/**/*.ts' 'tests/[!coverage]**/*.js' 'index.d.ts' '.eslintplugin.js'",
14
+ "lint:bundle": "(node ./tasks/check-exists.js ./build/debug/chrome || node tasks/build.js --debug --api) && eslint -- 'build/debug/chrome/**/*.js' 'darkreader.js'",
13
15
  "prepublishOnly": "npm test && npm run api",
14
16
  "release": "npm test && npm run lint && node tasks/build.js --release",
15
- "test": "jest --config=tests/jest.config.js",
16
- "test:browser": "npm run debug && jest --config=tests/browser/jest.config.js --runInBand",
17
- "test:chrome": "npm run debug && jest --config=tests/browser/jest.config.chrome.js --runInBand",
18
- "test:ci": "jest --config=tests/jest.config.js --runInBand",
19
- "test:config": "jest --config=tests/config/jest.config.js",
20
- "test:config:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/config/jest.config.js --runInBand --no-cache --watch",
21
- "test:coverage": "jest --config=tests/jest.config.js --coverage",
22
- "test:firefox": "npm run debug && jest --config=tests/browser/jest.config.firefox.js --runInBand",
17
+ "test": "npm run test:unit",
18
+ "test:all": "npm run test:unit; npm run test:browser; npm run test:inject; npm run test:project",
19
+ "test:browser": "npm run debug && npm run test:chrome && npm run test:firefox",
20
+ "test:chrome": "npm run debug && TEST_BROWSER=chrome jest --config=tests/browser/jest.config.js --runInBand",
21
+ "test:ci": "npm run test:unit",
22
+ "test:coverage": "jest --config=tests/unit/jest.config.js --coverage",
23
+ "test:firefox": "npm run debug && TEST_BROWSER=firefox jest --config=tests/browser/jest.config.js --runInBand",
23
24
  "test:inject": "node tests/inject/run.js",
24
25
  "test:inject:debug": "node tests/inject/run.js --debug",
25
- "test:utils": "jest --config=tests/utils/jest.config.js",
26
- "test:utils:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/utils/jest.config.js --runInBand --no-cache --watch"
26
+ "test:project": "jest --config=tests/project/jest.config.js",
27
+ "test:unit": "jest --config=tests/unit/jest.config.js",
28
+ "test:unit:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/unit/jest.config.js --runInBand --no-cache --watch",
29
+ "test:update-snapshots": "npm run test -- --updateSnapshot && npm run test:project -- --updateSnapshot"
27
30
  },
28
31
  "main": "darkreader.js",
29
32
  "repository": {
@@ -44,20 +47,6 @@
44
47
  "accessibility",
45
48
  "eye-care"
46
49
  ],
47
- "browserslist": [
48
- "supports es5",
49
- "not ie > 0",
50
- "not ie_mob > 0",
51
- "not op_mini all",
52
- "not op_mob < 59",
53
- "not android < 50",
54
- "not ios_saf < 6",
55
- "not safari < 9.3",
56
- "not opera < 36",
57
- "not chrome < 49",
58
- "not firefox < 33",
59
- "not edge <= 18"
60
- ],
61
50
  "homepage": "https://darkreader.org/",
62
51
  "funding": {
63
52
  "type": "opencollective",
@@ -65,42 +54,47 @@
65
54
  },
66
55
  "devDependencies": {
67
56
  "@rollup/plugin-node-resolve": "13.1.3",
68
- "@rollup/plugin-replace": "3.0.1",
69
- "@rollup/plugin-typescript": "8.3.0",
57
+ "@rollup/plugin-replace": "4.0.0",
58
+ "@rollup/plugin-typescript": "8.3.1",
70
59
  "@rollup/pluginutils": "4.1.2",
71
- "@types/chrome": "0.0.176",
60
+ "@types/chrome": "0.0.179",
61
+ "@types/eslint": "8.4.1",
72
62
  "@types/jasmine": "3.10.3",
73
- "@types/jest": "27.4.0",
74
- "@types/karma": "6.3.2",
63
+ "@types/jest": "27.4.1",
64
+ "@types/karma": "6.3.3",
65
+ "@types/karma-coverage": "2.0.1",
66
+ "@types/node": "17.0.21",
75
67
  "@types/offscreencanvas": "2019.6.4",
76
- "@types/node": "17.0.9",
77
- "@typescript-eslint/eslint-plugin": "5.9.1",
78
- "@typescript-eslint/parser": "5.9.1",
79
- "chokidar": "3.5.2",
80
- "eslint": "8.7.0",
68
+ "@typescript-eslint/eslint-plugin": "5.13.0",
69
+ "@typescript-eslint/parser": "5.13.0",
70
+ "chokidar": "3.5.3",
71
+ "eslint": "8.10.0",
72
+ "eslint-plugin-compat": "4.0.2",
81
73
  "eslint-plugin-import": "2.25.4",
82
74
  "eslint-plugin-local": "1.0.0",
83
- "globby": "11.0.4",
84
- "jasmine-core": "4.0.0",
85
- "jest": "27.4.7",
86
- "karma": "6.3.12",
75
+ "get-stream": "6.0.1",
76
+ "globby": "13.1.1",
77
+ "jasmine-core": "4.0.1",
78
+ "jest": "27.5.1",
79
+ "jest-extended": "2.0.0",
80
+ "karma": "6.3.17",
87
81
  "karma-chrome-launcher": "3.1.0",
88
- "karma-coverage": "2.1.0",
82
+ "karma-coverage": "2.2.0",
89
83
  "karma-firefox-launcher": "2.1.2",
90
84
  "karma-jasmine": "4.0.1",
91
- "karma-rollup-preprocessor": "7.0.7",
85
+ "karma-rollup-preprocessor": "7.0.8",
92
86
  "karma-safari-launcher": "1.0.0",
93
87
  "less": "4.1.2",
94
- "malevic": "0.18.6",
88
+ "malevic": "0.19.1",
95
89
  "prettier": "2.5.1",
96
- "puppeteer-core": "13.0.1",
97
- "rollup": "2.64.0",
90
+ "puppeteer-core": "13.4.1",
91
+ "rollup": "2.69.0",
98
92
  "rollup-plugin-istanbul2": "2.0.2",
99
93
  "ts-jest": "27.1.3",
100
94
  "tslib": "2.3.1",
101
- "typescript": "4.5.4",
102
- "web-ext": "6.6.0",
103
- "ws": "8.4.2",
95
+ "typescript": "4.6.2",
96
+ "web-ext": "6.7.0",
97
+ "ws": "8.5.0",
104
98
  "yazl": "2.5.1"
105
99
  }
106
100
  }