Sfoglia il codice sorgente

스킨 설정 구조 변경

Surplus_Up (2DU) 7 anni fa
parent
commit
ac6ba2acf7
1 ha cambiato i file con 53 aggiunte e 46 eliminazioni
  1. 53 46
      views/neo_yousoro/js/skin_set.js

+ 53 - 46
views/neo_yousoro/js/skin_set.js

@@ -1,69 +1,76 @@
-// 쿠키 생성
-function setCookie(name, value, expiredays) {
-    var cookie = name + "=" + escape(value) + "; path=/;"
-    if (typeof expiredays != 'undefined') {
-        var todayDate = new Date();
-        todayDate.setDate(todayDate.getDate() + expiredays);
-        cookie += "expires=" + todayDate.toGMTString() + ";"
+function get_post() {
+    check = document.getElementById('strike');
+    if(check.checked === true) {
+        document.cookie = 'del_strike=true;';
+    } else {
+        document.cookie = 'del_strike=false;';
     }
-    document.cookie = cookie;
-}
- 
-// 쿠키 획득
-function getCookie(name) {
-    name += "=";
-    var cookie = document.cookie;
-    var startIdx = cookie.indexOf(name);
-    if (startIdx != -1) {
-        startIdx += name.length;
-        var endIdx = cookie.indexOf(";", startIdx);
-        if (endIdx == -1) {
-            endIdx = cookie.length;
-            return unescape(cookie.substring(startIdx, endIdx));
-        }
+
+    check = document.getElementById('include');
+    if(check.checked === true) {
+        document.cookie = 'include_link=true;';
+    } else {
+        document.cookie = 'include_link=false;';
     }
-    return null;
+
+    window.location.reload(true);
 }
- 
-// 쿠키 삭제
-function deleteCookie(name) {
-    setCookie(name, "", -1);
+
+function regex_data(data) {
+    r_data = new RegExp('(?:^|; )' + data + '=([^;]*)')
+
+    return r_data;
 }
 
-// http://vip00112.tistory.com/33
+cookies = document.cookie;
 
-function get_post() {
-    check = document.getElementById('strike');
-    if(check.checked == true) {
-        setCookie("set_strike", "1");
-    } else {
-        deleteCookie("set_strike");
+function main_load() {
+    head_data = document.querySelector('head');
+    if(
+        cookies.match(regex_data('del_strike')) &&
+        cookies.match(regex_data('del_strike'))[1] === 'true'
+    ) {
+        head_data.innerHTML += '<style>s { display: none; }</style>';
     }
-    
-    window.location.reload(true);
-}
 
-head_data = document.querySelector('head');
-if(getCookie("set_strike") == "1") {
-    head_data.innerHTML += '<style>s { display: none; }';
+    if(
+        cookies.match(regex_data('include_link')) &&
+        cookies.match(regex_data('include_link'))[1] === 'true'
+    ) {
+        head_data.innerHTML += '<style>#include_link { display: inline; }</style>';
+    }
 }
 
+main_load();
+
 window.onload = function () {
-    if(window.location.pathname == '/skin_set') {
+    if(window.location.pathname === '/skin_set') {
         document.getElementById("main_top").innerHTML = '<h1>Skin setting</h1>';
-        data = document.getElementById("main_data")
+        document.title = document.title.replace(/.*(\- .*)$/, "Skin setting $1");
         
+        data = document.getElementById("main_data");
         set_data = {};
-        if(getCookie("set_strike") == "1") {
+
+        if(
+            cookies.match(regex_data('del_strike')) &&
+            cookies.match(regex_data('del_strike'))[1] === 'true'
+        ) {
             set_data["strike"] = "checked";
         } 
         
+        if(
+            cookies.match(regex_data('include_link')) &&
+            cookies.match(regex_data('include_link'))[1] === 'true'
+        ) {
+            set_data["include"] = "checked";
+        }
+
         data.innerHTML = ' \
             <input ' + set_data["strike"] + ' type="checkbox" id="strike" name="strike" value="strike"> Remove strikethrough \
-            <hr> \
+            <hr class="main_hr"> \
+            <input ' + set_data["include"] + ' type="checkbox" id="include" name="include" value="include"> Using include link \
+            <hr class="main_hr"> \
             <button onclick="get_post();">Save</button> \
         ';
-                            
-        document.title = document.title.replace(/.*(\- .*)$/, "skin setting $1");
     }
 }