From dd71cf2d8dac498453614cad56b383eb7a90039e Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 7 Oct 2018 15:29:58 +0800 Subject: [PATCH] feat: extend method Date.Format() --- src/disqus.js | 61 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/src/disqus.js b/src/disqus.js index cca0c9b..d69781c 100644 --- a/src/disqus.js +++ b/src/disqus.js @@ -1,10 +1,3 @@ -/*! - * DisqusJS | v0.1.0 - * Author: SukkaW - * Link: https://github.com/SukkaW/DisqusJS - * License: GPL-3.0 - */ - // Start import baiduTemplate /*! baiduTemplate | Verison 1.0.6 | BSD License */ @@ -227,6 +220,13 @@ // Finish import baiduTemplate +/*! + * DisqusJS | v0.1.0 + * Author: SukkaW + * Link: https://github.com/SukkaW/DisqusJS + * License: GPL-3.0 + */ + /* * The variable used in DisqusJS * @@ -264,6 +264,38 @@ var getLS = function (key) { return localStorage.getItem(key); } +/* + * Name: Date.Format() + * + * Usage: + * Month - M | MM + * Date - d | dd + * Hour - h | hh + * Minute - m | mm + * Second - s | ss + * Season - q | qq + * Year - y | yy | yyyy + * ms - S + * + * Example: (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") + */ + +Date.prototype.Format = function (fmt) { + var o = { + "M+": this.getMonth() + 1, // Minth + "d+": this.getDate(), // Date + "h+": this.getHours(), // Hour + "m+": this.getMinutes(), // Minute + "s+": this.getSeconds(), // Second + "q+": Math.floor((this.getMonth() + 3) / 3), // Season + "S": this.getMilliseconds() // ms + }; + if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); + for (var k in o) + if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); + return fmt; +} + /* * Name: getMode() * Description: get mode from localstorage @@ -272,6 +304,8 @@ var getLS = function (key) { function getMode() { var s = getLS('disqusjs_mode'); if (!s) { + // Run checkDisqus() when no localStorage item + // disqusjs.mode will be set in checkDisqus() checkDisqus(); } else { disqusjs.mode = s; @@ -448,6 +482,19 @@ function getCommentList(data) { } function renderComment(data) { + var commentContainerTpl = ` +
+ +
+ `; + + var commentItemTpl = ` + + ` + + var commentItem; data.map(function (comment) { console.log(comment) })