PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.1.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.1.0
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / assets / js / client_main.js

client_main.js in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.1.0, at assets/js/client_main.js

917 lines 28.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 var darkify_switch_unique_id = darkify_data.darkify_switch_unique_id;
4 var darkify_is_this_admin_panel = darkify_data.darkify_is_this_admin_panel;
5 var darkify_enable_default_dark_mode =
6 darkify_data.darkify_enable_default_dark_mode;
7 var darkify_enable_os_aware = darkify_data.darkify_enable_os_aware;
8 var darkify_enable_keyboard_shortcut =
9 darkify_data.darkify_enable_keyboard_shortcut;
10 var darkify_enable_time_based_dark =
11 darkify_data.darkify_enable_time_based_dark;
12 var darkify_time_based_dark_start = darkify_data.darkify_time_based_dark_start;
13 var darkify_time_based_dark_stop = darkify_data.darkify_time_based_dark_stop;
14 var darkify_alternative_dark_mode_switch =
15 darkify_data.darkify_alternative_dark_mode_switch;
16 var darkify_enable_low_image_brightness =
17 darkify_data.darkify_enable_low_image_brightness;
18 var darkify_image_brightness_to = darkify_data.darkify_image_brightness_to;
19 var darkify_enable_image_grayscale =
20 darkify_data.darkify_enable_image_grayscale;
21 var darkify_image_grayscale_to = darkify_data.darkify_image_grayscale_to;
22 var darkify_disallowed_grayscale_images =
23 darkify_data.darkify_disallowed_grayscale_images;
24 var darkify_enable_bg_image_darken =
25 darkify_data.darkify_enable_bg_image_darken;
26 var darkify_bg_image_darken_to = darkify_data.darkify_bg_image_darken_to;
27 var darkify_enable_invert_inline_svg =
28 darkify_data.darkify_enable_invert_inline_svg;
29 var darkify_enable_low_video_brightness =
30 darkify_data.darkify_enable_low_video_brightness;
31 var darkify_video_brightness_to = darkify_data.darkify_video_brightness_to;
32 var darkify_enable_video_grayscale =
33 darkify_data.darkify_enable_video_grayscale;
34
35 let has_process_run_at_least_once = false;
36 let old_transition = "";
37 let has_background_img_url = false;
38
39 const darkify_disallowed_grayscale_images_arr =
40 darkify_disallowed_grayscale_images.trim().length > 0
41 ? darkify_disallowed_grayscale_images.split(",")
42 : [];
43
44 let darken_level = parseInt(darkify_bg_image_darken_to) / 100;
45 darken_level = darken_level.toFixed(1);
46
47 let darkify_secondary_bg_color = "";
48
49
50
51 darkify_init_keyboard_shortcut_listener();
52 darkify_init_os_mode_change_listener();
53
54 const darkify_observer = new MutationObserver(function (mutationsList) {
55 darkify_init_processes();
56 });
57
58 const elements_class_changed = new MutationObserver((mutationsList) => {
59 if (document.readyState !== "loading") {
60 mutationsList.forEach((mutation) => {
61 const target = mutation.target;
62
63 if (target.classList.contains("darkifycessed")) {
64 if (!target.hasAttribute("data-darkify_preserved_classes")) {
65 target.dataset.darkify_preserved_classes =
66 target.classList.toString();
67 } else {
68 if (
69 target.dataset.darkify_preserved_classes ===
70 target.classList.toString()
71 ) {
72 return;
73 }
74 }
75
76 target.dataset.darkify_preserved_classes = target.classList.toString();
77 elements_class_changed.disconnect();
78 target.classList.remove("darkifycessed");
79 darkifycess_element(target);
80
81 document
82 .querySelectorAll(
83 "*:not(head, title, link, meta, script, style, defs, filter)"
84 )
85 .forEach((element) => {
86 elements_class_changed.observe(element, {
87 attributes: true,
88 attributeFilter: ["class"],
89 });
90 });
91 }
92 });
93 }
94 });
95
96 const dark_mode_status_changed = new MutationObserver((mutationsList) => {
97 mutationsList.forEach((mutation) => {
98 if (mutation.type === "attributes" && mutation.attributeName === "class") {
99 document
100 .querySelectorAll(
101 "*:not(head, title, link, meta, script, style, defs, filter)"
102 )
103 .forEach((element) => {
104 if (element.classList.contains("darkifycessed")) {
105 if (darkify_enable_bg_image_darken === "1") {
106 darkify_darken_bg_image(element, darken_level);
107 }
108 if (
109 (darkify_enable_low_image_brightness === "1" ||
110 darkify_enable_image_grayscale === "1") &&
111 element.nodeName.toLowerCase() === "img"
112 ) {
113 darkify_img_brightness_and_grayscale(element);
114 }
115
116 if (
117 darkify_enable_invert_inline_svg === "1" &&
118 element.nodeName.toLowerCase() === "svg"
119 ) {
120 darkify_invert_inline_svg(element);
121 }
122 if (
123 darkify_enable_low_video_brightness === "1" ||
124 darkify_enable_video_grayscale === "1"
125 ) {
126 if (element.nodeName.toLowerCase() === "video") {
127 darkify_video_brightness_and_grayscale(element);
128 }
129 if (
130 element.nodeName.toLowerCase() === "iframe" &&
131 element.getAttribute("src") != null
132 ) {
133 const srcAttribute = element.getAttribute("src");
134 if (
135 srcAttribute.includes("youtube") ||
136 srcAttribute.includes("vimeo") ||
137 srcAttribute.includes("dailymotion")
138 ) {
139 darkify_video_brightness_and_grayscale(element);
140 }
141 }
142 }
143
144 if (element.hasAttribute("data-darkify_alpha_bg")) {
145 darkify_fix_background_color_alpha(element);
146 }
147 }
148 });
149 }
150 });
151 });
152
153 function darkify_change_state() {
154 if (darkify_is_this_admin_panel === "1") {
155 localStorage.darkify_admin_panel_last_state = document
156 .getElementsByTagName("html")[0]
157 .classList.contains("darkify_dark_mode_enabled")
158 ? "1"
159 : "0";
160 } else {
161 localStorage.darkify_last_state = document
162 .getElementsByTagName("html")[0]
163 .classList.contains("darkify_dark_mode_enabled")
164 ? "1"
165 : "0";
166 }
167 }
168
169 function darkify_switch_trigger() {
170 if (!has_process_run_at_least_once) {
171 darkify_init_processes();
172 darkify_init_observer();
173 }
174
175 const htmlElement = document.getElementsByTagName("html")[0];
176
177 if (htmlElement.classList.contains("darkify_dark_mode_enabled")) {
178 htmlElement.classList.remove("darkify_dark_mode_enabled");
179 } else {
180 htmlElement.classList.add("darkify_dark_mode_enabled");
181 }
182
183 darkify_change_state();
184 }
185
186 function darkify_init_keyboard_shortcut_listener() {
187 if (darkify_enable_keyboard_shortcut === "1") {
188 document.onkeydown = function (event) {
189 if (event.ctrlKey && event.altKey && event.keyCode === 0x44) {
190 darkify_switch_trigger();
191 }
192 };
193 }
194 }
195
196 function darkify_init_os_mode_change_listener() {
197 if (darkify_is_this_admin_panel === "0" && darkify_enable_os_aware === "1") {
198 window
199 .matchMedia("(prefers-color-scheme: dark)")
200 .addEventListener("change", (event) => {
201 const mode = event.matches ? "dark" : "light";
202 const htmlElement = document.getElementsByTagName("html")[0];
203 if (mode === "dark") {
204 htmlElement.classList.add("darkify_dark_mode_enabled");
205 } else if (mode === "light") {
206 htmlElement.classList.remove("darkify_dark_mode_enabled");
207 }
208
209 darkify_change_state();
210 });
211 }
212 }
213
214 function darkify_init_alternative_dark_mode_switch() {
215 if (darkify_alternative_dark_mode_switch.length > 0) {
216 const elements = document.querySelectorAll(
217 darkify_alternative_dark_mode_switch
218 );
219 for (let i = 0; i < elements.length; i++) {
220 const element = elements[i];
221 element.addEventListener("click", () => {
222 darkify_switch_trigger();
223 });
224 }
225 }
226 }
227
228 function get_bg_color_to_preserve(element, fromDataset) {
229 let color = window.getComputedStyle(element, null).backgroundColor;
230 if (!fromDataset) {
231 color = element.dataset.darkify_preserved_bg;
232 }
233 if (
234 (color === "transparent" ||
235 color === "rgba(0, 0, 0, 0)" ||
236 color === "rgba(255,255,255,0)") &&
237 element.parentNode.nodeType === 1
238 ) {
239 color = get_bg_color_to_preserve(element.parentNode, false);
240 } else if (
241 element.parentNode.nodeType === 1 &&
242 element.parentNode.hasAttribute("data-darkify_preserved_bg") &&
243 window.getComputedStyle(element.parentNode, null).backgroundColor === color
244 ) {
245 color = get_bg_color_to_preserve(element.parentNode, false);
246 }
247 return color;
248 }
249
250 function get_txt_color_to_preserve(element, fromDataset) {
251 let color = window.getComputedStyle(element, null).color;
252 if (!fromDataset) {
253 color = element.dataset.darkify_preserved_color;
254 }
255 if (
256 (color === "transparent" ||
257 color === "rgba(0, 0, 0, 0)" ||
258 color === "rgba(255,255,255,0)") &&
259 element.parentNode.nodeType === 1
260 ) {
261 color = get_txt_color_to_preserve(element.parentNode, false);
262 } else if (
263 element.parentNode.nodeType === 1 &&
264 element.parentNode.hasAttribute("data-darkify_preserved_color") &&
265 window.getComputedStyle(element.parentNode, null).color === color
266 ) {
267 color = get_txt_color_to_preserve(element.parentNode, false);
268 }
269 return color;
270 }
271
272 function darkify_darken_bg_image(element, level) {
273 if (
274 document
275 .getElementsByTagName("html")[0]
276 .classList.contains("darkify_dark_mode_enabled")
277 ) {
278 if (
279 window.getComputedStyle(element, null).backgroundImage !== "none" &&
280 window.getComputedStyle(element, null).backgroundImage.includes("url") &&
281 !window
282 .getComputedStyle(element, null)
283 .backgroundImage.includes("rgba(0, 0, 0, " + level + ")")
284 ) {
285 element.style.setProperty(
286 "background-image",
287 "linear-gradient(rgba(0, 0, 0, " +
288 level +
289 "), rgba(0, 0, 0, " +
290 level +
291 ")), " +
292 window.getComputedStyle(element, null).backgroundImage
293 );
294 }
295 } else if (
296 window.getComputedStyle(element, null).backgroundImage !== "none" &&
297 window
298 .getComputedStyle(element, null)
299 .backgroundImage.includes("rgba(0, 0, 0, " + level + ")")
300 ) {
301 element.style.setProperty(
302 "background-image",
303 window
304 .getComputedStyle(element, null)
305 .backgroundImage.replace(
306 "linear-gradient(rgba(0, 0, 0, " +
307 level +
308 "), rgba(0, 0, 0, " +
309 level +
310 ")), ",
311 ""
312 )
313 );
314 }
315 }
316
317 function darkify_img_is_disallowed_for_brightness_and_grayscale(element, type) {
318 if (type === "grayscale") {
319 if (darkify_disallowed_grayscale_images_arr.length > 0) {
320 for (let i = 0; i < darkify_disallowed_grayscale_images_arr.length; i++) {
321 if (darkify_disallowed_grayscale_images_arr[i].trim().length > 0) {
322 const url = darkify_disallowed_grayscale_images_arr[i];
323 const pathname = new URL(url).pathname;
324
325 if (
326 element.getAttribute("src") != null &&
327 element.getAttribute("src").includes(pathname)
328 ) {
329 return true;
330 }
331
332 if (
333 element.getAttribute("srcset") != null &&
334 element.getAttribute("srcset").includes(pathname)
335 ) {
336 return true;
337 }
338 }
339 }
340 }
341 }
342 return false;
343 }
344 function darkify_img_brightness_and_grayscale(element) {
345 var disallowedBrightness =
346 darkify_img_is_disallowed_for_brightness_and_grayscale(
347 element,
348 "brightness"
349 );
350 var disallowedGrayscale =
351 darkify_img_is_disallowed_for_brightness_and_grayscale(
352 element,
353 "grayscale"
354 );
355
356 if (
357 document
358 .getElementsByTagName("html")[0]
359 .classList.contains("darkify_dark_mode_enabled")
360 ) {
361 if (
362 !element.classList.contains("darkify_changed_brightness_and_grayscale")
363 ) {
364 element.dataset.darkify_preserved_filter = element.style.filter;
365 element.classList.add("darkify_changed_brightness_and_grayscale");
366
367 if (
368 darkify_enable_low_image_brightness === "1" &&
369 darkify_enable_image_grayscale === "1" &&
370 !disallowedBrightness &&
371 !disallowedGrayscale
372 ) {
373 element.style.filter =
374 "brightness(" +
375 darkify_image_brightness_to +
376 "%)" +
377 " " +
378 "grayscale(" +
379 darkify_image_grayscale_to +
380 "%)";
381 } else {
382 if (
383 darkify_enable_low_image_brightness === "1" &&
384 !disallowedBrightness
385 ) {
386 element.style.filter =
387 "brightness(" + darkify_image_brightness_to + "%)";
388 } else if (
389 darkify_enable_image_grayscale === "1" &&
390 !disallowedGrayscale
391 ) {
392 element.style.filter =
393 "grayscale(" + darkify_image_grayscale_to + "%)";
394 }
395 }
396 }
397 } else if (
398 element.classList.contains("darkify_changed_brightness_and_grayscale")
399 ) {
400 element.style.filter = element.dataset.darkify_preserved_filter;
401 element.classList.remove("darkify_changed_brightness_and_grayscale");
402 delete element.dataset.darkify_preserved_filter;
403 }
404 }
405
406 function darkify_invert_image(element) {
407 if (element.classList.contains("darkify_inverted_image")) {
408 element.style.filter = element.style.filter.replace("invert(1)", "");
409 element.classList.remove("darkify_inverted_image");
410 }
411 }
412
413 function darkify_invert_inline_svg(element) {
414 if (
415 document
416 .getElementsByTagName("html")[0]
417 .classList.contains("darkify_dark_mode_enabled")
418 ) {
419 element.style.filter = "invert(1)";
420 element.classList.add("darkify_inverted_inline_svg");
421 } else if (element.classList.contains("darkify_inverted_inline_svg")) {
422 element.style.filter = element.style.filter.replace("invert(1)", "");
423 element.classList.remove("darkify_inverted_inline_svg");
424 }
425 }
426
427 function darkify_video_brightness_and_grayscale(element) {
428 if (
429 document
430 .getElementsByTagName("html")[0]
431 .classList.contains("darkify_dark_mode_enabled")
432 ) {
433 if (
434 !element.classList.contains(
435 "darkify_changed_video_brightness_and_grayscale"
436 )
437 ) {
438 element.dataset.darkify_preserved_filter = element.style.filter;
439 element.classList.add("darkify_changed_video_brightness_and_grayscale");
440
441 if (
442 darkify_enable_low_video_brightness === "1" &&
443 darkify_enable_video_grayscale === "1"
444 ) {
445 element.style.filter =
446 "brightness(" +
447 darkifyVideoBrightnessTo +
448 "%)" +
449 " " +
450 "grayscale(" +
451 darkifyVideoGrayscaleTo +
452 "%)";
453 } else {
454 if (darkify_enable_low_video_brightness === "1") {
455 element.style.filter =
456 "brightness(" + darkifyVideoBrightnessTo + "%)";
457 } else if (darkify_enable_video_grayscale === "1") {
458 element.style.filter = "grayscale(" + darkifyVideoGrayscaleTo + "%)";
459 }
460 }
461 }
462 } else if (
463 element.classList.contains("darkify_changed_video_brightness_and_grayscale")
464 ) {
465 element.style.filter = element.dataset.darkify_preserved_filter;
466 element.classList.remove("darkify_changed_video_brightness_and_grayscale");
467 delete element.dataset.darkify_preserved_filter;
468 }
469 }
470
471 function darkify_fix_background_color_alpha(element) {
472 if (
473 document
474 .getElementsByTagName("html")[0]
475 .classList.contains("darkify_dark_mode_enabled")
476 ) {
477 if (element.hasAttribute("data-darkify_alpha_bg")) {
478 const alphaValue = element.dataset.darkify_alpha_bg
479 .replace("rgba(", "")
480 .replace(")", "")
481 .split(",")[3]
482 .trim();
483 const backgroundColor = window.getComputedStyle(
484 element,
485 null
486 ).backgroundColor;
487
488 if (!backgroundColor.includes("rgba")) {
489 element.style.setProperty(
490 "background-color",
491 backgroundColor
492 .replace(")", ", " + alphaValue + ")")
493 .replace("rgb", "rgba"),
494 "important"
495 );
496 }
497 }
498 } else if (element.hasAttribute("data-darkify_alpha_bg")) {
499 element.style.backgroundColor = "";
500 }
501 }
502 function darkify_elements_force_to_correct(element) {
503 if (
504 document
505 .getElementsByTagName("html")[0]
506 .classList.contains("darkify_dark_mode_enabled") &&
507 element.hasAttribute("data-darkify_preserved_bg") &&
508 element.hasAttribute("data-darkify_preserved_color")
509 ) {
510 element.style.setProperty(
511 "background-color",
512 element.dataset.darkify_preserved_bg
513 );
514 element.style.setProperty("color", element.dataset.darkify_preserved_color);
515 }
516 }
517
518 function darkify_implement_secondary_bg() {
519 let maxAreaElement = null;
520 let maxArea = 0;
521
522 const elements = document.querySelectorAll(
523 "* :not(head, title, link, meta, script, style, defs, filter)"
524 );
525
526 for (let i = 0; i < elements.length; i++) {
527 const element = elements[i];
528 if (element.hasAttribute("data-darkify_secondary_bg_finder")) {
529 const secondaryBgColor = element.dataset.darkify_secondary_bg_finder;
530 if (
531 secondaryBgColor !== "transparent" &&
532 secondaryBgColor !== "rgba(0, 0, 0, 0)"
533 ) {
534 const boundingRect = element.getBoundingClientRect();
535 const area = boundingRect.width * boundingRect.height;
536 if (area > maxArea) {
537 maxArea = area;
538 maxAreaElement = secondaryBgColor;
539 }
540 }
541 }
542 }
543
544 for (let i = 0; i < elements.length; i++) {
545 const element = elements[i];
546 if (element.hasAttribute("data-darkify_secondary_bg_finder")) {
547 if (
548 element.classList.contains("darkify_style_all") ||
549 element.classList.contains("darkify_style_bg_txt") ||
550 element.classList.contains("darkify_style_bg_border") ||
551 element.classList.contains("darkify_style_bg")
552 ) {
553 const isDifferentSecondaryBg =
554 maxAreaElement !== element.dataset.darkify_secondary_bg_finder;
555 if (isDifferentSecondaryBg) {
556 element.classList.add("darkify_style_secondary_bg");
557 }
558 }
559 delete element.dataset.darkify_secondary_bg_finder;
560 }
561 }
562
563 darkify_secondary_bg_color = maxAreaElement;
564 }
565
566 function darkify_recheck_on_css_loaded_later() {
567 document
568 .querySelectorAll(
569 ".darkify_style_txt_border, .darkify_style_txt, .darkify_style_border"
570 )
571 .forEach(function (element) {
572 const computedStyle = window.getComputedStyle(element, null);
573 const backgroundColor = computedStyle.backgroundColor;
574 if (
575 backgroundColor !== "rgba(0, 0, 0, 0)" &&
576 backgroundColor !== "rgba(255, 255, 255, 0)"
577 ) {
578 darkifycess_element(element);
579 }
580 });
581 }
582
583 function darkify_check_preloading() {
584 let isPreloaded = false;
585 const lastState = localStorage.darkify_last_state
586 ? localStorage.darkify_last_state
587 : "not_set";
588 const adminPanelLastState = localStorage.darkify_admin_panel_last_state
589 ? localStorage.darkify_admin_panel_last_state
590 : "not_set";
591
592 if (darkify_is_this_admin_panel === "1") {
593 if (adminPanelLastState === "1") {
594 isPreloaded = true;
595 }
596 } else {
597 if (lastState === "1" || lastState === "0") {
598 if (lastState === "1") {
599 isPreloaded = true;
600 }
601 } else {
602 if (darkify_enable_default_dark_mode === "1") {
603 isPreloaded = true;
604 }
605 if (darkify_enable_time_based_dark === "1") {
606 const currentDate = new Date();
607 const darkStart = new Date();
608 const darkStop = new Date();
609 darkStart.setHours(
610 parseInt(darkify_time_based_dark_start.split(":")[0])
611 );
612 darkStart.setMinutes(
613 parseInt(darkify_time_based_dark_start.split(":")[1])
614 );
615 darkStop.setHours(parseInt(darkify_time_based_dark_stop.split(":")[0]));
616 darkStop.setMinutes(
617 parseInt(darkify_time_based_dark_stop.split(":")[1])
618 );
619
620 if (
621 parseInt(darkify_time_based_dark_stop.split(":")[0]) >=
622 parseInt(darkify_time_based_dark_start.split(":")[0])
623 ) {
624 if (
625 currentDate.getTime() > darkStart.getTime() &&
626 currentDate.getTime() < darkStop.getTime()
627 ) {
628 isPreloaded = true;
629 }
630 } else if (currentDate.getHours() > 12) {
631 if (
632 currentDate.getTime() > darkStart.getTime() &&
633 currentDate.getTime() > darkStop.getTime()
634 ) {
635 isPreloaded = true;
636 }
637 } else if (
638 currentDate.getTime() < darkStart.getTime() &&
639 currentDate.getTime() < darkStop.getTime()
640 ) {
641 isPreloaded = true;
642 }
643 }
644 }
645 }
646
647 if (
648 darkify_is_this_admin_panel === "0" &&
649 darkify_enable_os_aware === "1" &&
650 window.matchMedia &&
651 window.matchMedia("(prefers-color-scheme: dark)").matches &&
652 lastState !== "1" &&
653 lastState !== "0"
654 ) {
655 isPreloaded = true;
656 }
657
658 return isPreloaded;
659 }
660
661 function darkifycess_element(element) {
662 var computedStyle = window.getComputedStyle(element, null);
663 var old_transition = "";
664
665 if (computedStyle.transition !== "all 0s ease 0s") {
666 old_transition = computedStyle.transition;
667 element.style.setProperty("transition", "none");
668 }
669
670 if (
671 element.classList.contains("darkify_style_all") ||
672 element.classList.contains("darkify_style_bg_txt") ||
673 element.classList.contains("darkify_style_bg_border") ||
674 element.classList.contains("darkify_style_txt_border") ||
675 element.classList.contains("darkify_style_bg") ||
676 element.classList.contains("darkify_style_txt") ||
677 element.classList.contains("darkify_style_border") ||
678 element.classList.contains("darkify_style_secondary_bg")
679 ) {
680 element.classList.remove("darkify_style_all");
681 element.classList.remove("darkify_style_bg_txt");
682 element.classList.remove("darkify_style_bg_border");
683 element.classList.remove("darkify_style_txt_border");
684 element.classList.remove("darkify_style_bg");
685 element.classList.remove("darkify_style_txt");
686 element.classList.remove("darkify_style_border");
687 element.classList.remove("darkify_style_secondary_bg");
688 }
689
690 var nodeName = element.nodeName.toLowerCase();
691 var backgroundColor = computedStyle.backgroundColor;
692 var color = computedStyle.color;
693 var borderColor = computedStyle.borderColor;
694 var backgroundImage = computedStyle.backgroundImage;
695
696 if (
697 nodeName === "body" &&
698 (backgroundColor === "rgba(0, 0, 0, 0)" ||
699 backgroundColor === "rgba(255, 255, 255, 0)")
700 ) {
701 element.style.setProperty("background-color", "rgb(255, 255, 255)");
702 backgroundColor = window.getComputedStyle(element, null).backgroundColor;
703 }
704 var has_background_img_url = false;
705 if (backgroundImage !== "none" && backgroundImage.includes("url")) {
706 has_background_img_url = true;
707 if (darkify_enable_bg_image_darken === "1") {
708 darkify_darken_bg_image(element, darken_level);
709 }
710 }
711 if (
712 backgroundColor !== "rgba(0, 0, 0, 0)" &&
713 backgroundColor !== "rgba(255, 255, 255, 0)" &&
714 !has_background_img_url
715 ) {
716 if (!element.hasAttribute("data-darkify_secondary_bg_finder")) {
717 element.dataset.darkify_secondary_bg_finder = backgroundColor;
718 }
719 if (darkify_secondary_bg_color !== "") {
720 var isSecondaryBgColorDifferent =
721 darkify_secondary_bg_color !==
722 element.dataset.darkify_secondary_bg_finder;
723 if (isSecondaryBgColorDifferent) {
724 element.classList.add("darkify_style_secondary_bg");
725 }
726 delete element.dataset.darkify_secondary_bg_finder;
727 }
728 }
729 if (
730 backgroundColor !== "rgba(0, 0, 0, 0)" &&
731 color !== "rgba(0, 0, 0, 0)" &&
732 borderColor !== "rgba(0, 0, 0, 0)" &&
733 backgroundColor !== "rgba(255, 255, 255, 0)" &&
734 color !== "rgba(255, 255, 255, 0)" &&
735 borderColor !== "rgba(255, 255, 255, 0)" &&
736 has_background_img_url === false
737 ) {
738 element.classList.add("darkify_style_all");
739 } else {
740 if (
741 backgroundColor !== "rgba(0, 0, 0, 0)" &&
742 color !== "rgba(0, 0, 0, 0)" &&
743 backgroundColor !== "rgba(255, 255, 255, 0)" &&
744 color !== "rgba(255, 255, 255, 0)" &&
745 has_background_img_url === false
746 ) {
747 element.classList.add("darkify_style_bg_txt");
748 } else {
749 if (
750 backgroundColor !== "rgba(0, 0, 0, 0)" &&
751 borderColor !== "rgba(0, 0, 0, 0)" &&
752 backgroundColor !== "rgba(255, 255, 255, 0)" &&
753 borderColor !== "rgba(255, 255, 255, 0)" &&
754 has_background_img_url === false
755 ) {
756 element.classList.add("darkify_style_bg_border");
757 } else {
758 if (
759 color !== "rgba(0, 0, 0, 0)" &&
760 borderColor !== "rgba(0, 0, 0, 0)" &&
761 color !== "rgba(255, 255, 255, 0)" &&
762 borderColor !== "rgba(255, 255, 255, 0)"
763 ) {
764 element.classList.add("darkify_style_txt_border");
765 } else {
766 if (
767 backgroundColor !== "rgba(0, 0, 0, 0)" &&
768 backgroundColor !== "rgba(255, 255, 255, 0)" &&
769 has_background_img_url === false
770 ) {
771 element.classList.add("darkify_style_bg");
772 } else {
773 if (
774 color !== "rgba(0, 0, 0, 0)" &&
775 color !== "rgba(255, 255, 255, 0)"
776 ) {
777 element.classList.add("darkify_style_txt");
778 } else if (
779 borderColor !== "rgba(0, 0, 0, 0)" &&
780 borderColor !== "rgba(255, 255, 255, 0)"
781 ) {
782 element.classList.add("darkify_style_border");
783 }
784 }
785 }
786 }
787 }
788 }
789 if (
790 backgroundImage !== "none" &&
791 !has_background_img_url &&
792 !element.classList.contains("darkify_style_all") &&
793 !element.classList.contains("darkify_style_bg_txt") &&
794 !element.classList.contains("darkify_style_bg_border") &&
795 !element.classList.contains("darkify_style_bg")
796 ) {
797 element.classList.add("darkify_style_bg");
798 }
799
800 if (nodeName === "a") {
801 element.classList.add("darkify_style_link");
802 }
803
804 if (
805 nodeName === "input" ||
806 nodeName === "select" ||
807 nodeName === "textarea"
808 ) {
809 element.classList.add("darkify_style_form_element");
810 }
811
812 if (nodeName === "button") {
813 element.classList.add("darkify_style_button");
814 }
815
816 if (
817 (darkify_enable_low_image_brightness === "1" ||
818 darkify_enable_image_grayscale === "1") &&
819 nodeName === "img"
820 ) {
821 darkify_img_brightness_and_grayscale(element);
822 }
823
824 if (darkify_enable_invert_inline_svg === "1" && nodeName === "svg") {
825 darkify_invert_inline_svg(element);
826 }
827
828 if (
829 darkify_enable_low_video_brightness === "1" ||
830 darkify_enable_video_grayscale === "1"
831 ) {
832 if (nodeName === "video") {
833 darkify_video_brightness_and_grayscale(element);
834 }
835
836 if (nodeName === "iframe") {
837 const srcAttribute = element.getAttribute("src");
838 if (srcAttribute !== null) {
839 if (
840 srcAttribute.includes("youtube") ||
841 srcAttribute.includes("vimeo") ||
842 srcAttribute.includes("dailymotion")
843 ) {
844 darkify_video_brightness_and_grayscale(element);
845 }
846 }
847 }
848 }
849
850 if (backgroundColor.includes("rgba")) {
851 element.dataset.darkify_alpha_bg = backgroundColor;
852 darkify_fix_background_color_alpha(element);
853 }
854
855 if (old_transition !== "") {
856 setTimeout(function () {
857 element.style.setProperty("transition", old_transition);
858 }, 0);
859 }
860
861 setTimeout(function () {
862 elements_class_changed.observe(element, {
863 attributes: true,
864 attributeFilter: ["class"],
865 });
866 }, 0);
867
868 element.classList.add("darkifycessed");
869 }
870
871 function darkify_init_processes() {
872 has_process_run_at_least_once = true;
873 document
874 .querySelectorAll(
875 "* :not(head, title, link, meta, script, style, defs, filter, .darkifycessed)"
876 )
877 .forEach(function (element) {
878 darkifycess_element(element);
879 });
880 }
881
882 function darkify_init_observer() {
883 darkify_observer.observe(document, {
884 attributes: false,
885 childList: true,
886 characterData: false,
887 subtree: true,
888 });
889
890 dark_mode_status_changed.observe(document.getElementsByTagName("html")[0], {
891 attributes: true,
892 });
893
894 if (document.readyState !== "loading") {
895 if (!has_process_run_at_least_once) {
896 darkify_init_processes();
897 }
898 darkify_implement_secondary_bg();
899 darkify_recheck_on_css_loaded_later();
900 } else {
901 document.addEventListener("DOMContentLoaded", function () {
902 if (!has_process_run_at_least_once) {
903 darkify_init_processes();
904 }
905 darkify_implement_secondary_bg();
906 darkify_recheck_on_css_loaded_later();
907 });
908 }
909 }
910
911 if (darkify_check_preloading()) {
912 document
913 .getElementsByTagName("html")[0]
914 .classList.add("darkify_dark_mode_enabled");
915 darkify_init_observer();
916 }
917