diff options
author | Andrew Dolgov <[email protected]> | 2020-04-21 07:49:42 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2020-04-21 07:49:42 +0300 |
commit | bb0bbfb1ed76bb9c429b92d3769c19adef553e43 (patch) | |
tree | 14c6cb620fd9d1851d077800c93c951c83e86f14 /js/common.js | |
parent | f28a75864777b72027275f620feb31a357a5ae3d (diff) |
epubeapp-related stuff
Diffstat (limited to 'js/common.js')
-rw-r--r-- | js/common.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/js/common.js b/js/common.js index ecc8206..45851a7 100644 --- a/js/common.js +++ b/js/common.js @@ -50,3 +50,26 @@ function apply_night_mode(is_night) { $("#theme_css").attr("href", "lib/bootstrap/v3/css/" + (is_night ? "theme-dark.min.css" : "bootstrap-theme.min.css")); } + +const Cookie = { + set: function (name, value, lifetime) { + const d = new Date(); + d.setTime(d.getTime() + lifetime * 1000); + const expires = "expires=" + d.toUTCString(); + document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires; + }, + get: function (name) { + name = name + "="; + const ca = document.cookie.split(';'); + for (let i=0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1); + if (c.indexOf(name) == 0) return decodeURIComponent(c.substring(name.length, c.length)); + } + return ""; + }, + delete: function(name) { + const expires = "expires=Thu, 01-Jan-1970 00:00:01 GMT"; + document.cookie = name + "=" + "" + "; " + expires; + } +}; |