fix/feat: 0.1.0-alpha-8

0.2.5(deprecated)
SukkaW 7 years ago
parent 7816a15c5c
commit 903c8a0488

2
dist/disqus.js vendored

File diff suppressed because one or more lines are too long

2
dist/disqusjs.css vendored

@ -3,4 +3,4 @@
* Author: SukkaW * Author: SukkaW
* Link: https://github.com/SukkaW/DisqusJS * Link: https://github.com/SukkaW/DisqusJS
* License: GPL-3.0 * License: GPL-3.0
*/#dsqjs .dsqjs-container *{margin:0;padding:0}#dsqjs .dsqjs-container{margin:20px 0 0}#dsqjs ul.dsqjs-list{list-style:none;list-style-type:none}#dsqjs .dsqjs-item-container{position:relative;margin-bottom:24px;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out}#dsqjs .dsqjs-item-container:after,#dsqjs .dsqjs-item-container:before{display:table;content:"";line-height:0;clear:both}#dsqjs .dsqjs-avater{margin-right:12px;float:left;position:relative;z-index:100;padding:0}#dsqjs a{text-decoration:none;color:#076dd0}#dsqjs .dsqjs-avater img{width:42px;height:42px;display:block;border-radius:4px}#dsqjs .dsqjs-body{overflow:hidden}#dsqjs .dsqjs-header{line-height:1;font-size:13px}#dsqjs .dsqjs-bullet{line-height:1.4;margin:0 4px}#dsqjs .dsqjs-bullet::after{color:#c2c6cc;content:"•"}#dsqjs .dsqjs-author{line-height:1;color:#2479cc;font-weight:700}#dsqjs .dsqjs-author .dsqjs-admin-badge{color:#fff;background:#687a86;padding:1px 3px;margin-left:4px;font-size:12px;line-height:1.1;font-weight:700;border-radius:3px;display:inline-block;position:relative;top:-1px;left:1px}#dsqjs .dsqjs-meta{font-size:12px;color:#656c7a}#dsqjs .dsqjs-content p:last-child{margin:0}#dsqjs .dsqjs-content p{font-size:15px;line-height:21px;margin:0 0 12px;word-wrap:break-word}#dsqjs .dsqjs-children>.dsqjs-item{margin-left:60px}#dsqjs .dsqjs-children .dsqjs-avater img{width:38px;height:38px}#dsqjs .dsqjs-message{text-align:center;margin-top:4px;margin-bottom:4px;font-size:14px}#dsqjs .dsqjs-no-comment{text-align:center;margin-top:8px;margin-bottom:4px;font-size:18px;font-weight:700}#dsqjs .dsqjs-message a{margin-left:2px;margin-right:2px}.dsqjs-hide{display:none!important} */#dsqjs>*{margin:0;padding:0}#dsqjs .dsqjs-container *{margin:0;padding:0}#dsqjs .dsqjs-container{margin:20px 0 0}#dsqjs ul.dsqjs-list{list-style:none;list-style-type:none}#dsqjs .dsqjs-item-container{position:relative;margin-bottom:24px;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out}#dsqjs .dsqjs-item-container:after,#dsqjs .dsqjs-item-container:before{display:table;content:"";line-height:0;clear:both}#dsqjs .dsqjs-avater{margin-right:12px;float:left;position:relative;z-index:100;padding:0}#dsqjs a{text-decoration:none;color:#076dd0}#dsqjs .dsqjs-avater img{width:42px;height:42px;display:block;border-radius:4px}#dsqjs .dsqjs-body{overflow:hidden}#dsqjs .dsqjs-header{line-height:1;font-size:13px}#dsqjs .dsqjs-bullet{line-height:1.4;margin:0 4px}#dsqjs .dsqjs-bullet::after{color:#c2c6cc;content:"•"}#dsqjs .dsqjs-author{line-height:1;color:#2479cc;font-weight:700}#dsqjs .dsqjs-author .dsqjs-admin-badge{color:#fff;background:#687a86;padding:1px 3px;margin-left:4px;font-size:12px;line-height:1.1;font-weight:700;border-radius:3px;display:inline-block;position:relative;top:-1px;left:1px}#dsqjs .dsqjs-meta{font-size:12px;color:#656c7a}#dsqjs .dsqjs-content p:last-child{margin:0}#dsqjs .dsqjs-content p{font-size:15px;line-height:21px;margin:0 0 12px;word-wrap:break-word}#dsqjs .dsqjs-children>.dsqjs-item{margin-left:60px}#dsqjs .dsqjs-children .dsqjs-avater img{width:38px;height:38px}#dsqjs .dsqjs-message{text-align:center;margin-top:4px;margin-bottom:4px;font-size:14px}#dsqjs .dsqjs-no-comment{text-align:center;margin-top:8px;margin-bottom:4px;font-size:18px;font-weight:700}#dsqjs .dsqjs-message a{margin-left:2px;margin-right:2px}.dsqjs-hide{display:none!important}

