You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DisqusJS/dist/disqus.js

9 lines
10 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}
/*! baiduTemplate | Verison 1.0.6 | BSD License */!function(o){var e="undefined"==typeof module?o.baidu=o.baidu||{}:module.exports;e.template=function(t,e){var s=function(){if(!o.document)return a._compile(t);var e=document.getElementById(t);if(e){if(a.cache[t])return a.cache[t];var s=/^(textarea|input)$/i.test(e.nodeName)?e.value:e.innerHTML;return a._compile(s)}return a._compile(t)}(),n=a._isObject(e)?s(e):s;return s=null,n};var a=e.template;a.versions=a.versions||[],a.versions.push("1.0.6"),a.cache={},a.LEFT_DELIMITER=a.LEFT_DELIMITER||"<%",a.RIGHT_DELIMITER=a.RIGHT_DELIMITER||"%>",a.ESCAPE=!0,a._encodeHTML=function(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\\/g,"&#92;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")},a._encodeReg=function(e){return String(e).replace(/([.*+?^=!:${}()|[\]/\\])/g,"\\$1")},a._encodeEventHTML=function(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/\\\\/g,"\\").replace(/\\\//g,"/").replace(/\\n/g,"\n").replace(/\\r/g,"\r")},a._compile=function(e){var s="var _template_fun_array=[];\nvar fn=(function(__data__){\nvar _template_varName='';\nfor(name in __data__){\n_template_varName+=('var '+name+'=__data__[\"'+name+'\"];');\n};\neval(_template_varName);\n_template_fun_array.push('"+a._analysisStr(e)+"');\n_template_varName=null;\n})(_template_object);\nfn = null;\nreturn _template_fun_array.join('');\n";return new Function("_template_object",s)},a._isObject=function(e){return"function"==typeof e||!(!e||"object"!==_typeof(e))},a._analysisStr=function(e){var s=a.LEFT_DELIMITER,t=a.RIGHT_DELIMITER,n=a._encodeReg(s),o=a._encodeReg(t);return e=(e=String(e).replace(new RegExp("("+n+"[^"+o+"]*)//.*\n","g"),"$1").replace(new RegExp("\x3c!--.*?--\x3e","g"),"").replace(new RegExp(n+"\\*.*?\\*"+o,"g"),"").replace(new RegExp("[\\r\\t\\n]","g"),"").replace(new RegExp(n+"(?:(?!"+o+")[\\s\\S])*"+o+"|((?:(?!"+n+")[\\s\\S])+)","g"),function(e,s){var t="";if(s)for(t=s.replace(/\\/g,"&#92;").replace(/'/g,"&#39;");/<[^<]*?&#39;[^<]*?>/g.test(t);)t=t.replace(/(<[^<]*?)&#39;([^<]*?>)/g,"$1\r$2");else t=e;return t})).replace(new RegExp("("+n+"[\\s]*?var[\\s]*?.*?[\\s]*?[^;])[\\s]*?"+o,"g"),"$1;"+t).replace(new RegExp("("+n+":?[hvu]?[\\s]*?=[\\s]*?[^;|"+o+"]*?);[\\s]*?"+o,"g"),"$1"+t).split(s).join("\t"),e=(e=a.ESCAPE?e.replace(new RegExp("\\t=(.*?)"+o,"g"),"',typeof($1) === 'undefined'?'':baidu.template._encodeHTML($1),'"):e.replace(new RegExp("\\t=(.*?)"+o,"g"),"',typeof($1) === 'undefined'?'':$1,'")).replace(new RegExp("\\t:h=(.*?)"+o,"g"),"',typeof($1) === 'undefined'?'':baidu.template._encodeHTML($1),'").replace(new RegExp("\\t(?::=|-)(.*?)"+o,"g"),"',typeof($1)==='undefined'?'':$1,'").replace(new RegExp("\\t:u=(.*?)"+o,"g"),"',typeof($1)==='undefined'?'':encodeURIComponent($1),'").replace(new RegExp("\\t:v=(.*?)"+o,"g"),"',typeof($1)==='undefined'?'':baidu.template._encodeEventHTML($1),'").split("\t").join("');").split(t).join("_template_fun_array.push('").split("\r").join("\\'")}}(window),
/*!
* DisqusJS | v0.1.0
* Author: SukkaW
* Link: https://github.com/SukkaW/DisqusJS
* License: GPL-3.0
*/
disqusjs.page=[],window.disqus_config=function(){this.page.url=disqusjs.config.url,this.page.identifier=disqusjs.config.identifier};var xhr=new XMLHttpRequest;setLS=function(e,s){try{localStorage.setItem(e,s)}catch(e){console.log(e),console.log("Failed to set localStorage item")}},getLS=function(e){return localStorage.getItem(e)},Date.prototype.Format=function(e){var s={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),S:this.getMilliseconds()};for(var t in/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length))),s)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?s[t]:("00"+s[t]).substr((""+s[t]).length)));return e},loadDisqus=function(){var e=document;e.getElementById("dsqjs-load-disqus").classList.remove("dsqjs-hide"),e.getElementById("dsqjs-force-dsqjs").addEventListener("click",forceDsqjs);var s=e.createElement("script");s.src="https://"+disqusjs.config.shortname+".disqus.com/embed.js",s.setAttribute("data-timestamp",+new Date),(e.head||e.body).appendChild(s)},checkDisqus=function(){var s=new Image,t=setTimeout(function(){s.onerror=s.onload=null,setLS("disqusjs_mode","dsqjs")},2e3);s.onerror=function(){clearTimeout(t),setLS("disqusjs_mode","dsqjs"),main()},s.onload=function(){clearTimeout(t);var e=setTimeout(function(){s.onerror=s.onload=null,setLS("disqusjs_mode","dsqjs")},2e3);s.onerror=function(){clearTimeout(e),setLS("disqusjs_mode","dsqjs"),main()},s.onload=function(){clearTimeout(e),setLS("disqusjs_mode","disqus"),main()},s.src="https://"+disqusjs.config.shortname+".disqus.com/favicon.ico?"+ +new Date},s.src="https://disqus.com/favicon.ico?"+ +new Date},forceDsqjs=function(){setLS("disqusjs_mode","dsqjs"),main()},forceDisqus=function(){setLS("disqusjs_mode","disqus"),main()},loadError=function(){document.getElementById("dsqjs-load-error").classList.remove("dsqjs-hide"),document.getElementById("dsqjs-loading-dsqjs").classList.add("dsqjs-hide"),document.getElementById("dsqjs-reload").addEventListener("click",getThreadInfo)},getThreadInfo=function(){document.getElementById("dsqjs-loading-dsqjs").classList.remove("dsqjs-hide"),document.getElementById("dsqjs-force-disqus").addEventListener("click",forceDisqus),document.getElementById("dsqjs-reload-disqus").addEventListener("click",checkDisqus);var e=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",e,!0),xhr.timeout=4e3,xhr.send(),xhr.onload=function(){if(200==this.status||304==this.status){var e=JSON.parse(this.responseText).response[0];disqusjs.page={id:e.id,title:e.title,isClosed:e.isClosed,length:e.posts},getComment()}},xhr.ontimeout=function(e){loadError()},xhr.onerror=function(e){loadError()}},getComment=function(){var e=disqusjs.config.api+"3.0/posts/list.json?forum="+disqusjs.config.shortname+"&thread="+disqusjs.page.id+"&api_key="+disqusjs.config.apikey;xhr.open("GET",e,!0),xhr.timeout=4e3,xhr.send(),xhr.onload=function(){if(200==this.status||304==this.status){var e=JSON.parse(this.responseText);0===e.code&&0<e.response.length?getCommentList(e.response):0===e.code&&0===e.response.length&&document.getElementById("dsqjs-no-comment").classList.remove("dsqjs-hide")}},xhr.ontimeout=function(e){loadError()},xhr.onerror=function(e){loadError()}},getCommentList=function(e){var s=[],a=[];e.forEach(function(e){(e.parent?a:s).push(e)});var t=s.map(function(e){return{comment:e,author:e.author.name,isPrimary:e.author.username===disqusjs.config.admin,children:function e(s){if(0===a.length)return null;var t=[];for(var n=0;n<a.length;n++){var o=a[n];o.parent===s&&t.unshift({comment:o,author:o.author.name,isPrimary:o.author.username===disqusjs.config.admin,children:e(+o.id)})}return t.length?t:null}(+e.id)}});renderComment(t)},renderComment=function(e){var o='<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>';e.map(function(e){childrenComments=function(s){function e(e){return s.apply(this,arguments)}return e.toString=function(){return s.toString()},e}(function(e){var t=e.nesting,s=e.children||[];if("null"!=typeof s){if(t<4)var n='<ul class="dsqjs-list dsqjs-children">';else n='<ul class="dsqjs-list">';return s.map(function(e){var s=e.comment;s.author.profileUrl?(s.avatarEl='<a href="'.concat(s.author.profileUrl,'" target="_blank" rel="nofollow noopener noreferrer"><img src="').concat(s.author.avatar.cache,'"></a>'),s.authorEl='<a href="'.concat(s.author.profileUrl,'">').concat(s.author.name,"</a>")):(s.avatarEl='<img src="'.concat(s.author.avatar.cache,'">'),s.authorEl="".concat(s.author.name)),e.nesting=t+1,n+='<li class="dsqjs-item" id="comment-'.concat(s.id,'">'),n+=baidu.template(o,s),n+="".concat(childrenComments(e),"</li>")}),0!==(n+="</ul>").length?n:void 0}});var s=e.comment;s.author.profileUrl?(s.avatarEl='<a href="'.concat(s.author.profileUrl,'" target="_blank" rel="nofollow noopener noreferrer"><img src="').concat(s.author.avatar.cache,'"></a>'),s.authorEl='<a href="'.concat(s.author.profileUrl,'">').concat(s.author.name,"</a>")):(s.avatarEl='<img src="'.concat(s.author.avatar.cache,'">'),s.authorEl="".concat(s.author.name)),e.children&&(e.nesting=1);var t='<li class="dsqjs-item" id="comment-'.concat(s.id,'">');t+=baidu.template(o,s),t+="".concat(childrenComments(e),"</li>"),document.getElementById("dsqjs-list").insertAdjacentHTML("beforeend",t)})},main=function(){document.getElementById("disqus_thread").innerHTML='<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>',disqusjs.mode=getLS("disqusjs_mode"),"disqus"===disqusjs.mode?loadDisqus():"dsqjs"===disqusjs.mode?getThreadInfo():checkDisqus()},main();