@xiee/utils
Version:
Miscellaneous tools and utilities to manipulate HTML pages
2 lines • 2.77 kB
JavaScript
!function(e){if(!function(){var e=!0;try{e=window.self!==window.top}catch(e){}return e}()){var t=e.getElementById("disqus_thread"),n=t.nextElementSibling,r=e.querySelector("section.comments"),o=r.querySelectorAll('input[type="radio"]');n.setAttribute("data-timestamp",+new Date);var i,c=function(){return r.querySelector("#tab-2").checked=!0,"add"},s=function(e){"layout"===e.name&&r.classList["layout-2"===e.id?c():"remove"]("comment-full")},a=function(){s(this),l();var e=JSON.stringify(function(){var e={};return o.forEach((function(t){e[t.id]=t.checked})),e}());try{localStorage.setItem("comment-prefs",e)}catch(e){}},l=function(){var e=r.classList.contains("comment-full");r.querySelectorAll('input[name="tabs"]').forEach((function(t,n){if(e||t.checked){var o=r.querySelector(".panel:nth-of-type("+(n+1)+") > script[data-src]");o&&o.dataset.src&&(o.src=o.dataset.src,o.removeAttribute("data-src"))}}))};(i=localStorage.getItem("comment-prefs"))&&(i=JSON.parse(i),o.forEach((function(e){i[e.id]&&(e.checked=!0,s(e))}))),o.forEach((function(e){e.addEventListener("change",a)}));var d=!1,u=function(e){d||(r.querySelector(".tabs").style.display="",l(),d=!0,e&&t.scrollIntoView())};if(n.onerror=function(n){var r=e.createElement("script");r.src="//cdn.jsdelivr.net/gh/yihui/DisqusJS@1.3.3/src/disqus.min.js",t.appendChild(r);try{localStorage.setItem("dsqjs_mode","dsqjs")}catch(n){}r.onload=function(t){var n=e.createElement("link");n.rel="stylesheet",n.href="//cdn.jsdelivr.net/gh/yihui/DisqusJS@1.3.3/src/disqusjs.min.css",e.head.appendChild(n),disqus_config.DisqusJSInit()},r.onerror=function(e){t.innerText="Sorry, but you cannot make comments because Disqus failed to load for some reason. It is known to be blocked in certain regions. If you are sure it is not blocked in your region, please refresh the page. Alternatively, you can comment with Utterances. 您可能需要翻墙发表 Disqus 评论;若没有梯子,不妨尝试使用 Github 登录 Utterances 评论。",t.style.border="1px dashed",t.style.padding=".5em",t.style.background="lightyellow",c()}},n.onload=function(n){var o=e.getElementById("disqus_count");if(o){var i=e.createElement("script");i.src="//yihui.disqus.com/count.js",i.id="dsq-count-scr",t.appendChild(i),new MutationObserver((()=>{""==o.innerText||o.innerText>0||(c(),l(),r.append(r.querySelector("#tab-2 ~ .panel")),r.querySelector(".tabs").remove(),r.querySelector(".panel").style.display="block")})).observe(o,{characterData:!0,childList:!0})}},location.hash.match(/^#comment-[0-9]+$/))return u(!0);var m=function(){if(!d){var e=r.getBoundingClientRect();e.top<window.innerHeight&&e.bottom>=0&&u()}};window.addEventListener("load",m),e.addEventListener("scroll",m)}}(document);
//# sourceMappingURL=custom-disqus.min.js.map