hexo-theme-stellar/layout/_partial/comments/utterances/script.ejs

24 lines
702 B
Plaintext
Raw Normal View History

2024-05-31 20:32:04 +08:00
<script type="module">
const el = document.querySelector("#comments #utterances");
util.viewportLazyload(el, load_utterances, <%= theme.comments.lazyload ?? false %>);
function load_utterances() {
if (!el) return;
try {
el.innerHTML = '';
} catch (error) {
console.error(error);
}
const script = document.createElement('script');
script.src = 'https://utteranc.es/client.js';
script.async = true;
for (const key of Object.keys(el.attributes)) {
const attr = el.attributes[key];
if (['class', 'id'].includes(attr.name) === false) {
script.setAttribute(attr.name, attr.value);
2021-07-23 23:44:25 +08:00
}
2024-05-31 20:32:04 +08:00
}
el.appendChild(script);
2021-02-19 23:33:19 +08:00
}
</script>