hexo-theme-stellar/layout/_partial/plugins/comments/giscus/script.ejs

26 lines
694 B
Plaintext
Raw Normal View History

2022-08-28 19:54:34 +08:00
<script>
function loadJS() {
const els = document.querySelectorAll("#comments #giscus");
if (els.length === 0) return;
els.forEach((el, i) => {
try {
el.innerHTML = '';
} catch (error) {
2023-12-06 13:22:07 +08:00
console.error(error);
2022-08-28 19:54:34 +08:00
}
var script = document.createElement('script');
script.async = true;
for (let key of Object.keys(el.attributes)) {
let attr = el.attributes[key];
if (['class', 'id'].includes(attr.name) === false) {
script.setAttribute(attr.name, attr.value);
}
}
el.appendChild(script);
});
}
window.addEventListener('DOMContentLoaded', (event) => {
loadJS();
});
</script>