darkreader 4.9.58 → 4.9.67

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 (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -8
  3. package/darkreader.js +638 -293
  4. package/package.json +52 -48
package/darkreader.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Dark Reader v4.9.58
2
+ * Dark Reader v4.9.67
3
3
  * https://darkreader.org/
4
4
  */
5
5
 
@@ -28,6 +28,7 @@
28
28
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
29
29
  PERFORMANCE OF THIS SOFTWARE.
30
30
  ***************************************************************************** */
31
+ /* global Reflect, Promise, SuppressedError, Symbol */
31
32
 
32
33
  var __assign = function () {
33
34
  __assign =
@@ -107,7 +108,7 @@
107
108
  }
108
109
  function step(op) {
109
110
  if (f) throw new TypeError("Generator is already executing.");
110
- while (_)
111
+ while ((g && ((g = 0), op[0] && (_ = 0)), _))
111
112
  try {
112
113
  if (
113
114
  ((f = 1),
@@ -232,58 +233,95 @@
232
233
  return to.concat(ar || Array.prototype.slice.call(from));
233
234
  }
234
235
 
235
- var MessageType;
236
- (function (MessageType) {
237
- MessageType["UI_GET_DATA"] = "ui-get-data";
238
- MessageType["UI_SUBSCRIBE_TO_CHANGES"] = "ui-subscribe-to-changes";
239
- MessageType["UI_UNSUBSCRIBE_FROM_CHANGES"] =
240
- "ui-unsubscribe-from-changes";
241
- MessageType["UI_CHANGE_SETTINGS"] = "ui-change-settings";
242
- MessageType["UI_SET_THEME"] = "ui-set-theme";
243
- MessageType["UI_SET_SHORTCUT"] = "ui-set-shortcut";
244
- MessageType["UI_TOGGLE_ACTIVE_TAB"] = "ui-toggle-active-tab";
245
- MessageType["UI_MARK_NEWS_AS_READ"] = "ui-mark-news-as-read";
246
- MessageType["UI_MARK_NEWS_AS_DISPLAYED"] = "ui-mark-news-as-displayed";
247
- MessageType["UI_LOAD_CONFIG"] = "ui-load-config";
248
- MessageType["UI_APPLY_DEV_DYNAMIC_THEME_FIXES"] =
249
- "ui-apply-dev-dynamic-theme-fixes";
250
- MessageType["UI_RESET_DEV_DYNAMIC_THEME_FIXES"] =
251
- "ui-reset-dev-dynamic-theme-fixes";
252
- MessageType["UI_APPLY_DEV_INVERSION_FIXES"] =
253
- "ui-apply-dev-inversion-fixes";
254
- MessageType["UI_RESET_DEV_INVERSION_FIXES"] =
255
- "ui-reset-dev-inversion-fixes";
256
- MessageType["UI_APPLY_DEV_STATIC_THEMES"] =
257
- "ui-apply-dev-static-themes";
258
- MessageType["UI_RESET_DEV_STATIC_THEMES"] =
259
- "ui-reset-dev-static-themes";
260
- MessageType["UI_SAVE_FILE"] = "ui-save-file";
261
- MessageType["UI_REQUEST_EXPORT_CSS"] = "ui-request-export-css";
262
- MessageType["UI_COLOR_SCHEME_CHANGE"] = "ui-color-scheme-change";
263
- MessageType["BG_CHANGES"] = "bg-changes";
264
- MessageType["BG_ADD_CSS_FILTER"] = "bg-add-css-filter";
265
- MessageType["BG_ADD_STATIC_THEME"] = "bg-add-static-theme";
266
- MessageType["BG_ADD_SVG_FILTER"] = "bg-add-svg-filter";
267
- MessageType["BG_ADD_DYNAMIC_THEME"] = "bg-add-dynamic-theme";
268
- MessageType["BG_EXPORT_CSS"] = "bg-export-css";
269
- MessageType["BG_UNSUPPORTED_SENDER"] = "bg-unsupported-sender";
270
- MessageType["BG_CLEAN_UP"] = "bg-clean-up";
271
- MessageType["BG_RELOAD"] = "bg-reload";
272
- MessageType["BG_FETCH_RESPONSE"] = "bg-fetch-response";
273
- MessageType["BG_UI_UPDATE"] = "bg-ui-update";
274
- MessageType["BG_CSS_UPDATE"] = "bg-css-update";
275
- MessageType["CS_COLOR_SCHEME_CHANGE"] = "cs-color-scheme-change";
276
- MessageType["CS_FRAME_CONNECT"] = "cs-frame-connect";
277
- MessageType["CS_FRAME_FORGET"] = "cs-frame-forget";
278
- MessageType["CS_FRAME_FREEZE"] = "cs-frame-freeze";
279
- MessageType["CS_FRAME_RESUME"] = "cs-frame-resume";
280
- MessageType["CS_EXPORT_CSS_RESPONSE"] = "cs-export-css-response";
281
- MessageType["CS_FETCH"] = "cs-fetch";
282
- MessageType["CS_DARK_THEME_DETECTED"] = "cs-dark-theme-detected";
283
- MessageType["CS_DARK_THEME_NOT_DETECTED"] =
284
- "cs-dark-theme-not-detected";
285
- MessageType["CS_LOG"] = "cs-log";
286
- })(MessageType || (MessageType = {}));
236
+ typeof SuppressedError === "function"
237
+ ? SuppressedError
238
+ : function (error, suppressed, message) {
239
+ var e = new Error(message);
240
+ return (
241
+ (e.name = "SuppressedError"),
242
+ (e.error = error),
243
+ (e.suppressed = suppressed),
244
+ e
245
+ );
246
+ };
247
+
248
+ var MessageTypeUItoBG;
249
+ (function (MessageTypeUItoBG) {
250
+ MessageTypeUItoBG["GET_DATA"] = "ui-bg-get-data";
251
+ MessageTypeUItoBG["GET_DEVTOOLS_DATA"] = "ui-bg-get-devtools-data";
252
+ MessageTypeUItoBG["SUBSCRIBE_TO_CHANGES"] =
253
+ "ui-bg-subscribe-to-changes";
254
+ MessageTypeUItoBG["UNSUBSCRIBE_FROM_CHANGES"] =
255
+ "ui-bg-unsubscribe-from-changes";
256
+ MessageTypeUItoBG["CHANGE_SETTINGS"] = "ui-bg-change-settings";
257
+ MessageTypeUItoBG["SET_THEME"] = "ui-bg-set-theme";
258
+ MessageTypeUItoBG["TOGGLE_ACTIVE_TAB"] = "ui-bg-toggle-active-tab";
259
+ MessageTypeUItoBG["MARK_NEWS_AS_READ"] = "ui-bg-mark-news-as-read";
260
+ MessageTypeUItoBG["MARK_NEWS_AS_DISPLAYED"] =
261
+ "ui-bg-mark-news-as-displayed";
262
+ MessageTypeUItoBG["LOAD_CONFIG"] = "ui-bg-load-config";
263
+ MessageTypeUItoBG["APPLY_DEV_DYNAMIC_THEME_FIXES"] =
264
+ "ui-bg-apply-dev-dynamic-theme-fixes";
265
+ MessageTypeUItoBG["RESET_DEV_DYNAMIC_THEME_FIXES"] =
266
+ "ui-bg-reset-dev-dynamic-theme-fixes";
267
+ MessageTypeUItoBG["APPLY_DEV_INVERSION_FIXES"] =
268
+ "ui-bg-apply-dev-inversion-fixes";
269
+ MessageTypeUItoBG["RESET_DEV_INVERSION_FIXES"] =
270
+ "ui-bg-reset-dev-inversion-fixes";
271
+ MessageTypeUItoBG["APPLY_DEV_STATIC_THEMES"] =
272
+ "ui-bg-apply-dev-static-themes";
273
+ MessageTypeUItoBG["RESET_DEV_STATIC_THEMES"] =
274
+ "ui-bg-reset-dev-static-themes";
275
+ MessageTypeUItoBG["COLOR_SCHEME_CHANGE"] = "ui-bg-color-scheme-change";
276
+ MessageTypeUItoBG["HIDE_HIGHLIGHTS"] = "ui-bg-hide-highlights";
277
+ })(MessageTypeUItoBG || (MessageTypeUItoBG = {}));
278
+ var MessageTypeBGtoUI;
279
+ (function (MessageTypeBGtoUI) {
280
+ MessageTypeBGtoUI["CHANGES"] = "bg-ui-changes";
281
+ })(MessageTypeBGtoUI || (MessageTypeBGtoUI = {}));
282
+ var DebugMessageTypeBGtoUI;
283
+ (function (DebugMessageTypeBGtoUI) {
284
+ DebugMessageTypeBGtoUI["CSS_UPDATE"] = "debug-bg-ui-css-update";
285
+ DebugMessageTypeBGtoUI["UPDATE"] = "debug-bg-ui-update";
286
+ })(DebugMessageTypeBGtoUI || (DebugMessageTypeBGtoUI = {}));
287
+ var MessageTypeBGtoCS;
288
+ (function (MessageTypeBGtoCS) {
289
+ MessageTypeBGtoCS["ADD_CSS_FILTER"] = "bg-cs-add-css-filter";
290
+ MessageTypeBGtoCS["ADD_DYNAMIC_THEME"] = "bg-cs-add-dynamic-theme";
291
+ MessageTypeBGtoCS["ADD_STATIC_THEME"] = "bg-cs-add-static-theme";
292
+ MessageTypeBGtoCS["ADD_SVG_FILTER"] = "bg-cs-add-svg-filter";
293
+ MessageTypeBGtoCS["CLEAN_UP"] = "bg-cs-clean-up";
294
+ MessageTypeBGtoCS["FETCH_RESPONSE"] = "bg-cs-fetch-response";
295
+ MessageTypeBGtoCS["UNSUPPORTED_SENDER"] = "bg-cs-unsupported-sender";
296
+ })(MessageTypeBGtoCS || (MessageTypeBGtoCS = {}));
297
+ var DebugMessageTypeBGtoCS;
298
+ (function (DebugMessageTypeBGtoCS) {
299
+ DebugMessageTypeBGtoCS["RELOAD"] = "debug-bg-cs-reload";
300
+ })(DebugMessageTypeBGtoCS || (DebugMessageTypeBGtoCS = {}));
301
+ var MessageTypeCStoBG;
302
+ (function (MessageTypeCStoBG) {
303
+ MessageTypeCStoBG["COLOR_SCHEME_CHANGE"] = "cs-bg-color-scheme-change";
304
+ MessageTypeCStoBG["DARK_THEME_DETECTED"] = "cs-bg-dark-theme-detected";
305
+ MessageTypeCStoBG["DARK_THEME_NOT_DETECTED"] =
306
+ "cs-bg-dark-theme-not-detected";
307
+ MessageTypeCStoBG["FETCH"] = "cs-bg-fetch";
308
+ MessageTypeCStoBG["DOCUMENT_CONNECT"] = "cs-bg-document-connect";
309
+ MessageTypeCStoBG["DOCUMENT_FORGET"] = "cs-bg-document-forget";
310
+ MessageTypeCStoBG["DOCUMENT_FREEZE"] = "cs-bg-document-freeze";
311
+ MessageTypeCStoBG["DOCUMENT_RESUME"] = "cs-bg-document-resume";
312
+ })(MessageTypeCStoBG || (MessageTypeCStoBG = {}));
313
+ var DebugMessageTypeCStoBG;
314
+ (function (DebugMessageTypeCStoBG) {
315
+ DebugMessageTypeCStoBG["LOG"] = "debug-cs-bg-log";
316
+ })(DebugMessageTypeCStoBG || (DebugMessageTypeCStoBG = {}));
317
+ var MessageTypeCStoUI;
318
+ (function (MessageTypeCStoUI) {
319
+ MessageTypeCStoUI["EXPORT_CSS_RESPONSE"] = "cs-ui-export-css-response";
320
+ })(MessageTypeCStoUI || (MessageTypeCStoUI = {}));
321
+ var MessageTypeUItoCS;
322
+ (function (MessageTypeUItoCS) {
323
+ MessageTypeUItoCS["EXPORT_CSS"] = "ui-cs-export-css";
324
+ })(MessageTypeUItoCS || (MessageTypeUItoCS = {}));
287
325
 
288
326
  var isNavigatorDefined = typeof navigator !== "undefined";
289
327
  var userAgent = isNavigatorDefined
@@ -306,15 +344,10 @@
306
344
  : "some platform";
307
345
  var isChromium =
308
346
  userAgent.includes("chrome") || userAgent.includes("chromium");
309
- var isThunderbird = userAgent.includes("thunderbird");
310
347
  var isFirefox =
311
348
  userAgent.includes("firefox") ||
312
- userAgent.includes("librewolf") ||
313
- isThunderbird;
314
- userAgent.includes("vivaldi");
315
- userAgent.includes("yabrowser");
316
- userAgent.includes("opr") || userAgent.includes("opera");
317
- userAgent.includes("edg");
349
+ userAgent.includes("thunderbird") ||
350
+ userAgent.includes("librewolf");
318
351
  var isSafari = userAgent.includes("safari") && !isChromium;
319
352
  var isWindows = platform.startsWith("win");
320
353
  var isMacOS = platform.startsWith("mac");
@@ -348,12 +381,22 @@
348
381
  }
349
382
  })();
350
383
  var isCSSColorSchemePropSupported = (function () {
351
- if (typeof document === "undefined") {
384
+ try {
385
+ if (typeof document === "undefined") {
386
+ return false;
387
+ }
388
+ var el = document.createElement("div");
389
+ if (!el || typeof el.style !== "object") {
390
+ return false;
391
+ }
392
+ if (typeof el.style.colorScheme === "string") {
393
+ return true;
394
+ }
395
+ el.setAttribute("style", "color-scheme: dark");
396
+ return el.style.colorScheme === "dark";
397
+ } catch (e) {
352
398
  return false;
353
399
  }
354
- var el = document.createElement("div");
355
- el.setAttribute("style", "color-scheme: dark");
356
- return el.style && el.style.colorScheme === "dark";
357
400
  })();
358
401
 
359
402
  function getOKResponse(url, mimeType, origin) {
@@ -505,7 +548,12 @@
505
548
  return __generator(this, function (_b) {
506
549
  switch (_b.label) {
507
550
  case 0:
508
- if (!(args[0] && args[0].type === MessageType.CS_FETCH))
551
+ if (
552
+ !(
553
+ args[0] &&
554
+ args[0].type === MessageTypeCStoBG.FETCH
555
+ )
556
+ )
509
557
  return [3, 8];
510
558
  id_1 = args[0].id;
511
559
  _b.label = 1;
@@ -530,7 +578,7 @@
530
578
  case 6:
531
579
  messageListeners.forEach(function (cb) {
532
580
  return cb({
533
- type: MessageType.BG_FETCH_RESPONSE,
581
+ type: MessageTypeBGtoCS.FETCH_RESPONSE,
534
582
  data: text_1,
535
583
  error: null,
536
584
  id: id_1
@@ -542,7 +590,7 @@
542
590
  console.error(error_1);
543
591
  messageListeners.forEach(function (cb) {
544
592
  return cb({
545
- type: MessageType.BG_FETCH_RESPONSE,
593
+ type: MessageTypeBGtoCS.FETCH_RESPONSE,
546
594
  data: null,
547
595
  error: error_1,
548
596
  id: id_1
@@ -848,7 +896,7 @@
848
896
  start = now;
849
897
  attempts = 1;
850
898
  }
851
- if (mode === "parent") {
899
+ if (mode === "head") {
852
900
  if (prevSibling && prevSibling.parentNode !== parent) {
853
901
  stop();
854
902
  return;
@@ -863,16 +911,23 @@
863
911
  updateParent(prevSibling.parentNode);
864
912
  }
865
913
  }
914
+ if (mode === "head" && !parent.isConnected) {
915
+ parent = document.head;
916
+ }
866
917
  parent.insertBefore(
867
918
  node,
868
- prevSibling ? prevSibling.nextSibling : parent.firstChild
919
+ prevSibling && prevSibling.isConnected
920
+ ? prevSibling.nextSibling
921
+ : parent.firstChild
869
922
  );
870
923
  observer.takeRecords();
871
924
  onRestore && onRestore();
872
925
  });
873
926
  var observer = new MutationObserver(function () {
874
927
  if (
875
- (mode === "parent" && node.parentNode !== parent) ||
928
+ (mode === "head" &&
929
+ (node.parentNode !== parent ||
930
+ !node.parentNode.isConnected)) ||
876
931
  (mode === "prev-sibling" &&
877
932
  node.previousSibling !== prevSibling)
878
933
  ) {
@@ -1646,7 +1701,7 @@
1646
1701
  var c = $color[i];
1647
1702
  if ((c >= "0" && c <= "9") || c === "." || c === "+" || c === "-") {
1648
1703
  isMining = true;
1649
- } else if (isMining && (c === " " || c === ",")) {
1704
+ } else if (isMining && (c === " " || c === "," || c === "/")) {
1650
1705
  numbers.push($color.substring(prevPos, i));
1651
1706
  isMining = false;
1652
1707
  prevPos = i + 1;
@@ -2469,7 +2524,30 @@
2469
2524
  return toSVGMatrix(createFilterMatrix(config));
2470
2525
  }
2471
2526
 
2472
- var counter = 0;
2527
+ function hexify(number) {
2528
+ return (number < 16 ? "0" : "") + number.toString(16);
2529
+ }
2530
+ function generateUID() {
2531
+ if ("randomUUID" in crypto) {
2532
+ var uuid = crypto.randomUUID();
2533
+ return (
2534
+ uuid.substring(0, 8) +
2535
+ uuid.substring(9, 13) +
2536
+ uuid.substring(14, 18) +
2537
+ uuid.substring(19, 23) +
2538
+ uuid.substring(24)
2539
+ );
2540
+ }
2541
+ if ("getRandomValues" in crypto) {
2542
+ return Array.from(crypto.getRandomValues(new Uint8Array(16)))
2543
+ .map(function (x) {
2544
+ return hexify(x);
2545
+ })
2546
+ .join("");
2547
+ }
2548
+ return Math.floor(Math.random() * Math.pow(2, 55)).toString(36);
2549
+ }
2550
+
2473
2551
  var resolvers$1 = new Map();
2474
2552
  var rejectors = new Map();
2475
2553
  function bgFetch(request) {
@@ -2478,11 +2556,11 @@
2478
2556
  return [
2479
2557
  2,
2480
2558
  new Promise(function (resolve, reject) {
2481
- var id = ++counter;
2559
+ var id = generateUID();
2482
2560
  resolvers$1.set(id, resolve);
2483
2561
  rejectors.set(id, reject);
2484
2562
  chrome.runtime.sendMessage({
2485
- type: MessageType.CS_FETCH,
2563
+ type: MessageTypeCStoBG.FETCH,
2486
2564
  data: request,
2487
2565
  id: id
2488
2566
  });
@@ -2496,7 +2574,7 @@
2496
2574
  data = _a.data,
2497
2575
  error = _a.error,
2498
2576
  id = _a.id;
2499
- if (type === MessageType.BG_FETCH_RESPONSE) {
2577
+ if (type === MessageTypeBGtoCS.FETCH_RESPONSE) {
2500
2578
  var resolve = resolvers$1.get(id);
2501
2579
  var reject = rejectors.get(id);
2502
2580
  resolvers$1.delete(id);
@@ -2658,7 +2736,7 @@
2658
2736
  canvas = document.createElement("canvas");
2659
2737
  canvas.width = maxWidth;
2660
2738
  canvas.height = maxHeight;
2661
- context = canvas.getContext("2d");
2739
+ context = canvas.getContext("2d", {willReadFrequently: true});
2662
2740
  context.imageSmoothingEnabled = false;
2663
2741
  }
2664
2742
  function removeCanvas() {
@@ -2674,7 +2752,13 @@
2674
2752
  naturalHeight = image.naturalHeight;
2675
2753
  if (naturalHeight === 0 || naturalWidth === 0) {
2676
2754
  logWarn("logWarn(Image is empty ".concat(image.currentSrc, ")"));
2677
- return null;
2755
+ return {
2756
+ isDark: false,
2757
+ isLight: false,
2758
+ isTransparent: false,
2759
+ isLarge: false,
2760
+ isTooLarge: false
2761
+ };
2678
2762
  }
2679
2763
  var size = naturalWidth * naturalHeight * 4;
2680
2764
  if (size > MAX_IMAGE_SIZE) {
@@ -2794,44 +2878,44 @@
2794
2878
  var startIndex = conicGradient.length;
2795
2879
  var _loop_1 = function () {
2796
2880
  var typeGradient;
2797
- [linearGradient, radialGradient, conicGradient].find(function (
2798
- possibleType
2799
- ) {
2800
- if (index - possibleType.length >= 0) {
2801
- var possibleGradient = value.substring(
2802
- index - possibleType.length,
2803
- index
2804
- );
2805
- if (possibleGradient === possibleType) {
2806
- if (
2807
- value.slice(
2808
- index - possibleType.length - 10,
2809
- index - possibleType.length - 1
2810
- ) === "repeating"
2811
- ) {
2812
- typeGradient = "repeating-".concat(
2813
- possibleType,
2814
- "gradient"
2815
- );
2816
- return true;
2817
- }
2818
- if (
2819
- value.slice(
2820
- index - possibleType.length - 8,
2821
- index - possibleType.length - 1
2822
- ) === "-webkit"
2823
- ) {
2824
- typeGradient = "-webkit-".concat(
2825
- possibleType,
2826
- "gradient"
2827
- );
2881
+ [linearGradient, radialGradient, conicGradient].find(
2882
+ function (possibleType) {
2883
+ if (index - possibleType.length >= 0) {
2884
+ var possibleGradient = value.substring(
2885
+ index - possibleType.length,
2886
+ index
2887
+ );
2888
+ if (possibleGradient === possibleType) {
2889
+ if (
2890
+ value.slice(
2891
+ index - possibleType.length - 10,
2892
+ index - possibleType.length - 1
2893
+ ) === "repeating"
2894
+ ) {
2895
+ typeGradient = "repeating-".concat(
2896
+ possibleType,
2897
+ "gradient"
2898
+ );
2899
+ return true;
2900
+ }
2901
+ if (
2902
+ value.slice(
2903
+ index - possibleType.length - 8,
2904
+ index - possibleType.length - 1
2905
+ ) === "-webkit"
2906
+ ) {
2907
+ typeGradient = "-webkit-".concat(
2908
+ possibleType,
2909
+ "gradient"
2910
+ );
2911
+ return true;
2912
+ }
2913
+ typeGradient = "".concat(possibleType, "gradient");
2828
2914
  return true;
2829
2915
  }
2830
- typeGradient = "".concat(possibleType, "gradient");
2831
- return true;
2832
2916
  }
2833
2917
  }
2834
- });
2918
+ );
2835
2919
  if (!typeGradient) {
2836
2920
  return "break";
2837
2921
  }
@@ -3154,6 +3238,7 @@
3154
3238
  colorThumb = hslToString(hsl_1);
3155
3239
  colorThumbHover = hslToString(lighten(0.1));
3156
3240
  colorThumbActive = hslToString(lighten(0.2));
3241
+ colorCorner = hslToString(darken(0.5));
3157
3242
  }
3158
3243
  lines.push("::-webkit-scrollbar {");
3159
3244
  lines.push(" background-color: ".concat(colorTrack, ";"));
@@ -3335,48 +3420,54 @@
3335
3420
  /([^\(\),]+(\([^\(\)]*(\([^\(\)]*\)*[^\(\)]*)?\))?([^\(\), ]|( (?!calc)))*),?/g;
3336
3421
  var colorStopRegex =
3337
3422
  /^(from|color-stop|to)\(([^\(\)]*?,\s*)?(.*?)\)$/;
3338
- var parts = getMatches(partsRegex, match, 1).map(function (
3339
- part
3340
- ) {
3341
- part = part.trim();
3342
- var rgb = parseColorWithCache(part);
3343
- if (rgb) {
3344
- return function (filter) {
3345
- return modifyGradientColor(rgb, filter);
3346
- };
3347
- }
3348
- var space = part.lastIndexOf(" ");
3349
- rgb = parseColorWithCache(part.substring(0, space));
3350
- if (rgb) {
3351
- return function (filter) {
3352
- return ""
3353
- .concat(modifyGradientColor(rgb, filter), " ")
3354
- .concat(part.substring(space + 1));
3355
- };
3356
- }
3357
- var colorStopMatch = part.match(colorStopRegex);
3358
- if (colorStopMatch) {
3359
- rgb = parseColorWithCache(colorStopMatch[3]);
3423
+ var parts = getMatches(partsRegex, match, 1).map(
3424
+ function (part) {
3425
+ part = part.trim();
3426
+ var rgb = parseColorWithCache(part);
3427
+ if (rgb) {
3428
+ return function (filter) {
3429
+ return modifyGradientColor(rgb, filter);
3430
+ };
3431
+ }
3432
+ var space = part.lastIndexOf(" ");
3433
+ rgb = parseColorWithCache(part.substring(0, space));
3360
3434
  if (rgb) {
3361
3435
  return function (filter) {
3362
3436
  return ""
3363
- .concat(colorStopMatch[1], "(")
3364
- .concat(
3365
- colorStopMatch[2]
3366
- ? "".concat(colorStopMatch[2], ", ")
3367
- : ""
3368
- )
3369
3437
  .concat(
3370
3438
  modifyGradientColor(rgb, filter),
3371
- ")"
3372
- );
3439
+ " "
3440
+ )
3441
+ .concat(part.substring(space + 1));
3373
3442
  };
3374
3443
  }
3444
+ var colorStopMatch = part.match(colorStopRegex);
3445
+ if (colorStopMatch) {
3446
+ rgb = parseColorWithCache(colorStopMatch[3]);
3447
+ if (rgb) {
3448
+ return function (filter) {
3449
+ return ""
3450
+ .concat(colorStopMatch[1], "(")
3451
+ .concat(
3452
+ colorStopMatch[2]
3453
+ ? "".concat(
3454
+ colorStopMatch[2],
3455
+ ", "
3456
+ )
3457
+ : ""
3458
+ )
3459
+ .concat(
3460
+ modifyGradientColor(rgb, filter),
3461
+ ")"
3462
+ );
3463
+ };
3464
+ }
3465
+ }
3466
+ return function () {
3467
+ return part;
3468
+ };
3375
3469
  }
3376
- return function () {
3377
- return part;
3378
- };
3379
- });
3470
+ );
3380
3471
  return function (filter) {
3381
3472
  return ""
3382
3473
  .concat(typeGradient, "(")
@@ -3492,6 +3583,11 @@
3492
3583
  width = imageDetails.width;
3493
3584
  var result;
3494
3585
  if (isTooLarge) {
3586
+ logInfo(
3587
+ "Not modifying too large image ".concat(
3588
+ imageDetails.src
3589
+ )
3590
+ );
3495
3591
  result = 'url("'.concat(imageDetails.src, '")');
3496
3592
  } else if (
3497
3593
  isDark &&
@@ -3510,6 +3606,11 @@
3510
3606
  result = 'url("'.concat(inverted, '")');
3511
3607
  } else if (isLight && !isTransparent && filter.mode === 1) {
3512
3608
  if (isLarge) {
3609
+ logInfo(
3610
+ "Not modifying light non-transparent large image ".concat(
3611
+ imageDetails.src
3612
+ )
3613
+ );
3513
3614
  result = "none";
3514
3615
  } else {
3515
3616
  logInfo(
@@ -3534,6 +3635,11 @@
3534
3635
  );
3535
3636
  result = 'url("'.concat(filtered, '")');
3536
3637
  } else {
3638
+ logInfo(
3639
+ "Not modifying too large image ".concat(
3640
+ imageDetails.src
3641
+ )
3642
+ );
3537
3643
  result = null;
3538
3644
  }
3539
3645
  return result;
@@ -3579,7 +3685,7 @@
3579
3685
  match: match,
3580
3686
  index: index,
3581
3687
  typeGradient: typeGradient,
3582
- hasComma: hasComma,
3688
+ hasComma: hasComma || false,
3583
3689
  offset: offset
3584
3690
  })
3585
3691
  );
@@ -4119,8 +4225,9 @@
4119
4225
  return;
4120
4226
  }
4121
4227
  this.definedVars.add(varName);
4122
- var color = parseColorWithCache(value);
4123
- if (color) {
4228
+ var isColor =
4229
+ rawValueRegex.test(value) || parseColorWithCache(value);
4230
+ if (isColor) {
4124
4231
  this.unknownColorVars.add(varName);
4125
4232
  } else if (
4126
4233
  value.includes("url(") ||
@@ -4361,8 +4468,8 @@
4361
4468
  if (range) {
4362
4469
  return {start: start, end: range.end};
4363
4470
  }
4364
- return null;
4365
4471
  }
4472
+ return null;
4366
4473
  }
4367
4474
  function getVariablesMatches(input) {
4368
4475
  var ranges = [];
@@ -4736,9 +4843,15 @@
4736
4843
  var cache = [];
4737
4844
  var timeoutId = null;
4738
4845
  var handleAttributeMutations = throttle(function (mutations) {
4846
+ var handledTargets = new Set();
4739
4847
  mutations.forEach(function (m) {
4848
+ var target = m.target;
4849
+ if (handledTargets.has(target)) {
4850
+ return;
4851
+ }
4740
4852
  if (INLINE_STYLE_ATTRS.includes(m.attributeName)) {
4741
- elementStyleDidChange(m.target);
4853
+ handledTargets.add(target);
4854
+ elementStyleDidChange(target);
4742
4855
  }
4743
4856
  });
4744
4857
  });
@@ -5101,6 +5214,9 @@
5101
5214
  modRules.push(rulesModCache.get(cssText));
5102
5215
  return;
5103
5216
  }
5217
+ if (rule.style.all === "revert") {
5218
+ return;
5219
+ }
5104
5220
  var modDecs = [];
5105
5221
  rule.style &&
5106
5222
  iterateCSSDeclarations(
@@ -5250,9 +5366,8 @@
5250
5366
  important,
5251
5367
  sourceValue
5252
5368
  ) {
5253
- var _a = modified,
5254
- varDecs = _a.declarations,
5255
- onTypeChange = _a.onTypeChange;
5369
+ var varDecs = modified.declarations,
5370
+ onTypeChange = modified.onTypeChange;
5256
5371
  var varKey = ++varDeclarationCounter;
5257
5372
  var currentRenderId = renderId;
5258
5373
  var initialIndex = readyDeclarations.length;
@@ -5457,9 +5572,9 @@
5457
5572
  (element instanceof HTMLStyleElement ||
5458
5573
  element instanceof SVGStyleElement ||
5459
5574
  (element instanceof HTMLLinkElement &&
5460
- element.rel &&
5575
+ Boolean(element.rel) &&
5461
5576
  element.rel.toLowerCase().includes("stylesheet") &&
5462
- element.href &&
5577
+ Boolean(element.href) &&
5463
5578
  !element.disabled &&
5464
5579
  (isFirefox
5465
5580
  ? !element.href.startsWith("moz-extension://")
@@ -5502,7 +5617,8 @@
5502
5617
  "__darkreader__inlineScriptsAllowed",
5503
5618
  function () {
5504
5619
  canOptimizeUsingProxy$1 = true;
5505
- }
5620
+ },
5621
+ {once: true, passive: true}
5506
5622
  );
5507
5623
  var loadingLinkCounter = 0;
5508
5624
  var rejectorsForLoadingLinks = new Map();
@@ -5562,6 +5678,9 @@
5562
5678
  if (rule.href) {
5563
5679
  if (checkCrossOrigin) {
5564
5680
  if (
5681
+ !rule.href.startsWith(
5682
+ "https://fonts.googleapis.com/"
5683
+ ) &&
5565
5684
  rule.href.startsWith("http") &&
5566
5685
  !rule.href.startsWith(location.origin)
5567
5686
  ) {
@@ -5653,8 +5772,8 @@
5653
5772
  (accessError = _a[1]);
5654
5773
  if (
5655
5774
  !(
5656
- (!cssRules && !accessError && !isSafari) ||
5657
5775
  (isSafari && !element.sheet) ||
5776
+ (!isSafari && !cssRules && !accessError) ||
5658
5777
  isStillLoadingError(accessError)
5659
5778
  )
5660
5779
  )
@@ -5763,6 +5882,9 @@
5763
5882
  }
5764
5883
  cancelAsyncOperations = false;
5765
5884
  function removeCSSRulesFromSheet(sheet) {
5885
+ if (!sheet) {
5886
+ return;
5887
+ }
5766
5888
  for (var i = sheet.cssRules.length - 1; i >= 0; i--) {
5767
5889
  sheet.deleteRule(i);
5768
5890
  }
@@ -5894,7 +6016,8 @@
5894
6016
  function watchForSheetChangesUsingProxy() {
5895
6017
  element.addEventListener(
5896
6018
  "__darkreader__updateSheet",
5897
- onSheetChange
6019
+ onSheetChange,
6020
+ {passive: true}
5898
6021
  );
5899
6022
  }
5900
6023
  function stopWatchingForSheetChangesUsingProxy() {
@@ -5985,8 +6108,10 @@
5985
6108
  cleanUp();
5986
6109
  reject();
5987
6110
  });
5988
- link.addEventListener("load", onLoad);
5989
- link.addEventListener("error", onError);
6111
+ link.addEventListener("load", onLoad, {passive: true});
6112
+ link.addEventListener("error", onError, {
6113
+ passive: true
6114
+ });
5990
6115
  if (!link.href) {
5991
6116
  onError();
5992
6117
  }
@@ -6139,53 +6264,73 @@
6139
6264
 
6140
6265
  var observers = [];
6141
6266
  var observedRoots;
6267
+ var definedCustomElements = new Set();
6142
6268
  var undefinedGroups = new Map();
6143
6269
  var elementsDefinitionCallback;
6270
+ function isCustomElement(element) {
6271
+ if (element.tagName.includes("-") || element.getAttribute("is")) {
6272
+ return true;
6273
+ }
6274
+ return false;
6275
+ }
6276
+ function recordUndefinedElement(element) {
6277
+ var tag = element.tagName.toLowerCase();
6278
+ if (!tag.includes("-")) {
6279
+ var extendedTag = element.getAttribute("is");
6280
+ if (extendedTag) {
6281
+ tag = extendedTag;
6282
+ } else {
6283
+ return;
6284
+ }
6285
+ }
6286
+ if (!undefinedGroups.has(tag)) {
6287
+ undefinedGroups.set(tag, new Set());
6288
+ customElementsWhenDefined(tag).then(function () {
6289
+ if (elementsDefinitionCallback) {
6290
+ var elements = undefinedGroups.get(tag);
6291
+ undefinedGroups.delete(tag);
6292
+ elementsDefinitionCallback(Array.from(elements));
6293
+ }
6294
+ });
6295
+ }
6296
+ undefinedGroups.get(tag).add(element);
6297
+ }
6144
6298
  function collectUndefinedElements(root) {
6145
6299
  if (!isDefinedSelectorSupported) {
6146
6300
  return;
6147
6301
  }
6148
- forEach(root.querySelectorAll(":not(:defined)"), function (el) {
6149
- var tag = el.tagName.toLowerCase();
6150
- if (!tag.includes("-")) {
6151
- var extendedTag = el.getAttribute("is");
6152
- if (extendedTag) {
6153
- tag = extendedTag;
6154
- } else {
6155
- return;
6156
- }
6157
- }
6158
- if (!undefinedGroups.has(tag)) {
6159
- undefinedGroups.set(tag, new Set());
6160
- customElementsWhenDefined(tag).then(function () {
6161
- if (elementsDefinitionCallback) {
6162
- var elements = undefinedGroups.get(tag);
6163
- undefinedGroups.delete(tag);
6164
- elementsDefinitionCallback(Array.from(elements));
6165
- }
6166
- });
6167
- }
6168
- undefinedGroups.get(tag).add(el);
6169
- });
6302
+ forEach(
6303
+ root.querySelectorAll(":not(:defined)"),
6304
+ recordUndefinedElement
6305
+ );
6170
6306
  }
6171
6307
  var canOptimizeUsingProxy = false;
6172
6308
  document.addEventListener(
6173
6309
  "__darkreader__inlineScriptsAllowed",
6174
6310
  function () {
6175
6311
  canOptimizeUsingProxy = true;
6176
- }
6312
+ },
6313
+ {once: true, passive: true}
6177
6314
  );
6178
6315
  var resolvers = new Map();
6179
6316
  function handleIsDefined(e) {
6180
6317
  canOptimizeUsingProxy = true;
6181
- if (resolvers.has(e.detail.tag)) {
6182
- var resolve = resolvers.get(e.detail.tag);
6183
- resolve();
6318
+ var tag = e.detail.tag;
6319
+ definedCustomElements.add(tag);
6320
+ if (resolvers.has(tag)) {
6321
+ var r = resolvers.get(tag);
6322
+ resolvers.delete(tag);
6323
+ r.forEach(function (r) {
6324
+ return r();
6325
+ });
6184
6326
  }
6185
6327
  }
6186
6328
  function customElementsWhenDefined(tag) {
6187
6329
  return __awaiter(this, void 0, void 0, function () {
6188
6330
  return __generator(this, function (_a) {
6331
+ if (definedCustomElements.has(tag)) {
6332
+ return [2];
6333
+ }
6189
6334
  return [
6190
6335
  2,
6191
6336
  new Promise(function (resolve) {
@@ -6197,7 +6342,11 @@
6197
6342
  return resolve();
6198
6343
  });
6199
6344
  } else if (canOptimizeUsingProxy) {
6200
- resolvers.set(tag, resolve);
6345
+ if (resolvers.has(tag)) {
6346
+ resolvers.get(tag).push(resolve);
6347
+ } else {
6348
+ resolvers.set(tag, [resolve]);
6349
+ }
6201
6350
  document.dispatchEvent(
6202
6351
  new CustomEvent(
6203
6352
  "__darkreader__addUndefinedResolver",
@@ -6317,9 +6466,12 @@
6317
6466
  movedStyles: movedStyles
6318
6467
  });
6319
6468
  additions.forEach(function (n) {
6320
- iterateShadowHosts(n, subscribeForShadowRootChanges);
6469
+ extendedIterateShadowHosts(n);
6321
6470
  collectUndefinedElements(n);
6322
6471
  });
6472
+ additions.forEach(function (node) {
6473
+ return isCustomElement(node) && recordUndefinedElement(node);
6474
+ });
6323
6475
  }
6324
6476
  function handleHugeTreeMutations(root) {
6325
6477
  var styles = new Set(getManageableStyles(root));
@@ -6350,7 +6502,7 @@
6350
6502
  removedStyles: removedStyles,
6351
6503
  movedStyles: movedStyles
6352
6504
  });
6353
- iterateShadowHosts(root, subscribeForShadowRootChanges);
6505
+ extendedIterateShadowHosts(root);
6354
6506
  collectUndefinedElements(root);
6355
6507
  }
6356
6508
  function handleAttributeMutations(mutations) {
@@ -6379,13 +6531,15 @@
6379
6531
  }
6380
6532
  }
6381
6533
  function observe(root) {
6534
+ if (observedRoots.has(root)) {
6535
+ return;
6536
+ }
6382
6537
  var treeObserver = createOptimizedTreeObserver(root, {
6383
6538
  onMinorMutations: handleMinorTreeMutations,
6384
6539
  onHugeMutations: handleHugeTreeMutations
6385
6540
  });
6386
6541
  var attrObserver = new MutationObserver(handleAttributeMutations);
6387
6542
  attrObserver.observe(root, {
6388
- attributes: true,
6389
6543
  attributeFilter: ["rel", "disabled", "media", "href"],
6390
6544
  subtree: true
6391
6545
  });
@@ -6400,11 +6554,11 @@
6400
6554
  observe(shadowRoot);
6401
6555
  shadowRootDiscovered(shadowRoot);
6402
6556
  }
6557
+ function extendedIterateShadowHosts(node) {
6558
+ iterateShadowHosts(node, subscribeForShadowRootChanges);
6559
+ }
6403
6560
  observe(document);
6404
- iterateShadowHosts(
6405
- document.documentElement,
6406
- subscribeForShadowRootChanges
6407
- );
6561
+ extendedIterateShadowHosts(document.documentElement);
6408
6562
  watchWhenCustomElementsDefined(function (hosts) {
6409
6563
  var newStyles = [];
6410
6564
  hosts.forEach(function (host) {
@@ -6417,11 +6571,13 @@
6417
6571
  return;
6418
6572
  }
6419
6573
  subscribeForShadowRootChanges(host);
6420
- iterateShadowHosts(shadowRoot, subscribeForShadowRootChanges);
6574
+ extendedIterateShadowHosts(shadowRoot);
6421
6575
  collectUndefinedElements(shadowRoot);
6422
6576
  });
6423
6577
  });
6424
- document.addEventListener("__darkreader__isDefined", handleIsDefined);
6578
+ document.addEventListener("__darkreader__isDefined", handleIsDefined, {
6579
+ passive: true
6580
+ });
6425
6581
  collectUndefinedElements(document);
6426
6582
  }
6427
6583
  function resetObservers() {
@@ -6436,27 +6592,6 @@
6436
6592
  unsubscribeFromDefineCustomElements();
6437
6593
  }
6438
6594
 
6439
- function hexify(number) {
6440
- return (number < 16 ? "0" : "") + number.toString(16);
6441
- }
6442
- function generateUID() {
6443
- if ("randomUUID" in crypto) {
6444
- var uuid = crypto.randomUUID();
6445
- return (
6446
- uuid.substring(0, 8) +
6447
- uuid.substring(9, 13) +
6448
- uuid.substring(14, 18) +
6449
- uuid.substring(19, 23) +
6450
- uuid.substring(24)
6451
- );
6452
- }
6453
- return Array.from(crypto.getRandomValues(new Uint8Array(16)))
6454
- .map(function (x) {
6455
- return hexify(x);
6456
- })
6457
- .join("");
6458
- }
6459
-
6460
6595
  var adoptedStyleOverrides = new WeakMap();
6461
6596
  var overrideList = new WeakSet();
6462
6597
  function createAdoptedStyleSheetOverride(node) {
@@ -6532,7 +6667,10 @@
6532
6667
  };
6533
6668
  }
6534
6669
 
6535
- function injectProxy(enableStyleSheetsProxy) {
6670
+ function injectProxy(
6671
+ enableStyleSheetsProxy,
6672
+ enableCustomElementRegistryProxy
6673
+ ) {
6536
6674
  document.dispatchEvent(
6537
6675
  new CustomEvent("__darkreader__inlineScriptsAllowed")
6538
6676
  );
@@ -6555,6 +6693,13 @@
6555
6693
  var documentStyleSheetsDescriptor = enableStyleSheetsProxy
6556
6694
  ? Object.getOwnPropertyDescriptor(Document.prototype, "styleSheets")
6557
6695
  : null;
6696
+ var customElementRegistryDefineDescriptor =
6697
+ enableCustomElementRegistryProxy
6698
+ ? Object.getOwnPropertyDescriptor(
6699
+ CustomElementRegistry.prototype,
6700
+ "define"
6701
+ )
6702
+ : null;
6558
6703
  var shouldWrapHTMLElement = [
6559
6704
  "baidu.com",
6560
6705
  "baike.baidu.com",
@@ -6573,6 +6718,10 @@
6573
6718
  "getElementsByTagName"
6574
6719
  )
6575
6720
  : null;
6721
+ var shouldProxyChildNodes = location.hostname === "www.vy.no";
6722
+ var childNodesDescriptor = shouldProxyChildNodes
6723
+ ? Object.getOwnPropertyDescriptor(Node.prototype, "childNodes")
6724
+ : null;
6576
6725
  var cleanUp = function () {
6577
6726
  Object.defineProperty(
6578
6727
  CSSStyleSheet.prototype,
@@ -6606,6 +6755,13 @@
6606
6755
  documentStyleSheetsDescriptor
6607
6756
  );
6608
6757
  }
6758
+ if (enableCustomElementRegistryProxy) {
6759
+ Object.defineProperty(
6760
+ CustomElementRegistry.prototype,
6761
+ "define",
6762
+ customElementRegistryDefineDescriptor
6763
+ );
6764
+ }
6609
6765
  if (shouldWrapHTMLElement) {
6610
6766
  Object.defineProperty(
6611
6767
  Element.prototype,
@@ -6613,27 +6769,43 @@
6613
6769
  getElementsByTagNameDescriptor
6614
6770
  );
6615
6771
  }
6772
+ if (shouldProxyChildNodes) {
6773
+ Object.defineProperty(
6774
+ Node.prototype,
6775
+ "childNodes",
6776
+ childNodesDescriptor
6777
+ );
6778
+ }
6616
6779
  };
6617
- var addUndefinedResolver = function (e) {
6618
- customElements.whenDefined(e.detail.tag).then(function () {
6780
+ var addUndefinedResolverInner = function (tag) {
6781
+ customElements.whenDefined(tag).then(function () {
6619
6782
  document.dispatchEvent(
6620
6783
  new CustomEvent("__darkreader__isDefined", {
6621
- detail: {tag: e.detail.tag}
6784
+ detail: {tag: tag}
6622
6785
  })
6623
6786
  );
6624
6787
  });
6625
6788
  };
6626
- document.addEventListener("__darkreader__cleanUp", cleanUp);
6789
+ var addUndefinedResolver = function (e) {
6790
+ return addUndefinedResolverInner(e.detail.tag);
6791
+ };
6792
+ document.addEventListener("__darkreader__cleanUp", cleanUp, {
6793
+ passive: true
6794
+ });
6627
6795
  document.addEventListener(
6628
6796
  "__darkreader__addUndefinedResolver",
6629
- addUndefinedResolver
6797
+ addUndefinedResolver,
6798
+ {passive: true}
6630
6799
  );
6631
6800
  var updateSheetEvent = new Event("__darkreader__updateSheet");
6632
6801
  function proxyAddRule(selector, style, index) {
6633
6802
  addRuleDescriptor.value.call(this, selector, style, index);
6634
6803
  if (
6635
6804
  this.ownerNode &&
6636
- !this.ownerNode.classList.contains("darkreader")
6805
+ !(
6806
+ this.ownerNode.classList &&
6807
+ this.ownerNode.classList.contains("darkreader")
6808
+ )
6637
6809
  ) {
6638
6810
  this.ownerNode.dispatchEvent(updateSheetEvent);
6639
6811
  }
@@ -6647,7 +6819,10 @@
6647
6819
  );
6648
6820
  if (
6649
6821
  this.ownerNode &&
6650
- !this.ownerNode.classList.contains("darkreader")
6822
+ !(
6823
+ this.ownerNode.classList &&
6824
+ this.ownerNode.classList.contains("darkreader")
6825
+ )
6651
6826
  ) {
6652
6827
  this.ownerNode.dispatchEvent(updateSheetEvent);
6653
6828
  }
@@ -6657,7 +6832,10 @@
6657
6832
  deleteRuleDescriptor.value.call(this, index);
6658
6833
  if (
6659
6834
  this.ownerNode &&
6660
- !this.ownerNode.classList.contains("darkreader")
6835
+ !(
6836
+ this.ownerNode.classList &&
6837
+ this.ownerNode.classList.contains("darkreader")
6838
+ )
6661
6839
  ) {
6662
6840
  this.ownerNode.dispatchEvent(updateSheetEvent);
6663
6841
  }
@@ -6666,7 +6844,10 @@
6666
6844
  removeRuleDescriptor.value.call(this, index);
6667
6845
  if (
6668
6846
  this.ownerNode &&
6669
- !this.ownerNode.classList.contains("darkreader")
6847
+ !(
6848
+ this.ownerNode.classList &&
6849
+ this.ownerNode.classList.contains("darkreader")
6850
+ )
6670
6851
  ) {
6671
6852
  this.ownerNode.dispatchEvent(updateSheetEvent);
6672
6853
  }
@@ -6680,8 +6861,14 @@
6680
6861
  __read(docSheets),
6681
6862
  false
6682
6863
  ).filter(function (styleSheet) {
6683
- return !styleSheet.ownerNode.classList.contains(
6684
- "darkreader"
6864
+ return (
6865
+ styleSheet.ownerNode &&
6866
+ !(
6867
+ styleSheet.ownerNode.classList &&
6868
+ styleSheet.ownerNode.classList.contains(
6869
+ "darkreader"
6870
+ )
6871
+ )
6685
6872
  );
6686
6873
  });
6687
6874
  filteredSheets.item = function (item) {
@@ -6701,6 +6888,15 @@
6701
6888
  elements = new Proxy(elements, styleSheetListBehavior);
6702
6889
  return elements;
6703
6890
  }
6891
+ function proxyCustomElementRegistryDefine(name, constructor, options) {
6892
+ addUndefinedResolverInner(name);
6893
+ customElementRegistryDefineDescriptor.value.call(
6894
+ this,
6895
+ name,
6896
+ constructor,
6897
+ options
6898
+ );
6899
+ }
6704
6900
  function proxyGetElementsByTagName(tagName) {
6705
6901
  var _this = this;
6706
6902
  if (tagName !== "style") {
@@ -6712,11 +6908,17 @@
6712
6908
  tagName
6713
6909
  );
6714
6910
  return Object.setPrototypeOf(
6715
- __spreadArray([], __read(elements), false).filter(function (
6716
- element
6717
- ) {
6718
- return !element.classList.contains("darkreader");
6719
- }),
6911
+ __spreadArray([], __read(elements), false).filter(
6912
+ function (element) {
6913
+ return (
6914
+ element &&
6915
+ !(
6916
+ element.classList &&
6917
+ element.classList.contains("darkreader")
6918
+ )
6919
+ );
6920
+ }
6921
+ ),
6720
6922
  NodeList.prototype
6721
6923
  );
6722
6924
  };
@@ -6731,6 +6933,20 @@
6731
6933
  elements = new Proxy(elements, nodeListBehavior);
6732
6934
  return elements;
6733
6935
  }
6936
+ function proxyChildNodes() {
6937
+ var childNodes = childNodesDescriptor.get.call(this);
6938
+ return Object.setPrototypeOf(
6939
+ __spreadArray([], __read(childNodes), false).filter(
6940
+ function (element) {
6941
+ return (
6942
+ !element.classList ||
6943
+ !element.classList.contains("darkreader")
6944
+ );
6945
+ }
6946
+ ),
6947
+ NodeList.prototype
6948
+ );
6949
+ }
6734
6950
  Object.defineProperty(
6735
6951
  CSSStyleSheet.prototype,
6736
6952
  "addRule",
@@ -6760,6 +6976,15 @@
6760
6976
  })
6761
6977
  );
6762
6978
  }
6979
+ if (enableCustomElementRegistryProxy) {
6980
+ Object.defineProperty(
6981
+ CustomElementRegistry.prototype,
6982
+ "define",
6983
+ Object.assign({}, customElementRegistryDefineDescriptor, {
6984
+ value: proxyCustomElementRegistryDefine
6985
+ })
6986
+ );
6987
+ }
6763
6988
  if (shouldWrapHTMLElement) {
6764
6989
  Object.defineProperty(
6765
6990
  Element.prototype,
@@ -6769,6 +6994,74 @@
6769
6994
  })
6770
6995
  );
6771
6996
  }
6997
+ if (shouldProxyChildNodes) {
6998
+ Object.defineProperty(
6999
+ Node.prototype,
7000
+ "childNodes",
7001
+ Object.assign({}, childNodesDescriptor, {get: proxyChildNodes})
7002
+ );
7003
+ }
7004
+ }
7005
+
7006
+ var documentVisibilityListener = null;
7007
+ var documentIsVisible_ = !document.hidden;
7008
+ var listenerOptions = {
7009
+ capture: true,
7010
+ passive: true
7011
+ };
7012
+ function watchForDocumentVisibility() {
7013
+ document.addEventListener(
7014
+ "visibilitychange",
7015
+ documentVisibilityListener,
7016
+ listenerOptions
7017
+ );
7018
+ window.addEventListener(
7019
+ "pageshow",
7020
+ documentVisibilityListener,
7021
+ listenerOptions
7022
+ );
7023
+ window.addEventListener(
7024
+ "focus",
7025
+ documentVisibilityListener,
7026
+ listenerOptions
7027
+ );
7028
+ }
7029
+ function stopWatchingForDocumentVisibility() {
7030
+ document.removeEventListener(
7031
+ "visibilitychange",
7032
+ documentVisibilityListener,
7033
+ listenerOptions
7034
+ );
7035
+ window.removeEventListener(
7036
+ "pageshow",
7037
+ documentVisibilityListener,
7038
+ listenerOptions
7039
+ );
7040
+ window.removeEventListener(
7041
+ "focus",
7042
+ documentVisibilityListener,
7043
+ listenerOptions
7044
+ );
7045
+ }
7046
+ function setDocumentVisibilityListener(callback) {
7047
+ var alreadyWatching = Boolean(documentVisibilityListener);
7048
+ documentVisibilityListener = function () {
7049
+ if (!document.hidden) {
7050
+ removeDocumentVisibilityListener();
7051
+ callback();
7052
+ documentIsVisible_ = true;
7053
+ }
7054
+ };
7055
+ if (!alreadyWatching) {
7056
+ watchForDocumentVisibility();
7057
+ }
7058
+ }
7059
+ function removeDocumentVisibilityListener() {
7060
+ stopWatchingForDocumentVisibility();
7061
+ documentVisibilityListener = null;
7062
+ }
7063
+ function documentIsVisible() {
7064
+ return documentIsVisible_;
6772
7065
  }
6773
7066
 
6774
7067
  var INSTANCE_ID = generateUID();
@@ -6777,8 +7070,8 @@
6777
7070
  var filter = null;
6778
7071
  var fixes = null;
6779
7072
  var isIFrame$1 = null;
6780
- var ignoredImageAnalysisSelectors = null;
6781
- var ignoredInlineSelectors = null;
7073
+ var ignoredImageAnalysisSelectors = [];
7074
+ var ignoredInlineSelectors = [];
6782
7075
  function createOrUpdateStyle(className, root) {
6783
7076
  if (root === void 0) {
6784
7077
  root = document.head || document;
@@ -6809,7 +7102,7 @@
6809
7102
  function setupNodePositionWatcher(node, alias) {
6810
7103
  nodePositionWatchers.has(alias) &&
6811
7104
  nodePositionWatchers.get(alias).stop();
6812
- nodePositionWatchers.set(alias, watchForNodePosition(node, "parent"));
7105
+ nodePositionWatchers.set(alias, watchForNodePosition(node, "head"));
6813
7106
  }
6814
7107
  function stopStylePositionWatchers() {
6815
7108
  forEach(nodePositionWatchers.values(), function (watcher) {
@@ -6876,11 +7169,12 @@
6876
7169
  setupNodePositionWatcher(overrideStyle, "override");
6877
7170
  var variableStyle = createOrUpdateStyle("darkreader--variables");
6878
7171
  var selectionColors = getSelectionColor(filter);
6879
- var darkSchemeBackgroundColor = filter.darkSchemeBackgroundColor,
6880
- darkSchemeTextColor = filter.darkSchemeTextColor,
6881
- lightSchemeBackgroundColor = filter.lightSchemeBackgroundColor,
6882
- lightSchemeTextColor = filter.lightSchemeTextColor,
6883
- mode = filter.mode;
7172
+ var _a = filter,
7173
+ darkSchemeBackgroundColor = _a.darkSchemeBackgroundColor,
7174
+ darkSchemeTextColor = _a.darkSchemeTextColor,
7175
+ lightSchemeBackgroundColor = _a.lightSchemeBackgroundColor,
7176
+ lightSchemeTextColor = _a.lightSchemeTextColor,
7177
+ mode = _a.mode;
6884
7178
  var schemeBackgroundColor =
6885
7179
  mode === 0 ? lightSchemeBackgroundColor : darkSchemeBackgroundColor;
6886
7180
  var schemeTextColor =
@@ -6914,18 +7208,24 @@
6914
7208
  setupNodePositionWatcher(variableStyle, "variables");
6915
7209
  var rootVarsStyle = createOrUpdateStyle("darkreader--root-vars");
6916
7210
  document.head.insertBefore(rootVarsStyle, variableStyle.nextSibling);
6917
- var injectProxyArg = !(fixes && fixes.disableStyleSheetsProxy);
7211
+ var enableStyleSheetsProxy = !(fixes && fixes.disableStyleSheetsProxy);
7212
+ var enableCustomElementRegistryProxy = !(
7213
+ fixes && fixes.disableCustomElementRegistryProxy
7214
+ );
6918
7215
  {
6919
7216
  var proxyScript = createOrUpdateScript("darkreader--proxy");
6920
7217
  proxyScript.append(
6921
- "(".concat(injectProxy, ")(").concat(injectProxyArg, ")")
7218
+ "("
7219
+ .concat(injectProxy, ")(")
7220
+ .concat(enableStyleSheetsProxy, ", ")
7221
+ .concat(enableCustomElementRegistryProxy, ")")
6922
7222
  );
6923
7223
  document.head.insertBefore(proxyScript, rootVarsStyle.nextSibling);
6924
7224
  proxyScript.remove();
6925
7225
  }
6926
7226
  }
6927
7227
  var shadowRootsWithOverrides = new Set();
6928
- function createShadowStaticStyleOverrides(root) {
7228
+ function createShadowStaticStyleOverridesInner(root) {
6929
7229
  var inlineStyle = createOrUpdateStyle("darkreader--inline", root);
6930
7230
  inlineStyle.textContent = getInlineOverrideStyle();
6931
7231
  root.insertBefore(inlineStyle, root.firstChild);
@@ -6956,6 +7256,81 @@
6956
7256
  root.insertBefore(invertStyle, overrideStyle.nextSibling);
6957
7257
  shadowRootsWithOverrides.add(root);
6958
7258
  }
7259
+ function delayedCreateShadowStaticStyleOverrides(root) {
7260
+ var observer = new MutationObserver(function (mutations, observer) {
7261
+ var e_1, _a, e_2, _b;
7262
+ observer.disconnect();
7263
+ try {
7264
+ for (
7265
+ var mutations_1 = __values(mutations),
7266
+ mutations_1_1 = mutations_1.next();
7267
+ !mutations_1_1.done;
7268
+ mutations_1_1 = mutations_1.next()
7269
+ ) {
7270
+ var _c = mutations_1_1.value,
7271
+ type = _c.type,
7272
+ removedNodes = _c.removedNodes;
7273
+ if (type === "childList") {
7274
+ try {
7275
+ for (
7276
+ var _d =
7277
+ ((e_2 = void 0),
7278
+ __values(removedNodes)),
7279
+ _e = _d.next();
7280
+ !_e.done;
7281
+ _e = _d.next()
7282
+ ) {
7283
+ var _f = _e.value,
7284
+ nodeName = _f.nodeName,
7285
+ className = _f.className;
7286
+ if (
7287
+ nodeName === "STYLE" &&
7288
+ [
7289
+ "darkreader darkreader--inline",
7290
+ "darkreader darkreader--override",
7291
+ "darkreader darkreader--invert"
7292
+ ].includes(className)
7293
+ ) {
7294
+ createShadowStaticStyleOverridesInner(root);
7295
+ return;
7296
+ }
7297
+ }
7298
+ } catch (e_2_1) {
7299
+ e_2 = {error: e_2_1};
7300
+ } finally {
7301
+ try {
7302
+ if (_e && !_e.done && (_b = _d.return))
7303
+ _b.call(_d);
7304
+ } finally {
7305
+ if (e_2) throw e_2.error;
7306
+ }
7307
+ }
7308
+ }
7309
+ }
7310
+ } catch (e_1_1) {
7311
+ e_1 = {error: e_1_1};
7312
+ } finally {
7313
+ try {
7314
+ if (
7315
+ mutations_1_1 &&
7316
+ !mutations_1_1.done &&
7317
+ (_a = mutations_1.return)
7318
+ )
7319
+ _a.call(mutations_1);
7320
+ } finally {
7321
+ if (e_1) throw e_1.error;
7322
+ }
7323
+ }
7324
+ });
7325
+ observer.observe(root, {childList: true});
7326
+ }
7327
+ function createShadowStaticStyleOverrides(root) {
7328
+ var uninit = root.firstChild === null;
7329
+ createShadowStaticStyleOverridesInner(root);
7330
+ if (uninit) {
7331
+ delayedCreateShadowStaticStyleOverrides(root);
7332
+ }
7333
+ }
6959
7334
  function replaceCSSTemplates($cssText) {
6960
7335
  return $cssText.replace(/\${(.+?)}/g, function (_, $color) {
6961
7336
  var color = parseColorWithCache($color);
@@ -6993,15 +7368,11 @@
6993
7368
  });
6994
7369
  variablesStore.matchVariablesAndDependants();
6995
7370
  variablesStore.setOnRootVariableChange(function () {
6996
- variablesStore.putRootVars(
6997
- document.head.querySelector(".darkreader--root-vars"),
6998
- filter
6999
- );
7371
+ var rootVarsStyle = createOrUpdateStyle("darkreader--root-vars");
7372
+ variablesStore.putRootVars(rootVarsStyle, filter);
7000
7373
  });
7001
- variablesStore.putRootVars(
7002
- document.head.querySelector(".darkreader--root-vars"),
7003
- filter
7004
- );
7374
+ var rootVarsStyle = createOrUpdateStyle("darkreader--root-vars");
7375
+ variablesStore.putRootVars(rootVarsStyle, filter);
7005
7376
  styleManagers.forEach(function (manager) {
7006
7377
  return manager.render(filter, ignoredImageAnalysisSelectors);
7007
7378
  });
@@ -7038,7 +7409,7 @@
7038
7409
  function createManager(element) {
7039
7410
  var loadingStyleId = ++loadingStylesCounter;
7040
7411
  function loadingStart() {
7041
- if (!isDOMReady() || !didDocumentShowUp) {
7412
+ if (!isDOMReady() || !documentIsVisible()) {
7042
7413
  loadingStyles.add(loadingStyleId);
7043
7414
  logInfo(
7044
7415
  "Current amount of styles loading: ".concat(
@@ -7109,39 +7480,14 @@
7109
7480
  return;
7110
7481
  }
7111
7482
  }
7112
- var documentVisibilityListener = null;
7113
- var didDocumentShowUp = !document.hidden;
7114
- function watchForDocumentVisibility(callback) {
7115
- var alreadyWatching = Boolean(documentVisibilityListener);
7116
- documentVisibilityListener = function () {
7117
- if (!document.hidden) {
7118
- stopWatchingForDocumentVisibility();
7119
- callback();
7120
- didDocumentShowUp = true;
7121
- }
7122
- };
7123
- if (!alreadyWatching) {
7124
- document.addEventListener(
7125
- "visibilitychange",
7126
- documentVisibilityListener
7127
- );
7128
- }
7129
- }
7130
- function stopWatchingForDocumentVisibility() {
7131
- document.removeEventListener(
7132
- "visibilitychange",
7133
- documentVisibilityListener
7134
- );
7135
- documentVisibilityListener = null;
7483
+ function runDynamicStyle() {
7484
+ createDynamicStyleOverrides();
7485
+ watchForUpdates();
7136
7486
  }
7137
7487
  function createThemeAndWatchForUpdates() {
7138
7488
  createStaticStyleOverrides();
7139
- function runDynamicStyle() {
7140
- createDynamicStyleOverrides();
7141
- watchForUpdates();
7142
- }
7143
- if (document.hidden && !filter.immediateModify) {
7144
- watchForDocumentVisibility(runDynamicStyle);
7489
+ if (!documentIsVisible() && !filter.immediateModify) {
7490
+ setDocumentVisibilityListener(runDynamicStyle);
7145
7491
  } else {
7146
7492
  runDynamicStyle();
7147
7493
  }
@@ -7224,12 +7570,10 @@
7224
7570
  var styleAttr = element.getAttribute("style") || "";
7225
7571
  if (styleAttr.includes("--")) {
7226
7572
  variablesStore.matchVariablesAndDependants();
7227
- variablesStore.putRootVars(
7228
- document.head.querySelector(
7229
- ".darkreader--root-vars"
7230
- ),
7231
- filter
7573
+ var rootVarsStyle = createOrUpdateStyle(
7574
+ "darkreader--root-vars"
7232
7575
  );
7576
+ variablesStore.putRootVars(rootVarsStyle, filter);
7233
7577
  }
7234
7578
  }
7235
7579
  },
@@ -7293,7 +7637,7 @@
7293
7637
  addMetaListener();
7294
7638
  return false;
7295
7639
  }
7296
- function createOrUpdateDynamicTheme(
7640
+ function createOrUpdateDynamicThemeInternal(
7297
7641
  filterConfig,
7298
7642
  dynamicThemeFixes,
7299
7643
  iframe
@@ -7321,6 +7665,7 @@
7321
7665
  isIFrame$1 = iframe;
7322
7666
  if (document.head) {
7323
7667
  if (isAnotherDarkReaderInstanceActive()) {
7668
+ removeDynamicTheme();
7324
7669
  return;
7325
7670
  }
7326
7671
  document.documentElement.setAttribute(
@@ -7394,7 +7739,7 @@
7394
7739
  function cleanDynamicThemeCache() {
7395
7740
  variablesStore.clear();
7396
7741
  parsedURLCache.clear();
7397
- stopWatchingForDocumentVisibility();
7742
+ removeDocumentVisibilityListener();
7398
7743
  cancelRendering();
7399
7744
  stopWatchingForUpdates();
7400
7745
  cleanModificationCache();
@@ -7504,7 +7849,7 @@
7504
7849
  if (theme.engine !== ThemeEngine.dynamicTheme) {
7505
7850
  throw new Error("Theme engine is not supported.");
7506
7851
  }
7507
- createOrUpdateDynamicTheme(theme, fixes, isIFrame);
7852
+ createOrUpdateDynamicThemeInternal(theme, fixes, isIFrame);
7508
7853
  isDarkReaderEnabled = true;
7509
7854
  }
7510
7855
  function isEnabled() {