@ -31,7 +31,7 @@ gulp.task('minify-js', () => {
output: { output: {
comments: /^!/ comments: /^!/
}, },
keep_fnames: true keep_fnames: false
})) }))
.pipe(gulp.dest('dist')); .pipe(gulp.dest('dist'));
}); });

@ -1,6 +1,6 @@
{ {
"name": "disqusjs", "name": "disqusjs",
"version": "0.1.0-alpha-5", "version": "0.1.0-alpha-8",
"description": "Show comments list from Disqus API", "description": "Show comments list from Disqus API",
"main": "dist/disqus.js", "main": "dist/disqus.js",
"scripts": { "scripts": {

@ -248,388 +248,391 @@
* disqusjs.page.lenfth - How many comment in this thread * disqusjs.page.lenfth - How many comment in this thread
*/ */
disqusjs.page = []; (function () {
disqusjs.page = [];
window.disqus_config = function () { window.disqus_config = function () {
this.page.url = disqusjs.config.url; this.page.url = disqusjs.config.url;
this.page.identifier = disqusjs.config.identifier; this.page.identifier = disqusjs.config.identifier;
};
var xhr = new XMLHttpRequest();
setLS = (key, value) => {
try {
localStorage.setItem(key, value)
} catch (o) {
console.log(o), console.log("Failed to set localStorage item")
}
}
getLS = (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;
}
/* var xhr = new XMLHttpRequest();
* Name: loadDisqus()
* Descriptin: load disqus as it should be.
*/
loadDisqus = () => { let setLS = (key, value) => {
var d = document; try {
d.getElementById('dsqjs-load-disqus').classList.remove('dsqjs-hide'); localStorage.setItem(key, value)
d.getElementById('dsqjs-force-dsqjs').addEventListener('click', forceDsqjs); } catch (o) {
var s = d.createElement('script'); console.log(o), console.log("Failed to set localStorage item")
s.src = 'https://' + disqusjs.config.shortname + '.disqus.com/embed.js'; }
s.setAttribute('data-timestamp', + new Date()); },
(d.head || d.body).appendChild(s);
}
/* getLS = (key) => {
* Name: checkDisqus() return localStorage.getItem(key);
* Description: Check disqus is avaliable for visitor or not }
* How it works: check favicons under 2 domains can be loaded or not.
*/
checkDisqus = () => { /*
var img = new Image; * Name: Date.Format()
let check1 = setTimeout(() => { *
img.onerror = img.onload = null; * Usage:
setLS('disqusjs_mode', 'dsqjs'); * Month - M | MM
}, 2000); * 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;
}
img.onerror = () => { /*
clearTimeout(check1); * Name: loadDisqus()
setLS('disqusjs_mode', 'dsqjs'); * Descriptin: load disqus as it should be.
main(); */
};
img.onload = () => { let loadDisqus = () => {
clearTimeout(check1); var d = document;
let check2 = setTimeout(() => { d.getElementById('dsqjs-load-disqus').classList.remove('dsqjs-hide');
d.getElementById('dsqjs-force-dsqjs').addEventListener('click', forceDsqjs);
var s = d.createElement('script');
s.src = 'https://' + disqusjs.config.shortname + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', + new Date());
(d.head || d.body).appendChild(s);
}
/*
* Name: checkDisqus()
* Description: Check disqus is avaliable for visitor or not
* How it works: check favicons under 2 domains can be loaded or not.
*/
let checkDisqus = () => {
var img = new Image;
let check1 = setTimeout(() => {
img.onerror = img.onload = null; img.onerror = img.onload = null;
setLS('disqusjs_mode', 'dsqjs'); setLS('disqusjs_mode', 'dsqjs');
}, 2000); }, 2000);
img.onerror = () => { img.onerror = () => {
clearTimeout(check2); clearTimeout(check1);
setLS('disqusjs_mode', 'dsqjs'); setLS('disqusjs_mode', 'dsqjs');
main(); main();
}; };
img.onload = () => { img.onload = () => {
clearTimeout(check2); clearTimeout(check1);
setLS('disqusjs_mode', 'disqus'); let check2 = setTimeout(() => {
main(); img.onerror = img.onload = null;
}; setLS('disqusjs_mode', 'dsqjs');
}, 2000);
img.src = 'https://' + disqusjs.config.shortname + '.disqus.com/favicon.ico?' + +(new Date);
}; img.onerror = () => {
clearTimeout(check2);
img.src = 'https://disqus.com/favicon.ico?' + +(new Date); setLS('disqusjs_mode', 'dsqjs');
} main();
};
/* img.onload = () => {
* Name: forceDsqjs() forceDisqus() clearTimeout(check2);
*/ setLS('disqusjs_mode', 'disqus');
main();
};
forceDsqjs = () => { img.src = 'https://' + disqusjs.config.shortname + '.disqus.com/favicon.ico?' + +(new Date);
setLS('disqusjs_mode', 'dsqjs'); };
main();
}
forceDisqus = () => { img.src = 'https://disqus.com/favicon.ico?' + +(new Date);
setLS('disqusjs_mode', 'disqus'); }
main();
}
/* /*
* Name: loadError() * Name: forceDsqjs() forceDisqus()
* Description: When dsqjs mode load error */
*/
loadError = () => { let forceDsqjs = () => {
document.getElementById('dsqjs-load-error').classList.remove('dsqjs-hide'); setLS('disqusjs_mode', 'dsqjs');
document.getElementById('dsqjs-loading-dsqjs').classList.add('dsqjs-hide'); main();
document.getElementById('dsqjs-reload').addEventListener('click', getThreadInfo); }
}
/* let forceDisqus = () => {
* Name: getThreadInfo() setLS('disqusjs_mode', 'disqus');
* Description: Disqus API only support get thread list by ID, not identifter. So get Thread ID before get thread list. main();
* API Docs: https://disqus.com/api/docs/threads/list/ }
* API URI: /3.0/threads/list.json?forum=[disqus_shortname]&thread=ident:[identifier]&api_key=[apikey]
*/
getThreadInfo = () => { /*
document.getElementById('dsqjs-loading-dsqjs').classList.remove('dsqjs-hide'); * Name: loadError()
document.getElementById('dsqjs-force-disqus').addEventListener('click', forceDisqus); * Description: When dsqjs mode load error
document.getElementById('dsqjs-reload-disqus').addEventListener('click', checkDisqus); */
let url = disqusjs.config.api + '3.0/threads/list.json?forum=' + disqusjs.config.shortname + '&thread=ident:' + disqusjs.config.identifier + '&api_key=' + disqusjs.config.apikey;
xhr.open('GET', url, true); let loadError = () => {
xhr.timeout = 4000; document.getElementById('dsqjs-load-error').classList.remove('dsqjs-hide');
xhr.send(); document.getElementById('dsqjs-loading-dsqjs').classList.add('dsqjs-hide');
xhr.onload = function () { document.getElementById('dsqjs-reload').addEventListener('click', getThreadInfo);
if (this.status == 200 || this.status == 304) { }
var response = JSON.parse(this.responseText).response[0];
disqusjs.page = {
id: response.id,
title: response.title,
isClosed: response.isClosed,
length: response.posts
};
getComment();
}
};
xhr.ontimeout = (e) => {
loadError();
};
xhr.onerror = (e) => {
loadError();
};
}
/* /*
* Name: getComment() * Name: getThreadInfo()
* Description: get the comment content * Description: Disqus API only support get thread list by ID, not identifter. So get Thread ID before get thread list.
* API URI: /3.0/posts/list.json?forum=[shortname]&thread=[thread id]&api_key=[apikey] * API Docs: https://disqus.com/api/docs/threads/list/
*/ * API URI: /3.0/threads/list.json?forum=[disqus_shortname]&thread=ident:[identifier]&api_key=[apikey]
*/
getComment = () => { let getThreadInfo = () => {
let url = disqusjs.config.api + '3.0/posts/list.json?forum=' + disqusjs.config.shortname + '&thread=' + disqusjs.page.id + '&api_key=' + disqusjs.config.apikey; document.getElementById('dsqjs-loading-dsqjs').classList.remove('dsqjs-hide');
xhr.open('GET', url, true); document.getElementById('dsqjs-force-disqus').addEventListener('click', forceDisqus);
xhr.timeout = 4000; document.getElementById('dsqjs-reload-disqus').addEventListener('click', checkDisqus);
xhr.send(); let url = disqusjs.config.api + '3.0/threads/list.json?forum=' + disqusjs.config.shortname + '&thread=ident:' + disqusjs.config.identifier + '&api_key=' + disqusjs.config.apikey;
xhr.onload = function () { xhr.open('GET', url, true);
if (this.status == 200 || this.status == 304) { xhr.timeout = 4000;
var res = JSON.parse(this.responseText); xhr.send();
if (res.code === 0 && res.response.length > 0) { xhr.onload = function () {
getCommentList(res.response); if (this.status == 200 || this.status == 304) {
} else if (res.code === 0 && res.response.length === 0) { var response = JSON.parse(this.responseText).response[0];
// Have no comments. disqusjs.page = {
document.getElementById('dsqjs-no-comment').classList.remove('dsqjs-hide'); id: response.id,
title: response.title,
isClosed: response.isClosed,
length: response.posts
};
getComment();
} }
};
xhr.ontimeout = (e) => {
loadError();
};
xhr.onerror = (e) => {
loadError();
};
}
} /*
}; * Name: getComment()
xhr.ontimeout = (e) => { * Description: get the comment content
// Have error when get comments. * API URI: /3.0/posts/list.json?forum=[shortname]&thread=[thread id]&api_key=[apikey]
loadError(); */
};
xhr.onerror = (e) => { let getComment = () => {
// Have error when get comments. let url = disqusjs.config.api + '3.0/posts/list.json?forum=' + disqusjs.config.shortname + '&thread=' + disqusjs.page.id + '&api_key=' + disqusjs.config.apikey;
loadError(); xhr.open('GET', url, true);
}; xhr.timeout = 4000;
} xhr.send();
xhr.onload = function () {
/* if (this.status == 200 || this.status == 304) {
* Name: getCommentList(data) var res = JSON.parse(this.responseText);
* Description: Render JSON to comment list components if (res.code === 0 && res.response.length > 0) {
*/ getCommentList(res.response);
} else if (res.code === 0 && res.response.length === 0) {
// Have no comments.
document.getElementById('dsqjs-no-comment').classList.remove('dsqjs-hide');
}
getCommentList = (data) => { }
var topLevelComments = []; };
var childComments = []; xhr.ontimeout = (e) => {
// Have error when get comments.
loadError();
};
xhr.onerror = (e) => {
// Have error when get comments.
loadError();
};
}
data.forEach(comment => { /*
(comment.parent ? childComments : topLevelComments)['push'](comment) * Name: getCommentList(data)
}) * Description: Render JSON to comment list components
*/
let getCommentList = (data) => {
var topLevelComments = [];
var childComments = [];
data.forEach(comment => {
(comment.parent ? childComments : topLevelComments)['push'](comment)
})
var commentLists = topLevelComments.map(comment => {
return {
comment,
author: comment.author.name,
isPrimary: comment.author.username === disqusjs.config.admin,
children: getChildren(+comment.id)
};
});
function getChildren(id) {
if (childComments.length === 0) return null;
var list = [];
for (let comment of childComments) {
if (comment.parent === id) {
list.unshift({
comment,
author: comment.author.name,
isPrimary: comment.author.username === disqusjs.config.admin,
children: getChildren(+comment.id)
});
}
}
var commentLists = topLevelComments.map(comment => { if (list.length) {
return { return list;
comment, } else {
author: comment.author.name, return null;
isPrimary: comment.author.username === disqusjs.config.admin,
children: getChildren(+comment.id)
};
});
function getChildren(id) {
if (childComments.length === 0) return null;
var list = [];
for (let comment of childComments) {
if (comment.parent === id) {
list.unshift({
comment,
author: comment.author.name,
isPrimary: comment.author.username === disqusjs.config.admin,
children: getChildren(+comment.id)
});
} }
} }
if (list.length) { renderComment(commentLists)
return list;
} else {
return null;
}
} }
renderComment(commentLists) let renderComment = (data) => {
} /*
<div class="dsqjs-item-container">
renderComment = (data) => { <div class="dsqjs-avater">
/* <%- avatarEl %>
<div class="dsqjs-item-container"> </div>
<div class="dsqjs-avater"> <div class="dsqjs-body">
<%- avatarEl %> <header class="dsqjs-header">
</div> <span class="dsqjs-author"><%- authorEl %></span>
<div class="dsqjs-body"> <span class="dsqjs-bullet"></span>
<header class="dsqjs-header"> <span class="dsqjs-meta"><time><%- (new Date(createdAt)).Format("yyyy-MM-dd hh:mm:ss") %></time></span>
<span class="dsqjs-author"><%- authorEl %></span> </header>
<span class="dsqjs-bullet"></span> <div class="dsqjs-content"><%- message %></div>
<span class="dsqjs-meta"><time><%- (new Date(createdAt)).Format("yyyy-MM-dd hh:mm:ss") %></time></span> </div>
</header>
<div class="dsqjs-content"><%- message %></div>
</div> </div>
</div> */
*/ var commentBodyTpl = `<div class="dsqjs-item-container"><div class="dsqjs-avater"><%- avatarEl %></div><div class="dsqjs-body"><header class="dsqjs-header"><span class="dsqjs-author"><%- authorEl %></span><span class="dsqjs-bullet"></span><span class="dsqjs-meta"><time><%- (new Date(createdAt)).Format("yyyy-MM-dd hh:mm:ss") %></time></span></header><div class="dsqjs-content"><%- message %></div></div></div>`
var commentBodyTpl = `<div class="dsqjs-item-container"><div class="dsqjs-avater"><%- avatarEl %></div><div class="dsqjs-body"><header class="dsqjs-header"><span class="dsqjs-author"><%- authorEl %></span><span class="dsqjs-bullet"></span><span class="dsqjs-meta"><time><%- (new Date(createdAt)).Format("yyyy-MM-dd hh:mm:ss") %></time></span></header><div class="dsqjs-content"><%- message %></div></div></div>`
data.map(s => { data.map(s => {
childrenComments = (s) => { let childrenComments = (s) => {
var nesting = s.nesting var nesting = s.nesting
var children = (s.children || []); var children = (s.children || []);
if (typeof children === 'null') { if (typeof children === 'null') {
return; return;
} }
if (nesting < 4) { if (nesting < 4) {
var html = '<ul class="dsqjs-list dsqjs-children">'; var html = '<ul class="dsqjs-list dsqjs-children">';
} else { } else {
var html = '<ul class="dsqjs-list">'; var html = '<ul class="dsqjs-list">';
} }
children.map(s => { children.map(s => {
let comment = s.comment let comment = s.comment
if (comment.author.profileUrl) { if (comment.author.profileUrl) {
/* /*
<a href="${comment.author.profileUrl}" target="_blank" rel="nofollow noopener noreferrer"> <a href="${comment.author.profileUrl}" target="_blank" rel="nofollow noopener noreferrer">
<img src="${comment.author.avatar.cache}"> <img src="${comment.author.avatar.cache}">
</a> </a>
*/ */
comment.avatarEl = `<a href="${comment.author.profileUrl}" target="_blank" rel="nofollow noopener noreferrer"><img src="${comment.author.avatar.cache}"></a>`; comment.avatarEl = `<a href="${comment.author.profileUrl}" target="_blank" rel="nofollow noopener noreferrer"><img src="${comment.author.avatar.cache}"></a>`;
comment.authorEl = `<a href="${comment.author.profileUrl}">${comment.author.name}</a>` comment.authorEl = `<a href="${comment.author.profileUrl}">${comment.author.name}</a>`
} else { } else {
comment.avatarEl = `<img src="${comment.author.avatar.cache}">`; comment.avatarEl = `<img src="${comment.author.avatar.cache}">`;
comment.authorEl = `${comment.author.name}` comment.authorEl = `${comment.author.name}`
} }
if (comment.author.name === disqusjs.config.admin) { if (comment.author.name === disqusjs.config.admin) {
comment.authorEl += `<span class="dsqjs-admin-badge">${disqusjs.config.adminLabel}</span>` comment.authorEl += `<span class="dsqjs-admin-badge">${disqusjs.config.adminLabel}</span>`
} }
s.nesting = nesting + 1 s.nesting = nesting + 1
html += `<li class="dsqjs-item" id="comment-${comment.id}">` html += `<li class="dsqjs-item" id="comment-${comment.id}">`
html += baidu.template(commentBodyTpl, comment) html += baidu.template(commentBodyTpl, comment)
html += `${childrenComments(s)}</li>` html += `${childrenComments(s)}</li>`
}) })
html += '</ul>'; html += '</ul>';
if (html.length !== 0) { if (html.length !== 0) {
return html; return html;
} else { } else {
return; return;
} }
}; };
let comment = s.comment; let comment = s.comment;
if (comment.author.profileUrl) { if (comment.author.profileUrl) {
comment.avatarEl = `<a href="${comment.author.profileUrl}" target="_blank" rel="nofollow noopener noreferrer"><img src="${comment.author.avatar.cache}"></a>`; comment.avatarEl = `<a href="${comment.author.profileUrl}" target="_blank" rel="nofollow noopener noreferrer"><img src="${comment.author.avatar.cache}"></a>`;
comment.authorEl = `<a href="${comment.author.profileUrl}">${comment.author.name}</a>` comment.authorEl = `<a href="${comment.author.profileUrl}">${comment.author.name}</a>`
} else { } else {
comment.avatarEl = `<img src="${comment.author.avatar.cache}">`; comment.avatarEl = `<img src="${comment.author.avatar.cache}">`;
comment.authorEl = `${comment.author.name}` comment.authorEl = `${comment.author.name}`
} }
if (comment.author.name === disqusjs.config.admin) { if (comment.author.name === disqusjs.config.admin) {
comment.authorEl += `<span class="dsqjs-admin-badge">${disqusjs.config.adminLabel}</span>` comment.authorEl += `<span class="dsqjs-admin-badge">${disqusjs.config.adminLabel}</span>`
} }
if (s.children) { if (s.children) {
s.nesting = 1 s.nesting = 1
} }
let html = `<li class="dsqjs-item" id="comment-${comment.id}">` let html = `<li class="dsqjs-item" id="comment-${comment.id}">`
html += baidu.template(commentBodyTpl, comment) html += baidu.template(commentBodyTpl, comment)
html += `${childrenComments(s)}</li>`; html += `${childrenComments(s)}</li>`;
document.getElementById('dsqjs-list').insertAdjacentHTML('beforeend', html); document.getElementById('dsqjs-list').insertAdjacentHTML('beforeend', html);
}) })
} }
main = () => { let main = () => {
// Add dsqjs container element to #disqus_thread // Add dsqjs container element to #disqus_thread
/*
<div id="dsqjs">
<section class="dsqjs-action"></section>
<header></header>
<section class="dsqjs-info">
<p id="dsqjs-load-disqus" class="dsqjs-message dsqjs-hide">评论完整模式加载中...如果长时间无法加载请针对 disq.us | disquscdn.com | disqus.com 启用代理或使用<a href="#" id="dsqjs-force-dsqjs">评论基础模式</a></p>
<p id="dsqjs-loading-dsqjs" class="dsqjs-message dsqjs-hide">你可能无法访问 Disqus已启用评论基础模式如需完整体验请针对 disq.us | disquscdn.com | disqus.com 启用代理并<a href="#" id="dsqjs-reload-disqus">尝试使用完整 Disqus 模式</a> | <a href="#" id="dsqjs-force-disqus"> Disqus </a></p>
<p id="dsqjs-load-error" class="dsqjs-message dsqjs-hide">评论基础模式出现错误是否<a href="#" id="dsqjs-reload">重载</a></p>
<p id="dsqjs-no-comment" class="dsqjs-no-comment dsqjs-hide">这里冷冷清清的一条评论都没有</p>
</section>
<section class="dsqjs-container" id="dsqjs-container"><ul id="dsqjs-list" class="dsqjs-list"></ul></section>
</div>
*/
var disqusjsBaseTpl = `<div id="dsqjs"><section class="dsqjs-action"></section><header></header><section class="dsqjs-info"><p id="dsqjs-load-disqus" class="dsqjs-message dsqjs-hide">评论完整模式加载中...如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理,或使用<a href="#" id="dsqjs-force-dsqjs">评论基础模式</a></p><p id="dsqjs-loading-dsqjs" class="dsqjs-message dsqjs-hide">你可能无法访问 Disqus已启用评论基础模式。如需完整体验请针对 disq.us | disquscdn.com | disqus.com 启用代理并<a href="#" id="dsqjs-reload-disqus">尝试使用完整 Disqus 模式</a> | <a href="#" id="dsqjs-force-disqus">强制完整 Disqus 模式</a>。</p><p id="dsqjs-load-error" class="dsqjs-message dsqjs-hide">评论基础模式出现错误,是否<a href="#" id="dsqjs-reload">重载</a></p><p id="dsqjs-no-comment" class="dsqjs-no-comment dsqjs-hide">这里冷冷清清的,一条评论都没有</p></section><section class="dsqjs-container" id="dsqjs-container"><ul id="dsqjs-list" class="dsqjs-list"></ul></section></div>`;
document.getElementById('disqus_thread').innerHTML = disqusjsBaseTpl;
disqusjs.mode = getLS('disqusjs_mode');
if (disqusjs.mode === 'disqus') {
loadDisqus();
} else if (disqusjs.mode === 'dsqjs') {
getThreadInfo();
} else {
// Run checkDisqus() when no localStorage item
// disqusjs.mode will be set in checkDisqus()
checkDisqus();
}
/*
<div id="dsqjs">
<section class="dsqjs-action"></section>
<header></header>
<section class="dsqjs-info">
<p id="dsqjs-load-disqus" class="dsqjs-message dsqjs-hide">评论完整模式加载中...如果长时间无法加载请针对 disq.us | disquscdn.com | disqus.com 启用代理或使用<a href="#" id="dsqjs-force-dsqjs">评论基础模式</a></p>
<p id="dsqjs-loading-dsqjs" class="dsqjs-message dsqjs-hide">你可能无法访问 Disqus已启用评论基础模式如需完整体验请针对 disq.us | disquscdn.com | disqus.com 启用代理并<a href="#" id="dsqjs-reload-disqus">尝试使用完整 Disqus 模式</a> | <a href="#" id="dsqjs-force-disqus"> Disqus </a></p>
<p id="dsqjs-load-error" class="dsqjs-message dsqjs-hide">评论基础模式出现错误是否<a href="#" id="dsqjs-reload">重载</a></p>
<p id="dsqjs-no-comment" class="dsqjs-no-comment dsqjs-hide">这里冷冷清清的一条评论都没有</p>
</section>
<section class="dsqjs-container" id="dsqjs-container"><ul id="dsqjs-list" class="dsqjs-list"></ul></section>
</div>
*/
var disqusjsBaseTpl = `<div id="dsqjs"><section class="dsqjs-action"></section><header></header><section class="dsqjs-info"><p id="dsqjs-load-disqus" class="dsqjs-message dsqjs-hide">评论完整模式加载中...如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理,或使用<a href="#" id="dsqjs-force-dsqjs">评论基础模式</a></p><p id="dsqjs-loading-dsqjs" class="dsqjs-message dsqjs-hide">你可能无法访问 Disqus已启用评论基础模式。如需完整体验请针对 disq.us | disquscdn.com | disqus.com 启用代理并<a href="#" id="dsqjs-reload-disqus">尝试使用完整 Disqus 模式</a> | <a href="#" id="dsqjs-force-disqus">强制完整 Disqus 模式</a>。</p><p id="dsqjs-load-error" class="dsqjs-message dsqjs-hide">评论基础模式出现错误,是否<a href="#" id="dsqjs-reload">重载</a></p><p id="dsqjs-no-comment" class="dsqjs-no-comment dsqjs-hide">这里冷冷清清的,一条评论都没有</p></section><section class="dsqjs-container" id="dsqjs-container"><ul id="dsqjs-list" class="dsqjs-list"></ul></section></div>`;
document.getElementById('disqus_thread').innerHTML = disqusjsBaseTpl;
disqusjs.mode = getLS('disqusjs_mode');
if (disqusjs.mode === 'disqus') {
loadDisqus();
} else if (disqusjs.mode === 'dsqjs') {
getThreadInfo();
} else {
// Run checkDisqus() when no localStorage item
// disqusjs.mode will be set in checkDisqus()
checkDisqus();
} }
} main();
main(); })();
Loading…
Cancel
Save