localstorage 대신 쿠키 [draft]

1408 단어
            getItem = function () {
                if (document.cookie.length>0) {
                    let c_start=document.cookie.indexOf(name + '=')
                    if (c_start!=-1) { 
                        c_start=c_start + name.length+1 
                        c_end=document.cookie.indexOf(';',c_start)
                        if (c_end==-1) c_end=document.cookie.length
                        return unescape(document.cookie.substring(c_start,c_end))
                    } 
                }
                return '';
            };
            setLocalStorage = function (opened) {
                var value = JSON.stringify({opened: opened, timestamp: new Date().getTime()});
                var name = "kjl_case_guide";
                if (getItem(name) === '') {
                    document.cookie += '; ' + name + '=' + value;
                } else {
                    let c_start=document.cookie.indexOf(name + '=') + name.length + 1;
                    let preString = document.cookie.substr(0, c_start);
                    let c_end=c_end=document.cookie.indexOf(';',c_start);
                    let tailString = document.cookie.substr(c_end, document.cookie.length);
                    document.cookie = c_start + value + tailString;
                }
            };
        }

좋은 웹페이지 즐겨찾기