diff --git a/README.md b/README.md index 43bac1d..582be0f 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ var dsqjs = new DisqusJS({ - DisqusJS 请求的 API Endpoint,通常情况下你应该配置一个 Disqus API 的反代并填入反代的地址。你也可以直接使用 DISQUS 官方 API 的 Endpoint `https://disqus.com/api/`,或是使用我搭建的 Disqus API 反代 Endpoint `https://disqus.skk.moe/disqus/`。如有必要可以阅读关于搭建反代的 [相关内容](https://github.com/SukkaW/DisqusJS#%E8%B0%83%E8%AF%95%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8--%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3) - **建议**,默认值为 `https://disqus.skk.moe/disqus/` -**apikey** `{string || {Array}}` +**apikey** `{string || Array}` - DisqusJS 向 API 发起请求时使用的 API Key,你应该在配置 Disqus Application 时获取了 API Key - DisqusJS 支持填入一个 包含多个 API Key 的 Array,在每次请求时会随机使用其中一个;如果你只需要填入一个 API Key,则可以填入 String 或 Array。 @@ -160,9 +160,9 @@ var dsqjs = new DisqusJS({ - nesting 最大评论嵌套数(超过嵌套层数的评论会显示在同一层级下,目前该值采用 Disqus 官方 4 级嵌套且不可改变) - nocomment 没有评论时的提示语(对应 Disqus Admin - Settings - Community - Comment Count Link - Zero comments) -~~- commentPolicyURL 站点评论政策 URL(对应 对应 Disqus Admin - Settings - General - Comment Policy URL)~~ -~~- commentPolicyText 站点评论政策简介(对应 对应 Disqus Admin - Settings - General - Comment Policy Summary)~~ -~~- newcomment 是否允许添加新评论(目前增加评论功能尚未实现)~~ +- ~~commentPolicyURL 站点评论政策 URL(对应 对应 Disqus Admin - Settings - General - Comment Policy URL)~~ +- ~~commentPolicyText 站点评论政策简介(对应 对应 Disqus Admin - Settings - General - Comment Policy Summary)~~ +- ~~newcomment 是否允许添加新评论(目前增加评论功能尚未实现)~~ ### PJAX 站点注意事项 @@ -177,7 +177,7 @@ DisqusJS v1.0.0 及之后的版本使用了新的方法加载 DisqusJS,并去 - Disqus API 不支持通过 AJAX 方式调用创建评论或者初始化页面,所以自动初始化页面和创建匿名评论在不搭配专门的后端程序的话不能实现。 - 所以如果 DisqusJS 检测到当前页面没有初始化、会提示是否切换到 Disqus 完整模式进行初始化。 - DisqusJS 仅在当前域名首次访问时检测 Disqus 可用性并选择模式,并把结果持久化在 localStorage 中,之后访问都会沿用之前的模式。 -- 一个 Disqus Application 的 Rate Limit 是每小时 1000 次;DisqusJS 一次正常加载会产生 2 次请求。~~未来可能会开放填入多个 API Key,支持调用多个 Application,绕过 Rate Limit。~~DisqusJS 已经支持填入多个 API Key,你可以创建多个 Disqus API Application 并分别获取 API Key。 +- 一个 Disqus Application 的 Rate Limit 是每小时 1000 次;DisqusJS 一次正常加载会产生 2 次请求。DisqusJS 支持填入多个 API Key,你可以创建多个 Disqus API Application 并分别获取 API Key。 - 我搭建了一个 Disqus API 反代的服务 `https://disqus.skk.moe/disqus/` 供没有能力搭建反代的用户使用,不保证 SLA、缓存 TTL 1 小时。 ## 谁在使用 DisqusJS? @@ -197,7 +197,7 @@ DisqusJS v1.0.0 及之后的版本使用了新的方法加载 DisqusJS,并去 - DisqusJS 在 localStorage 中持久化了 Disqus 连通性检查结果,key 为 `dsqjs_mode`,value 为 `disqus` 或者 `dsqjs`。需要调整 DisqusJS 的模式时可以直接操作 localStorage。 - Disqus 自己的 config 保存在全局变量 `window.disqus_config` 中,你可能好奇为什么没有引入。实际上由于 `disqus_config` 和 DisqusJS 中有很多重复的配置,所以 DisqusJS 直接将相关配置项赋给了 `disqus_config`,所以用户只需要配置 Disqus 即可。 - DisqusJS 并没有使用 Webpack 将 `disqusjs.css` 和 `disqus.js` 打包在一起,大家可以开发自己的 DisqusJS 主题。所有 DisqusJS 创建的 HTML 元素都在 `
` 之中、几乎所有的元素都有自己的类名并都以 `dsqjs-` 为前缀,防止污染。 -- DisqusJS v1.2.0 版本实现了评论排序。Disqus 将评论排序方式持久化在 localStorage 中、key 为 `disqus.sort`,DisqusJS 沿用了这一位置。 +- DisqusJS 从 v1.2.0 版本开始实现了评论排序。Disqus 将评论排序方式持久化在 localStorage 中、key 为 `disqus.sort`,DisqusJS 沿用了这一位置。 ## Todo List diff --git a/dist/disqus.js b/dist/disqus.js index 21d187f..4b92a53 100644 --- a/dist/disqus.js +++ b/dist/disqus.js @@ -1,6 +1,6 @@ /*! - * DisqusJS | v1.2.0 + * DisqusJS | v1.2.2 * Author: SukkaW * Link: https://github.com/SukkaW/DisqusJS * License: MIT - */"use strict";function _typeof(s){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(s){return typeof s}:function(s){return s&&"function"==typeof Symbol&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s})(s)}!function(s,e){"function"==typeof define&&define.amd?define("DisqusJS",[],e):"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports?module.exports=e():s.DisqusJS=e()}("undefined"!=typeof self?self:void 0,function(){return function(s){var n=document,p=function(s){return n.getElementById(s)},o=function(s,e,t){var n=new XMLHttpRequest;n.open("GET",encodeURI(s),!0),n.onload=function(){if(200<=n.status&&n.status<300||304===n.status){var s=JSON.parse(n.responseText);e(s)}else a()},n.timeout=4500,n.ontimeout=function(s){t(s)},n.onerror=function(s){t(s)},n.send()},j=function(s,e){try{localStorage.setItem(s,e)}catch(s){}},d=function(s){var e=function(s){return s<10?"0".concat(s):s};s=Date.parse(new Date(s));var t=(s=new Date(s+288e5)).getFullYear(),n=e(s.getMonth()+1),o=e(s.getDate()),a=e(s.getHours()),r=e(s.getMinutes());return"".concat(t,"-").concat(n,"-").concat(o," ").concat(a,":").concat(r)};function e(){var s=n.createElement("script");p("disqus_thread").innerHTML='
评论完整模式加载中...如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理,或使用 评论基础模式
',p("dsqjs-force-dsqjs").addEventListener("click",r),s.src="https://".concat(v.config.shortname,".disqus.com/embed.js"),s.setAttribute("data-timestamp",+new Date),(n.head||n.body).appendChild(s)}function g(){p("disqus_thread").innerHTML='
正在检查 Disqus 能否访问...
';for(var s=["disqus.com","".concat(v.config.shortname,".disqus.com")],n=0,o=0,a=function(){s.length===n&&n===o?h():s.length===n&&r()},e=function(s){var e=new Image,t=setTimeout(function(){e.onerror=e.onload=null,n++,a()},3e3);e.onerror=function(){clearTimeout(t),n++,a()},e.onload=function(){clearTimeout(t),n++,o++,a()},e.src="https://".concat(s,"/favicon.ico?").concat(+new Date)},t=0;t切换到完整 Disqus 模式 进行初始化?',p("dsqjs-force-disqus").addEventListener("click",h)):a()},function(s){a()})}();var t=function d(s){var c=p("dsqjs-load-more"),l=n.getElementsByClassName("dsqjs-order-radio"),u=function s(){var e=!0,t=!1,n=void 0;try{for(var o,a=l[Symbol.iterator]();!(e=(o=a.next()).done);e=!0)i=o.value,i.removeEventListener("change",m)}catch(s){t=!0,n=s}finally{try{e||null==a.return||a.return()}finally{if(t)throw n}}c.removeEventListener("click",s),d(v.page.next)},r=function(){s?(c.classList.remove("dsqjs-disabled"),c.innerHTML="加载更多评论失败,点击重试",c.addEventListener("click",u)):a()},m=function s(e){v.sortType=e.target.getAttribute("value"),j("disqus.sort",v.sortType);var t=!0,n=!1,o=void 0;try{for(var a,r=l[Symbol.iterator]();!(t=(a=r.next()).done);t=!0)i=a.value,i.removeEventListener("change",s)}catch(s){n=!0,o=s}finally{try{t||null==r.return||r.return()}finally{if(n)throw o}}c.removeEventListener("click",u),v.page.comment=[],v.page.next="",p("dsqjs-post-container").innerHTML='

正在切换排序方式...

',c.classList.add("dsqjs-hide"),d()};s=s?"&cursor=".concat(s):"",c.classList.add("dsqjs-disabled");var q={parseDate:function(s){return Date.parse(new Date(s.createdAt))},parentAsc:function(s,e){return s.parent&&e.parent?q.parseDate(s)-q.parseDate(e):0}},e="".concat(v.config.api,"3.0/threads/listPostsThreaded?forum=").concat(v.config.shortname,"&thread=").concat(v.page.id).concat(s,"&api_key=").concat(y(),"&order=").concat(v.sortType);o(e,function(s){if(0===s.code&&0尝试完整 Disqus 模式 | 强制完整 Disqus 模式。',p("dsqjs-header").classList.remove("dsqjs-hide"),p("dsqjs-post-container").innerHTML='
这里冷冷清清的,一条评论都没有
',p("dsqjs-reload-disqus").addEventListener("click",g),p("dsqjs-force-disqus").addEventListener("click",h)):r()},function(s){r()})},f=function(s){var e,o,a,t,r=function(s){return s.comment.author.profileUrl?(s.comment.avatarEl=''),s.comment.authorEl='")):(s.comment.avatarEl=''),s.comment.authorEl='")),v.config.adminLabel&&s.isPrimary&&(s.comment.authorEl+=''.concat(v.config.adminLabel,"")),s},i=function(s){var t,e,n,o="",a="";return a=s.isDeleted?"此评论已被删除":(o="".concat(s.authorEl,''),s.message),'
'.concat(s.avatarEl,'
').concat(o,'
').concat((t=a,e=new RegExp(/(.+?)<\/a>/gi),n=new RegExp(/href=\"(.+?)\"/gi),(t.match(e)||[]).map(function(s){var e=s.match(n)[0].replace(/href=\"https:\/\/disq.us\/url\?url=/g,"").replace(/(.*)"/,"$1");e=(e=decodeURIComponent(e)).replace(/(.*):(.*)cuid=(.*)/,"$1"),t=t.replace(s,'').concat(e,""))}),t=t.replace(/href=/g,'target="_blank" href=')),"
")},n="";e=[],o=[],a=function(s){return{comment:s,author:s.author.name,isPrimary:!!v.config.admin&&s.author.username===v.config.admin,children:t(+s.id)}},t=function(s){if(0===o.length)return null;for(var e=[],t=0;t').concat(i(s.comment)).concat(function e(s){var t=s.nesting,n=s.children||[];if(n){var o=t<4?'
    ':'
      ';return n.map(function(s){(s=r(s)).nesting=t+1,o+='
    • ').concat(i(s.comment)).concat(e(s),"
    • ")}),0!==(o+="
    ").length?o:void 0}}(s),"")}),p("dsqjs-header").classList.remove("dsqjs-hide"),p("dsqjs-msg").innerHTML='你可能无法访问 Disqus,已启用评论基础模式。如需完整体验请针对 disq.us | disquscdn.com | disqus.com 启用代理并 尝试完整 Disqus 模式 | 强制完整 Disqus 模式。',p("dsqjs-post-container").innerHTML=n,p("dsqjs-reload-disqus").addEventListener("click",g),p("dsqjs-force-disqus").addEventListener("click",h)}}function a(){p("dsqjs-msg").innerHTML='评论基础模式加载失败,是否 重载尝试完整 Disqus 模式 ?',p("dsqjs-reload-dsqjs").addEventListener("click",t),p("dsqjs-reload-disqus").addEventListener("click",g)}function r(){j("dsqjs_mode","dsqjs"),t()}function h(){j("dsqjs_mode","disqus"),e()}Array.isArray||(Array.isArray=function(s){return"[object Array]"===Object.prototype.toString.call(s)});var v=[];v.config=s,v.config.api=v.config.api||"https://disqus.skk.moe/disqus/",v.config.identifier=v.config.identifier||n.location.origin+n.location.pathname+n.location.search,v.config.url=v.config.url||n.location.origin+n.location.pathname+n.location.search,v.page=[];var y=function(){return Array.isArray(v.config.apikey)?v.config.apikey[Math.floor(Math.random()*v.config.apikey.length)]:v.config.apikey};window.disqus_config=function(){this.page.url=v.config.url,this.page.identifier=v.config.identifier},v.mode=localStorage.getItem("dsqjs_mode"),v.sortType=localStorage.getItem("disqus.sort"),v.sortType||(j("disqus.sort","desc"),v.sortType="desc"),"disqus"===v.mode?e():"dsqjs"===v.mode?t():g()}}); \ No newline at end of file + */"use strict";function _typeof(s){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(s){return typeof s}:function(s){return s&&"function"==typeof Symbol&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s})(s)}!function(s,e){"function"==typeof define&&define.amd?define("DisqusJS",[],e):"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports?module.exports=e():s.DisqusJS=e()}("undefined"!=typeof self?self:void 0,function(){return function(s){var n=document,f=function(s){return n.getElementById(s)},o=function(s,e,t){var n=new XMLHttpRequest;n.open("GET",encodeURI(s),!0),n.onload=function(){if(200<=n.status&&n.status<300||304===n.status){var s=JSON.parse(n.responseText);e(s)}else a()},n.timeout=4500,n.ontimeout=function(s){t(s)},n.onerror=function(s){t(s)},n.send()},p=function(s,e){try{localStorage.setItem(s,e)}catch(s){}},d=function(s){var e=function(s){return s<10?"0".concat(s):s};s=Date.parse(new Date(s));var t=(s=new Date(s+288e5)).getFullYear(),n=e(s.getMonth()+1),o=e(s.getDate()),a=e(s.getHours()),r=e(s.getMinutes());return"".concat(t,"-").concat(n,"-").concat(o," ").concat(a,":").concat(r)};function e(){var s=n.createElement("script");f("disqus_thread").innerHTML='
    评论完整模式加载中...如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理,或使用 评论基础模式
    ',f("dsqjs-force-dsqjs").addEventListener("click",r),s.src="https://".concat(h.config.shortname,".disqus.com/embed.js"),s.setAttribute("data-timestamp",+new Date),(n.head||n.body).appendChild(s)}function j(){f("disqus_thread").innerHTML='
    正在检查 Disqus 能否访问...
    ';for(var s=["disqus.com","".concat(h.config.shortname,".disqus.com")],n=0,o=0,a=function(){s.length===n&&n===o?g():s.length===n&&r()},e=function(s){var e=new Image,t=setTimeout(function(){e.onerror=e.onload=null,n++,a()},3e3);e.onerror=function(){clearTimeout(t),n++,a()},e.onload=function(){clearTimeout(t),n++,o++,a()},e.src="https://".concat(s,"/favicon.ico?").concat(+new Date)},t=0;t切换到完整 Disqus 模式 进行初始化?',f("dsqjs-force-disqus").addEventListener("click",g)):a()},function(s){a()})}();var t=function i(s){var d=f("dsqjs-load-more"),c=n.getElementsByClassName("dsqjs-order-radio"),l=function s(){var e=!0,t=!1,n=void 0;try{for(var o,a=c[Symbol.iterator]();!(e=(o=a.next()).done);e=!0)o.value.removeEventListener("change",u)}catch(s){t=!0,n=s}finally{try{e||null==a.return||a.return()}finally{if(t)throw n}}d.removeEventListener("click",s),i(h.page.next)},r=function(){s?(d.classList.remove("dsqjs-disabled"),d.innerHTML="加载更多评论失败,点击重试",d.addEventListener("click",l)):a()},u=function s(e){h.sortType=e.target.getAttribute("value"),p("disqus.sort",h.sortType);var t=!0,n=!1,o=void 0;try{for(var a,r=c[Symbol.iterator]();!(t=(a=r.next()).done);t=!0)a.value.removeEventListener("change",s)}catch(s){n=!0,o=s}finally{try{t||null==r.return||r.return()}finally{if(n)throw o}}d.removeEventListener("click",l),h.page.comment=[],h.page.next="",f("dsqjs-post-container").innerHTML='

    正在切换排序方式...

    ',d.classList.add("dsqjs-hide"),i()};s=s?"&cursor=".concat(s):"",d.classList.add("dsqjs-disabled");var m={parseDate:function(s){return Date.parse(new Date(s.createdAt))},parentAsc:function(s,e){return s.parent&&e.parent?m.parseDate(s)-m.parseDate(e):0}},e="".concat(h.config.api,"3.0/threads/listPostsThreaded?forum=").concat(h.config.shortname,"&thread=").concat(h.page.id).concat(s,"&api_key=").concat(v(),"&order=").concat(h.sortType);o(e,function(s){if(0===s.code&&0尝试完整 Disqus 模式 | 强制完整 Disqus 模式。',f("dsqjs-header").classList.remove("dsqjs-hide"),f("dsqjs-post-container").innerHTML='
    这里冷冷清清的,一条评论都没有
    ',f("dsqjs-reload-disqus").addEventListener("click",j),f("dsqjs-force-disqus").addEventListener("click",g)):r()},function(s){r()})},q=function(s){var e,o,a,t,r=function(s){return s.comment.author.profileUrl?(s.comment.avatarEl=''),s.comment.authorEl='")):(s.comment.avatarEl=''),s.comment.authorEl='")),h.config.adminLabel&&s.isPrimary&&(s.comment.authorEl+=''.concat(h.config.adminLabel,"")),s},i=function(s){var t,e,n,o="",a="";return a=s.isDeleted?"此评论已被删除":(o="".concat(s.authorEl,''),s.message),'
    '.concat(s.avatarEl,'
    ').concat(o,'
    ').concat((t=a,e=new RegExp(/(.+?)<\/a>/gi),n=new RegExp(/href=\"(.+?)\"/gi),(t.match(e)||[]).map(function(s){var e=s.match(n)[0].replace(/href=\"https:\/\/disq.us\/url\?url=/g,"").replace(/(.*)"/,"$1");e=(e=decodeURIComponent(e)).replace(/(.*):(.*)cuid=(.*)/,"$1"),t=t.replace(s,'').concat(e,""))}),t=t.replace(/href=/g,'target="_blank" href=')),"
    ")},n="";e=[],o=[],a=function(s){return{comment:s,author:s.author.name,isPrimary:!!h.config.admin&&s.author.username===h.config.admin,children:t(+s.id)}},t=function(s){if(0===o.length)return null;for(var e=[],t=0;t').concat(i(s.comment)).concat(function e(s){var t=s.nesting,n=s.children||[];if(n){var o=t<4?'
      ':'
        ';return n.map(function(s){(s=r(s)).nesting=t+1,o+='
      • ').concat(i(s.comment)).concat(e(s),"
      • ")}),0!==(o+="
      ").length?o:void 0}}(s),"")}),f("dsqjs-header").classList.remove("dsqjs-hide"),f("dsqjs-msg").innerHTML='你可能无法访问 Disqus,已启用评论基础模式。如需完整体验请针对 disq.us | disquscdn.com | disqus.com 启用代理并 尝试完整 Disqus 模式 | 强制完整 Disqus 模式。',f("dsqjs-post-container").innerHTML=n,f("dsqjs-reload-disqus").addEventListener("click",j),f("dsqjs-force-disqus").addEventListener("click",g)}}function a(){f("dsqjs-msg").innerHTML='评论基础模式加载失败,是否 重载尝试完整 Disqus 模式 ?',f("dsqjs-reload-dsqjs").addEventListener("click",t),f("dsqjs-reload-disqus").addEventListener("click",j)}function r(){p("dsqjs_mode","dsqjs"),t()}function g(){p("dsqjs_mode","disqus"),e()}Array.isArray||(Array.isArray=function(s){return"[object Array]"===Object.prototype.toString.call(s)});var h=[];h.config=s,h.config.api=h.config.api||"https://disqus.skk.moe/disqus/",h.config.identifier=h.config.identifier||n.location.origin+n.location.pathname+n.location.search,h.config.url=h.config.url||n.location.origin+n.location.pathname+n.location.search,h.page=[];var v=function(){return Array.isArray(h.config.apikey)?h.config.apikey[Math.floor(Math.random()*h.config.apikey.length)]:h.config.apikey};window.disqus_config=function(){this.page.url=h.config.url,this.page.identifier=h.config.identifier},h.mode=localStorage.getItem("dsqjs_mode"),h.sortType=localStorage.getItem("disqus.sort"),h.sortType||(p("disqus.sort","desc"),h.sortType="desc"),"disqus"===h.mode?e():"dsqjs"===h.mode?t():j()}}); \ No newline at end of file diff --git a/dist/disqusjs.css b/dist/disqusjs.css index eb851c4..4bd5708 100644 --- a/dist/disqusjs.css +++ b/dist/disqusjs.css @@ -1,5 +1,5 @@ /*! - * DisqusJS - Default Theme | v1.2.0 + * DisqusJS - Default Theme | v1.2.2 * Author: SukkaW * Link: https://github.com/SukkaW/DisqusJS * License: MIT diff --git a/docs/index.html b/docs/index.html index 9bb228d..86ca9a6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -11,7 +11,7 @@ - +