fix: load script synchronously (#482)

* fix: constant path

* fix: load script synchronously
This commit is contained in:
山吹色御守 2024-06-16 22:30:38 +08:00 committed by GitHub
parent 6679dbd07b
commit 692f1fda5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 15 deletions

View File

@ -6,10 +6,7 @@
if (!el) return;
utils.css('<%- theme.comments.artalk.css %>');
utils.js('<%- theme.comments.artalk.js %>', {defer: true}).then(function () {
const path = el.getAttribute('comment_id');
if (!path) {
path = decodeURI(window.location.pathname);
}
const path = el.getAttribute('comment_id') ?? decodeURI(window.location.pathname);
const artalk = Artalk.init({
el: '#artalk_container',
pageKey: path,

View File

@ -1,14 +1,11 @@
<script type="module">
const el = document.getElementById('artalk_container');
const el = document.getElementById('twikoo_container');
util.viewportLazyload(el, load_twikoo, <%= theme.comments.lazyload ?? false %>);
function load_twikoo() {
if (!el) return;
utils.js('<%- theme.comments.twikoo.js %>', {defer: true}).then(function () {
const path = el.getAttribute('comment_id');
if (!path) {
path = decodeURI(window.location.pathname);
}
const path = el.getAttribute('comment_id') ?? decodeURI(window.location.pathname);
twikoo.init(Object.assign(<%- JSON.stringify(theme.comments.twikoo) %>, {
el: '#twikoo_container',
path: path,

View File

@ -10,11 +10,7 @@
utils.css('<%- theme.comments.waline.css %>');
utils.css('<%- theme.comments.waline.meta_css %>');
const path = el.getAttribute('comment_id');
if (!path) {
path = decodeURI(window.location.pathname);
}
const path = el.getAttribute('comment_id') ?? decodeURI(window.location.pathname);
const waline = init(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
el: '#waline_container',
path: path,

View File

@ -21,7 +21,7 @@ function custom_inject() {
<%- partial('scripts/tagtree') %>
<!-- required -->
<script src="<%- `${theme.stellar.main_js}?v=${stellar_info('version')}` %>" async></script>
<script src="<%- `${theme.stellar.main_js}?v=${stellar_info('version')}` %>" defer></script>
<%- partial('scripts/theme') %>