oc-theme-preload.js 836 B

123456789101112131415161718192021222324252627
  1. ;(function () {
  2. var themeId = localStorage.getItem("opencode-theme-id") || "oc-2"
  3. var scheme = localStorage.getItem("opencode-color-scheme") || "system"
  4. var isDark = scheme === "dark" || (scheme === "system" && matchMedia("(prefers-color-scheme: dark)").matches)
  5. var mode = isDark ? "dark" : "light"
  6. document.documentElement.dataset.theme = themeId
  7. document.documentElement.dataset.colorScheme = mode
  8. if (themeId === "oc-2") return
  9. var css = localStorage.getItem("opencode-theme-css-" + mode)
  10. if (css) {
  11. var style = document.createElement("style")
  12. style.id = "oc-theme-preload"
  13. style.textContent =
  14. ":root{color-scheme:" +
  15. mode +
  16. ";--text-mix-blend-mode:" +
  17. (isDark ? "plus-lighter" : "multiply") +
  18. ";" +
  19. css +
  20. "}"
  21. document.head.appendChild(style)
  22. }
  23. })()