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

26 lines
832 B
Plaintext
Raw Normal View History

2021-02-19 23:33:19 +08:00
<script>
2021-02-21 18:48:38 +08:00
function utterances(){
2021-02-19 23:33:19 +08:00
if(!document.getElementById("utterances"))return;
setTimeout(function() {
var checkUtterances = setInterval(function () {
2021-02-21 23:20:13 +08:00
var el = document.getElementById("utterances");
if (!el) return
2021-02-19 23:33:19 +08:00
clearInterval(checkUtterances)
try {
2021-02-21 23:20:13 +08:00
el.innerHTML="";
2021-02-19 23:33:19 +08:00
} catch (error) {}
var script = document.createElement('script');
2021-02-21 18:48:38 +08:00
script.src = 'https://utteranc.es/client.js';
2021-02-22 22:03:02 +08:00
const keys = ['repo', 'issue-term', 'issue-number', 'theme', 'label', 'crossorigin'];
2021-02-21 23:20:13 +08:00
keys.forEach((key, i) => {
if (el.attributes[key] && el.attributes[key].value) {
script.setAttribute(key, el.attributes[key].value);
2021-02-21 18:48:38 +08:00
}
2021-02-21 23:20:13 +08:00
});
el.appendChild(script);
2021-02-19 23:33:19 +08:00
}, 200)
});
}
2021-02-21 18:48:38 +08:00
utterances();
2021-02-19 23:33:19 +08:00
</script>