oc-theme-preload.js 1.0 KB

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