hexo-theme-stellar/layout/_partial/scripts/services.ejs

29 lines
976 B
Plaintext
Raw Permalink Normal View History

2024-02-18 12:33:28 +08:00
<script defer>
2024-02-12 23:07:56 +08:00
window.addEventListener('DOMContentLoaded', (event) => {
2024-02-18 12:33:28 +08:00
ctx.services = Object.assign({}, JSON.parse(`<%- JSON.stringify(theme.data_services) %>`));
2024-02-12 23:07:56 +08:00
for (let id of Object.keys(ctx.services)) {
2024-02-18 12:33:28 +08:00
const js = ctx.services[id].js;
2024-02-12 23:07:56 +08:00
if (id == 'siteinfo') {
2024-02-12 23:45:08 +08:00
ctx.cardlinks = document.querySelectorAll('a.link-card[cardlink]');
if (ctx.cardlinks?.length > 0) {
2024-02-12 23:07:56 +08:00
utils.js(js, { defer: true }).then(function () {
2024-02-12 23:45:08 +08:00
setCardLink(ctx.cardlinks);
2024-02-12 23:07:56 +08:00
});
}
} else {
2024-02-18 12:33:28 +08:00
const els = document.getElementsByClassName(`ds-${id}`);
2024-02-12 23:07:56 +08:00
if (els?.length > 0) {
utils.jq(() => {
if (id == 'timeline' || 'memos' || 'marked') {
utils.js(deps.marked).then(function () {
utils.js(js, { defer: true });
});
} else {
utils.js(js, { defer: true });
}
});
}
}
}
});
</script>