93 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-04-02 05:34:16 +00:00
import AnimeNotifier from "../AnimeNotifier"
2017-11-16 13:57:49 +00:00
2017-11-16 14:15:35 +00:00
let currentTheme = "light"
2018-03-23 16:40:33 +00:00
const light = {}
const dark = {
2017-11-16 13:57:49 +00:00
"hue": "45",
"saturation": "100%",
"text-color": "hsl(0, 0%, 90%)",
"bg-color": "hsl(0, 0%, 24%)",
"link-color": "hsl(var(--hue), var(--saturation), 66%)",
"link-hover-color": "hsl(var(--hue), var(--saturation), 76%)",
"link-hover-text-shadow": "0 0 8px hsla(var(--hue), var(--saturation), 66%, 0.5)",
"reverse-light-color": "rgba(255, 255, 255, 0.1)",
"reverse-light-hover-color": "rgba(255, 255, 255, 0.2)",
2017-11-28 23:03:44 +00:00
"ui-background": "hsl(0, 0%, 18%)",
"sidebar-background": "hsla(0, 0%, 0%, 0.2)",
"sidebar-opaque-background": "hsl(0, 0%, 18%)",
2017-11-16 13:57:49 +00:00
"table-row-hover-background": "hsla(0, 0%, 100%, 0.01)",
"theme-white": "var(--bg-color)",
"theme-black": "var(--text-color)",
"main-color": "var(--link-color)",
"link-active-color": "var(--link-hover-color)",
"button-hover-color": "var(--link-hover-color)",
2017-11-28 23:03:44 +00:00
"button-hover-background": "hsl(0, 0%, 14%)",
2017-11-16 13:57:49 +00:00
"tab-background": "hsla(0, 0%, 0%, 0.1)",
"tab-hover-background": "hsla(0, 0%, 0%, 0.2)",
"tab-active-color": "hsl(0, 0%, 95%)",
"tab-active-background": "hsla(0, 0%, 2%, 0.5)",
"loading-anim-color": "var(--link-color)",
"anime-alternative-title-color": "hsla(0, 0%, 100%, 0.5)",
"anime-list-item-name-color": "var(--text-color)",
"post-like-color": "var(--link-color)",
"post-unlike-color": "var(--link-color)",
"post-permalink-color": "var(--link-color)",
2018-03-08 16:36:55 +00:00
"quote-color": "var(--text-color)",
"calendar-hover-color": "var(--reverse-light-color)"
2017-11-16 13:57:49 +00:00
}
2017-11-16 14:15:35 +00:00
// Toggle theme
export function toggleTheme(arn: AnimeNotifier) {
2017-11-16 14:15:35 +00:00
if(currentTheme === "light") {
2018-03-13 15:45:40 +00:00
darkTheme(arn)
arn.statusMessage.showInfo("Previewing Dark theme. If you would like to use it permanently, please buy a PRO account.", 4000)
2017-11-16 14:15:35 +00:00
return
}
2018-03-13 15:45:40 +00:00
lightTheme(arn)
2017-11-16 14:15:35 +00:00
}
2017-11-16 13:57:49 +00:00
// Light theme
2018-03-13 15:45:40 +00:00
export function lightTheme(arn: AnimeNotifier) {
2017-11-16 13:57:49 +00:00
let root = document.documentElement
for(let property in light) {
if(!light.hasOwnProperty(property)) {
continue
}
root.style.setProperty(`--${property}`, light[property])
}
2017-11-16 14:15:35 +00:00
currentTheme = "light"
2017-11-16 13:57:49 +00:00
}
// Dark theme
2018-03-13 15:45:40 +00:00
export function darkTheme(arn: AnimeNotifier) {
2017-11-16 13:57:49 +00:00
let root = document.documentElement
2018-03-14 02:50:39 +00:00
// if(arn.user.dataset.pro !== "true") {
// alert("You need a PRO account!")
// }
2018-03-13 15:45:40 +00:00
2017-11-16 13:57:49 +00:00
for(let property in dark) {
if(!dark.hasOwnProperty(property)) {
continue
}
2017-11-16 14:15:35 +00:00
if(light[property] === undefined) {
light[property] = root.style.getPropertyValue(`--${property}`)
}
2017-11-16 13:57:49 +00:00
root.style.setProperty(`--${property}`, dark[property])
}
2017-11-16 14:15:35 +00:00
currentTheme = "dark"
2017-11-16 13:57:49 +00:00
}