|
37 | 37 | }
|
38 | 38 | }(typeof self !== 'undefined' ? self : this, function () {
|
39 | 39 | function DisqusJS(config) {
|
40 |
| - /* |
| 40 | + |
| 41 | + const d = document, |
| 42 | + $$ = (elementID) => d.getElementById(elementID); |
| 43 | + |
| 44 | + /** |
41 | 45 | * get - 封装 XHR GET
|
42 | 46 | *
|
43 | 47 | * @param {string} url
|
|
81 | 85 | // localstorage 操作类
|
82 | 86 | // 用于持久化某些数据(如 newComment 的评论者的相关信息)
|
83 | 87 |
|
84 |
| - /* |
| 88 | + /** |
85 | 89 | * setLS(kwy, value) - 设置 localStorage
|
86 | 90 | *
|
87 | 91 | * @param {string} key
|
|
94 | 98 | }
|
95 | 99 | }
|
96 | 100 |
|
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 |
109 | 103 | *
|
110 | 104 | * @param {string} date - 传入评论创建日期(XML 格式)
|
111 | 105 | * @return {string} - 格式化后的日期
|
112 | 106 | */
|
113 |
| - const dateFormat = (date) => { |
| 107 | + const formatDate = (date) => { |
114 | 108 | // 将传入的 date 转化为时间戳
|
115 | 109 | date = Date.parse(new Date(date));
|
116 | 110 |
|
|
130 | 124 | return `${y}-${m}-${d} ${h}:${minute}`;
|
131 | 125 | }
|
132 | 126 |
|
133 |
| - const d = document, |
134 |
| - $$ = (elementID) => d.getElementById(elementID); |
135 |
| - |
136 | 127 | /*
|
137 | 128 | * loadDisqus() - 加载 Disqus
|
138 | 129 | */
|
|
159 | 150 | let checker = () => {
|
160 | 151 | // 测试域名数量 ==== 测试次数 === 成功次数
|
161 | 152 | // 如果 truw 则认定可以 Disqus 可以连通
|
162 |
| - if ((domain.length === test) && (test === success)) { |
| 153 | + if (domain.length === test === success) { |
163 | 154 | forceDisqus()
|
164 | 155 | // 否则认为 Disqus 无法连通
|
165 | 156 | } else if (domain.length === test) {
|
|
494 | 485 | <div class="dsqjs-post-body">
|
495 | 486 | <div class="dsqjs-post-header">
|
496 | 487 | ${authorEl}
|
497 |
| - <span class="dsqjs-meta"><time>${dateFormat(s.createdAt)}</time></span> |
| 488 | + <span class="dsqjs-meta"><time>${formatDate(s.createdAt)}</time></span> |
498 | 489 | </div>
|
499 | 490 | <div class="dsqjs-post-content">
|
500 | 491 | ${message}
|
501 | 492 | </div>
|
502 | 493 | </div>
|
503 | 494 | </div>
|
504 | 495 | */
|
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>` |
506 | 497 |
|
507 | 498 | return html;
|
508 | 499 | }
|
|
611 | 602 | };
|
612 | 603 |
|
613 | 604 |
|
614 |
| - disqusjs.mode = getLS('dsqjs_mode'); |
| 605 | + disqusjs.mode = localStorage.getItem('dsqjs_mode'); |
615 | 606 |
|
616 | 607 | if (disqusjs.mode === 'disqus') {
|
617 | 608 | loadDisqus();
|
|
0 commit comments