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.

1 line
11 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.

/*! DisqusJS v1.3.0 | Sukka (https://skk.moe) | https://disqusjs.skk.moe | MIT License */"use strict";function DisqusJS(C){!function(e,p,t,n,o){function r(){for(var s=arguments.length,e=new Array(s),t=0;t<s;t++)e[t]=arguments[t];return(r=Object.assign||function(s){for(var e=0,t=arguments.length;e<t;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r])}return s}).apply(this,e)}var q=function(s){return p.getElementById(s)},f=function(s){var e=q("dsqjs-msg");e&&(e.innerHTML=s)},h="click",d="disqus_thread",j="dsqjs_sort",c='target="_blank" rel="external nofollow noopener noreferrer"',l='<footer><p class="dsqjs-footer">Powered by <a class="dsqjs-disqus-logo" href="https://disqus.com" '+c+'></a>&nbsp;&amp;&nbsp;<a href="https://disqusjs.skk.moe" target="_blank">DisqusJS</a></p></footer>',u=function(s,e){return'<div class="dsqjs-header" id="dsqjs-header"><nav class="dsqjs-nav dsqjs-clearfix"><ul><li class="dsqjs-nav-tab dsqjs-tab-active"><span>'+s+' Comments</span></li><li class="dsqjs-nav-tab">'+e+'</li></ul><div class="dsqjs-order"><input class="dsqjs-order-radio" id="dsqjs-order-desc" type="radio" name="comment-order" value="desc" checked="true"><label class="dsqjs-order-label" for="dsqjs-order-desc" title=""></label><input class="dsqjs-order-radio" id="dsqjs-order-asc" type="radio" name="comment-order" value="asc"><label class="dsqjs-order-label" for="dsqjs-order-asc" title=""></label><input class="dsqjs-order-radio" id="dsqjs-order-popular" type="radio" name="comment-order" value="popular"><label class="dsqjs-order-label" for="dsqjs-order-popular" title=""></label></div></nav></div>'},v=function(s,e,t){var n=s.avatarEl,r=s.createdAt;return'<div class="dsqjs-post-item dsqjs-clearfix"><div class="dsqjs-post-avatar">'+n+'</div><div class="dsqjs-post-body"><div class="dsqjs-post-header">'+e+'<span class="dsqjs-meta"><time>'+a(r)+'</time></span></div><div class="dsqjs-post-content">'+t+"</div></div></div>"},g=' disq.us | disquscdn.com | disqus.com <a id="dsqjs-reload-disqus" class="dsqjs-msg-btn"> Disqus </a> | <a id="dsqjs-force-disqus" class="dsqjs-msg-btn"> Disqus </a>',b=function(s){return n(s,{method:"GET"}).then(function(s){return o.all([s.ok,s.status,s.json(),s.headers])}).then(function(s){var e=s[0],t=s[1],n=s[2],r=s[3];if(e)return{ok:e,status:t,data:n,headers:r};throw new Error}).catch(function(s){throw s})},y=function(s,e){try{t.setItem(s,e)}catch(s){}},a=function(s){function e(s){return s<10?"0"+s:s}return s=Date.parse(new Date(s)),(s=new Date(s+288e5)).getFullYear()+"-"+e(s.getMonth()+1)+"-"+e(s.getDate())+" "+e(s.getHours())+":"+e(s.getMinutes())};function s(){if(e.DISQUS)e.DISQUS.reset({reload:!0,config:function(){this.page.identifier=M.config.identifier,this.page.url=M.config.url,this.page.title=M.config.title}});else{var s=p.createElement("script");q(d).innerHTML='<div id="dsqjs"><section><div id="dsqjs-msg">... disq.us | disquscdn.com | disqus.com <a id="dsqjs-force-dsqjs" class="dsqjs-msg-btn"></a></div></section>'+l+"</div>",q("dsqjs-force-dsqjs").addEventListener(h,D),s.src="https://"+M.config.shortname+".disqus.com/embed.js",s.setAttribute("data-timestamp",+new Date),(p.head||p.body).appendChild(s)}}function E(){q(d).innerHTML='<div id="dsqjs"><section><div id="dsqjs-msg"> Disqus 访...</div></section>'+l+"</div>";function s(r){return new o(function(s,e){var t=new Image,n=setTimeout(function(){t.onerror=t.onload=null,e()},3e3);t.onerror=function(){clearTimeout(n),e()},t.onload=function(){clearTimeout(n),s()},t.src="https://"+r+"/favicon.ico?"+ +new Date+"="+ +new Date})}return o.all([s("disqus.com"),s(M.config.shortname+".disqus.com")]).then(w,D)}function L(){q("dsqjs-reload-disqus").addEventListener(h,E),q("dsqjs-force-disqus").addEventListener(h,w)}function i(){f("... "+g),L();var s=M.config.api+"3.0/threads/list.json?forum="+encodeURIComponent(M.config.shortname)+"&thread="+encodeURIComponent("ident:"+M.config.identifier)+"&api_key="+encodeURIComponent(k());b(s).then(function(s){var e=s.data;if(0===e.code&&1===e.response.length){var t=e.response[0],n=t.id,r=t.title,o=t.isClosed,a=t.posts;M.page={id:n,title:r,isClosed:o,length:a,comment:[]},q(d).innerHTML='<div id="dsqjs"><div id="dsqjs-msg">... '+g+"</div>"+u(a,M.config.siteName)+'<section class="dsqjs-post-container"><ul class="dsqjs-post-list" id="dsqjs-post-container"><p class="dsqjs-no-comment">...</p></ul><a id="dsqjs-load-more" class="dsqjs-load-more dsqjs-hide"></a></section>'+l+"</div>",L(),q("dsqjs-order-"+M.sortType).setAttribute("checked","true"),i()}else{if(0!==e.code||1===e.response.length)throw new Error;f(' Thread <a id="dsqjs-force-disqus" class="dsqjs-msg-btn"> Disqus </a>'),q("dsqjs-force-disqus").addEventListener(h,w)}}).catch(T);function e(s){function n(s){return{comment:s,author:s.author.name,isPrimary:!!M.config.admin&&s.author.username===M.config.admin,children:t(+s.id),hasMore:s.hasMore}}var e=[],r=[],t=function(e){if(0===r.length)return null;var t=[];return r.forEach(function(s){s.parent===e&&t.unshift(n(s))}),t.length?t:null};return s.forEach(function(s){(s.parent?r:e).push(s)}),e.map(n)}var i=function t(s){void 0===s&&(s="");function n(){Array.prototype.slice.call(o).forEach(function(s){return s.removeEventListener("change",d)}),r.removeEventListener(h,i),Array.prototype.slice.call(a).forEach(function(s){return s.removeEventListener(h,E)})}var r=q("dsqjs-load-more"),o=p.getElementsByClassName("dsqjs-order-radio"),a=p.getElementsByClassName("dsqjs-has-more-btn"),i=function(){n(),t(M.page.next)},d=function(s){var e=s.target;M.sortType=e.getAttribute("value"),y(j,M.sortType),n(),M.page.comment=[],M.page.next="",q("dsqjs-post-container").innerHTML='<p class="dsqjs-no-comment">...</p>',r.classList.add("dsqjs-hide"),t()},e=""===s?"":"&cursor="+s;r.classList.add("dsqjs-disabled");function c(s){var e=s.createdAt;return Date.parse(new Date(e))}function l(s,e){return s.parent&&e.parent?c(s)-c(e):0}var u=M.config.api+"3.0/threads/listPostsThreaded?forum="+encodeURIComponent(M.config.shortname)+"&thread="+encodeURIComponent(M.page.id)+encodeURIComponent(e)+"&api_key="+encodeURIComponent(k())+"&order="+encodeURIComponent(M.sortType);b(u).then(function(s){var e=s.data;if(0===e.code&&0<e.response.length){var t;r.classList.remove("dsqjs-disabled"),(t=M.page.comment).push.apply(t,e.response),M.page.comment.sort(l),m(M.page.comment),Array.prototype.slice.call(o).forEach(function(s){return s.addEventListener("change",d)}),Array.prototype.slice.call(a).forEach(function(s){return s.addEventListener(h,E)}),e.cursor.hasNext?(M.page.next=e.cursor.next,r.innerHTML="",r.classList.remove("dsqjs-hide"),r.addEventListener(h,i)):r.classList.add("dsqjs-hide")}else{if(0!==e.code||0!==e.response.length)throw new Error;f("访 Disqus"+g),q("dsqjs-post-container").innerHTML='<p class="dsqjs-no-comment" >'+M.config.nocomment+"</p>",L(),q("dsqjs-force-disqus").addEventListener(h,D)}}).catch(function(){""===s?T():(r.classList.remove("dsqjs-disabled"),r.innerHTML="",r.addEventListener(h,i))})},m=function(s){function o(s){return s.comment.author.profileUrl?(s.comment.avatarEl='<a href="'+s.comment.author.profileUrl+'" '+c+'><img src="'+n(s.comment.author.avatar.cache)+'"></a>',s.comment.authorEl='<span class="dsqjs-post-author"><a href="'+s.comment.author.profileUrl+'" '+c+">"+s.comment.author.name+"</a></span>"):(s.comment.avatarEl='<img src="'+n(s.comment.author.avatar.cache)+'">',s.comment.authorEl='<span class="dsqjs-post-author">'+s.comment.author.name+"</span>"),M.config.adminLabel&&s.isPrimary&&(s.comment.authorEl+='<span class="dsqjs-admin-badge">'+M.config.adminLabel+"</span>"),s}function a(s){var e="",t="";return t=s.isDeleted?"<small></small>":(e=s.authorEl+'<span class="dsqjs-bullet"></span>',function(s){var e=p.createElement("div");e.innerHTML=s;var t=e.getElementsByTagName("a");return Array.prototype.slice.call(t).forEach(function(s){var e=decodeURIComponent(s.href.replace(/https:\/\/disq\.us\/url\?url=/g,"")).replace(/(.*):.+cuid=.*/,"$1");s.href=e,s.innerHTML=e,s.rel="external noopener nofollow noreferrer",s.target="_blank"}),e.innerHTML}(n(s.message))),v(s,e,t)}var n=function(s){return s.replace(/a\.disquscdn\.com/g,"c.disquscdn.com")},t="";e(s).map(function(s){s.children&&(s.nesting=1);var e="";(s=o(s)).hasMore&&(e='<p class="dsqjs-has-more"> <a id="load-more-'+s.comment.id+'"> Disqus </a> </p>'),t+='<li data-id="comment-'+s.comment.id+'" id="comment-'+s.comment.id+'">'+a(s.comment)+function t(s){var n=s.nesting,e=s.children||[];if(e){var r="";return r=n<M.config.nesting?'<ul class="dsqjs-post-list dsqjs-children">':'<ul class="dsqjs-post-list">',e.map(function(s){(s=o(s)).nesting=n+1;var e=s.hasMore?'<p class="dsqjs-has-more"> <a class="dsqjs-has-more-btn" id="load-more-'+s.comment.id+'" data-more-id="comment-'+s.comment.id+'"> Disqus </a> </p>':"";r+='<li data-id="comment-'+s.comment.id+'" id="comment-'+s.comment.id+'">'+a(s.comment)+t(s)+e+"</li>"}),0!==(r+="</ul>").length?r:void 0}}(s)+e+"</li>"}),f("访 Disqus"+g),q("dsqjs-post-container").innerHTML=t,L()}}function T(s){console.log(s),f(' <a id="dsqjs-reload-dsqjs" class="dsqjs-msg-btn"></a> <a id="dsqjs-reload-disqus" class="dsqjs-msg-btn"> Disqus </a> '),q("dsqjs-reload-dsqjs").addEventListener(h,i),q("dsqjs-reload-disqus").addEventListener(h,E)}function D(){y("dsqjs_mode","dsqjs"),i()}function w(){y("dsqjs_mode","disqus"),s()}var M={},m=p.location.origin+p.location.pathname+p.location.search;M.config=r({api:"https://disqus.skk.moe/disqus/",identifier:m,url:m,title:p.title,siteName:"",nesting:parseInt(C.nesting)||4,nocomment:""},C),M.page={};var I=M.config.apikey,k=function(){return Array.isArray(I)?I[Math.floor(Math.random()*I.length)]:I};e.disqus_config=function(){this.page.url=M.config.url,this.page.identifier=M.config.identifier,this.page.title=M.config.title},q(d).innerHTML='<div id="dsqjs"><div id="dsqjs-msg"></div>'+l+"</div>",n&&t&&o?(M.mode=t.getItem("dsqjs_mode"),M.sortType=t.getItem(j)||t.getItem("disqus.sort"),M.sortType||(y(j,"desc"),M.sortType="desc"),"disqus"===M.mode?s():"dsqjs"===M.mode?i():E()):(f(""+g),L())}(window,document,localStorage,fetch,Promise)}try{module.exports=DisqusJS}catch(s){}