Skip to content

Commit 8b382b1

Browse files
committed
refactor: minor updates
1 parent bec6c16 commit 8b382b1

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/disqus.js

+13-22
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
}
3838
}(typeof self !== 'undefined' ? self : this, function () {
3939
function DisqusJS(config) {
40-
/*
40+
41+
const d = document,
42+
$$ = (elementID) => d.getElementById(elementID);
43+
44+
/**
4145
* get - 封装 XHR GET
4246
*
4347
* @param {string} url
@@ -81,7 +85,7 @@
8185
// localstorage 操作类
8286
// 用于持久化某些数据(如 newComment 的评论者的相关信息)
8387

84-
/*
88+
/**
8589
* setLS(kwy, value) - 设置 localStorage
8690
*
8791
* @param {string} key
@@ -94,23 +98,13 @@
9498
}
9599
}
96100

97-
/*
98-
* getLS(key) - 从 localStorage 条目
99-
*
100-
* @param {string} key
101-
* @return {string} - 返回条目 value 内容
102-
*/
103-
const getLS = (key) => {
104-
return localStorage.getItem(key);
105-
}
106-
107-
/*
108-
* dateFormat(date) - 解析 date 为 yyyy-MM-dd hh:mm:ss
101+
/**
102+
* formatDate(date) - 解析 date 为 yyyy-MM-dd hh:mm:ss
109103
*
110104
* @param {string} date - 传入评论创建日期(XML 格式)
111105
* @return {string} - 格式化后的日期
112106
*/
113-
const dateFormat = (date) => {
107+
const formatDate = (date) => {
114108
// 将传入的 date 转化为时间戳
115109
date = Date.parse(new Date(date));
116110

@@ -130,9 +124,6 @@
130124
return `${y}-${m}-${d} ${h}:${minute}`;
131125
}
132126

133-
const d = document,
134-
$$ = (elementID) => d.getElementById(elementID);
135-
136127
/*
137128
* loadDisqus() - 加载 Disqus
138129
*/
@@ -159,7 +150,7 @@
159150
let checker = () => {
160151
// 测试域名数量 ==== 测试次数 === 成功次数
161152
// 如果 truw 则认定可以 Disqus 可以连通
162-
if ((domain.length === test) && (test === success)) {
153+
if (domain.length === test === success) {
163154
forceDisqus()
164155
// 否则认为 Disqus 无法连通
165156
} else if (domain.length === test) {
@@ -494,15 +485,15 @@
494485
<div class="dsqjs-post-body">
495486
<div class="dsqjs-post-header">
496487
${authorEl}
497-
<span class="dsqjs-meta"><time>${dateFormat(s.createdAt)}</time></span>
488+
<span class="dsqjs-meta"><time>${formatDate(s.createdAt)}</time></span>
498489
</div>
499490
<div class="dsqjs-post-content">
500491
${message}
501492
</div>
502493
</div>
503494
</div>
504495
*/
505-
var html = `<div class="dsqjs-post-item dsqjs-clearfix"><div class="dsqjs-post-avatar">${s.avatarEl}</div><div class="dsqjs-post-body"><div class="dsqjs-post-header">${authorEl}<span class="dsqjs-meta"><time>${dateFormat(s.createdAt)}</time></span></div><div class="dsqjs-post-content">${removeDisqUs(message)}</div></div></div>`
496+
var html = `<div class="dsqjs-post-item dsqjs-clearfix"><div class="dsqjs-post-avatar">${s.avatarEl}</div><div class="dsqjs-post-body"><div class="dsqjs-post-header">${authorEl}<span class="dsqjs-meta"><time>${formatDate(s.createdAt)}</time></span></div><div class="dsqjs-post-content">${removeDisqUs(message)}</div></div></div>`
506497

507498
return html;
508499
}
@@ -611,7 +602,7 @@
611602
};
612603

613604

614-
disqusjs.mode = getLS('dsqjs_mode');
605+
disqusjs.mode = localStorage.getItem('dsqjs_mode');
615606

616607
if (disqusjs.mode === 'disqus') {
617608
loadDisqus();

0 commit comments

Comments
 (0)