cusdis
cusdis copied to clipboard
Seems not working with Pjax
Hi, I am using Hexo with NexT theme and trying to setup Cusdis. The core codes for injecting Cusdis is:
<script>
document.addEventListener('page:loaded', () => {
if (CONFIG.cusdis.comment_count) {
const loadCount = () => {
NexT.utils.getScript(`${CONFIG.cusdis.host}/js/cusdis-count.umd.js`, {});
};
// defer loading until the whole page loading is completed
window.addEventListener('load', loadCount, false);
}
if (CONFIG.page.comments) {
NexT.utils.loadComments('#cusdis_thread').then( () => {
var p = document.getElementById("cusdis_thread");
p.setAttribute("data-page-id", CONFIG.page.path);
p.setAttribute("data-page-url", CONFIG.page.permalink);
p.setAttribute("data-page-title", CONFIG.page.title);
NexT.utils.getScript(`${CONFIG.cusdis.host}/js/cusdis.es.js`, {
parentNode: document.querySelector('#cusdis_thread')
});
});
}
});
</script>
This works fine when I did not turn on Pjax.
After turning on Pjax, the script is reloaded and executed every time page switches, due to event listener on 'page:loaded'.
There's a mistake when page switches: Uncaught SyntaxError: Identifier 'e' has already been declared (at cusdis.es.js:1:1)
.
At the beginning of cusdis.es.js
, there comes let e;
. I guess the problem originates from the scope of var e
. I am not a front-end guy and am looking for help. Thanks!
I'm also getting this error when using Cusdis with Application Insights browser script. They both declare a variable "e".