diff options
| author | BigCoke233 <hi@guhub.cn> | 2020-05-30 15:36:38 +0800 |
|---|---|---|
| committer | BigCoke233 <hi@guhub.cn> | 2020-05-30 15:36:38 +0800 |
| commit | 244832eddf5cfa451c0526843a0acb8e463e8785 (patch) | |
| tree | 4f1fa572e24a0949e7d1bf5b2b4829750b811d43 /assets | |
| parent | d253a04f2f378a3d795c2b384ca31a72215e2687 (diff) | |
⚡️ Perf: 用 localStorage 储存 theme,代替 cookie #57
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/js/miracles.min.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/assets/js/miracles.min.js b/assets/js/miracles.min.js index b7bb2a9..26d961c 100644 --- a/assets/js/miracles.min.js +++ b/assets/js/miracles.min.js @@ -6,7 +6,7 @@ */
/**
- * Use cookies
+ * 快速使用 cookies
*/
//add cookie
function addCookie(name, value, expireHours) {
@@ -42,8 +42,17 @@ function getCookie(cname) { }
/**
- * Basic Animation
- * 基础动画
+ * 快速使用 localStorage
+ */
+function setStrg(key, value) {
+ localStorage.setItem(key,value);
+}
+function getStrg(key) {
+ return localStorage.getItem(key);
+}
+
+/**
+ * 动画
*/
function scaleIn(object, time) {
object.css('transition', time).css('transform', 'scale(0)');
@@ -72,9 +81,8 @@ function gotoPosition(e){ var theme = 0;
function Dark() {
theme++;
- //Add cookie to record
if(theme==2){
- addCookie("theme", "2", 9);
+ setStrg("theme", "2");
$("#toggle-dark-button").html('<i class="iconfont icon-moon"></i>');
$("#toggle-dark-mobile").html('<i class="iconfont icon-moon"></i>');
$("body").removeClass("body-sepia");
@@ -82,7 +90,7 @@ function Dark() { alertSend("已切换夜间模式");
}
else if(theme==1){
- addCookie("theme", "1", 9);
+ setStrg("theme", "1");
$("#toggle-dark-button").html('<i class="iconfont icon-sunset"></i>');
$("#toggle-dark-mobile").html('<i class="iconfont icon-sunset"></i>');
$("body").removeClass("body-dark");
@@ -90,7 +98,7 @@ function Dark() { alertSend("已切换日落模式");
}
else {
- addCookie("theme", "3", 9);
+ setStrg("theme", "3");
theme = 0;
$("#toggle-dark-button").html('<i class="iconfont icon-sun"></i>');
$("#toggle-dark-mobile").html('<i class="iconfont icon-sun"></i>');
@@ -101,7 +109,7 @@ function Dark() { }
//auto dark theme
-var whatTheme = getCookie("theme");
+var whatTheme = getStrg("theme");
var schemeGeter = window.matchMedia ("(prefers-color-scheme: dark)");
if (whatTheme == "2" || schemeGeter.matches) {
$("body").addClass("body-dark");
|
