aboutsummarylogtreecommitdiffstats
path: root/whatsapp-nativefier-dark-inject.js
blob: bde8470c42b6b108a1f337cc6b123f12753e1f9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(function () {
  function darkStartup() {
    var css = [
      ":root {",
      "    --dark: #1f232a;",
      "    --darker: #333943;",
      "    --light: #e9e9e9;",
      "    --accent: #7289da;",
      "  }",
      '  body [id *= "startup"] {',
      "    background-color: var(--dark) !important;",
      "  }",
      '  body [id *= "startup"] progress {',
      "    color: var(--accent) !important;",
      "    background-color: var(--darker) !important;",
      "  }",
      '  body [id *= "startup"] ::-moz-progress-bar {',
      "    background-color: var(--accent) !important;",
      "  }",
      '  body [id *= "startup"] circle {',
      "    stroke: var(--light);",
      "  }",
    ].join("\n");

    var node = document.createElement("style");
    node.type = "text/css";
    node.appendChild(document.createTextNode(css));
    var heads = document.getElementsByTagName("head");
    if (heads.length > 0) {
      heads[0].appendChild(node);
    } else {
      // no head yet, stick it whereever
      document.documentElement.appendChild(node);
    }
  }

  function darkTheme() {
    document.body.onload = function () {
      document.body.className = "dark web";
    };
  }

  function serviceWorkerHack() {
    if (
      document.querySelector(
        "a[href='https://support.google.com/chrome/answer/95414']"
      )
    ) {
      navigator.serviceWorker.getRegistration().then((registration) => {
        registration.unregister();
        document.location.reload();
      });
    }
  }

  // Make sure the initial load screen is dark
  darkStartup();
  // Apply official dark theme
  darkTheme();
  // Apply hack for service worker
  serviceWorkerHack();
})();