diff options
| author | Hamidreza Ghavami <hamid.r.gh.1998@gmail.com> | 2023-05-08 16:34:12 +0300 |
|---|---|---|
| committer | Hamidreza Ghavami <hamid.r.gh.1998@gmail.com> | 2023-05-08 16:34:12 +0300 |
| commit | d137deccfa49fdd202dc7ce5147ad71d450c3134 (patch) | |
| tree | d2b665f0cdf820cda9f69cfa767869db692bb02c /web/assets/js/util | |
| parent | 00777e3a258c19301c8b98e55b2b79df8d9585a6 (diff) | |
fix style height when rotating + move cookie util to their specific file
Diffstat (limited to 'web/assets/js/util')
| -rw-r--r-- | web/assets/js/util/common.js | 41 | ||||
| -rw-r--r-- | web/assets/js/util/date-util.js | 5 | ||||
| -rw-r--r-- | web/assets/js/util/utils.js | 15 |
3 files changed, 39 insertions, 22 deletions
diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index b3ebc0bd..808b1ba9 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -56,14 +56,37 @@ function toFixed(num, n) { return Math.round(num * n) / n; } -function debounce (fn, delay) { - var timeoutID = null +function debounce(fn, delay) { + var timeoutID = null; return function () { - clearTimeout(timeoutID) - var args = arguments - var that = this - timeoutID = setTimeout(function () { - fn.apply(that, args) - }, delay) + clearTimeout(timeoutID); + var args = arguments; + var that = this; + timeoutID = setTimeout(function () { + fn.apply(that, args); + }, delay); + }; +} + +function getCookie(cname) { + let name = cname + '='; + let decodedCookie = decodeURIComponent(document.cookie); + let ca = decodedCookie.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 c.substring(name.length, c.length); + } } - }
\ No newline at end of file + return ''; +} + +function setCookie(cname, cvalue, exdays) { + const d = new Date(); + d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); + let expires = 'expires=' + d.toUTCString(); + document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; +} diff --git a/web/assets/js/util/date-util.js b/web/assets/js/util/date-util.js index 24e08879..651101d8 100644 --- a/web/assets/js/util/date-util.js +++ b/web/assets/js/util/date-util.js @@ -128,14 +128,13 @@ Date.prototype.formatDateTime = function (split = ' ') { }; class DateUtil { - // 字符串转 Date 对象 static parseDate(str) { return new Date(str.replace(/-/g, '/')); } static formatMillis(millis) { - return moment(millis).format('YYYY-M-D H:m:s') + return moment(millis).format('YYYY-M-D H:m:s'); } static firstDayOfMonth() { @@ -144,4 +143,4 @@ class DateUtil { date.setMinTime(); return date; } -}
\ No newline at end of file +} diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index 9c441537..28891cd4 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -68,13 +68,11 @@ class HttpUtil { } class PromiseUtil { - static async sleep(timeout) { await new Promise(resolve => { setTimeout(resolve, timeout) }); } - } const seq = [ @@ -95,7 +93,6 @@ const shortIdSeq = [ ]; class RandomUtil { - static randomIntRange(min, max) { return parseInt(Math.random() * (max - min) + min, 10); } @@ -153,8 +150,8 @@ class RandomUtil { static randomText() { var chars = 'abcdefghijklmnopqrstuvwxyz1234567890'; var string = ''; - var len = 6 + Math.floor(Math.random() * 5) - for(var ii=0; ii<len; ii++){ + var len = 6 + Math.floor(Math.random() * 5); + for (var ii = 0; ii < len; ii++) { string += chars[Math.floor(Math.random() * chars.length)]; } return string; @@ -162,11 +159,11 @@ class RandomUtil { static randowShortId() { let str = ''; - str += this.randomShortIdSeq(8) + str += this.randomShortIdSeq(8); return str; } - - static randomShadowsocksPassword(){ + + static randomShadowsocksPassword() { let array = new Uint8Array(32); window.crypto.getRandomValues(array); return btoa(String.fromCharCode.apply(null, array)); @@ -174,7 +171,6 @@ class RandomUtil { } class ObjectUtil { - static getPropIgnoreCase(obj, prop) { for (const name in obj) { if (!obj.hasOwnProperty(name)) { @@ -322,5 +318,4 @@ class ObjectUtil { } return true; } - } |
