oc-theme-preload.js 865 B

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