Follows System Discord Theme

Witch Discord theme based Automatically on your system theme.

// ==UserScript==
// @name        Follows System Discord  Theme
// @description Witch Discord theme based Automatically  on your system theme.
// @version     0.1.2
// @grant       none
// @match       https://discord.com/*
// @run-at      document-idle
// @namespace https://greasyfork.org/users/749016
// ==/UserScript==
(async function () {
  const modules = await getModules();
 
  let updateLocalSettings;
  for (const module of modules) {
    if ((updateLocalSettings = module.exports?.default?.updateLocalSettings)) {
      break;
    }
  }
 
  const updateTheme = (dark) => {
    updateLocalSettings({ theme: dark ? "dark" : "light" });
  };
 
  const query = matchMedia("(prefers-color-scheme: dark)");
 
  query.addEventListener("change", (event) => {
    updateTheme(event.matches);
  });
 
  setTimeout(() => updateTheme(query.matches), 1500);
})();
 
async function getModules() {
  // ✨✨✨
  const uid = Math.random().toString(36).substring(7);
  return Object.values(
    (
      await new Promise((resolve) => {
        window.webpackJsonp.push([
          [uid],
          { [uid]: (...args) => resolve(args) },
          [[uid]],
        ]);
      })
    )[2].c
  );
}