2021-02-19 23:33:19 +08:00
|
|
|
<script>
|
2021-07-23 23:44:25 +08:00
|
|
|
function loadUtterances() {
|
|
|
|
const els = document.querySelectorAll("#comments #utterances");
|
|
|
|
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);
|
2021-07-23 23:44:25 +08:00
|
|
|
}
|
|
|
|
var script = document.createElement('script');
|
|
|
|
script.src = 'https://utteranc.es/client.js';
|
|
|
|
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);
|
2021-02-19 23:33:19 +08:00
|
|
|
});
|
|
|
|
}
|
2021-07-23 23:44:25 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', (event) => {
|
|
|
|
loadUtterances();
|
|
|
|
});
|
2021-02-19 23:33:19 +08:00
|
|
|
</script>
|