diff options
| author | Eltrac <hi@guhub.cn> | 2025-08-29 15:02:13 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-08-29 15:02:13 +0800 |
| commit | 96153c88d957102234c0ef4ad794dbe62d7ca4ef (patch) | |
| tree | 7636f2a56e1e8079ba8c8cb2b4ed2076c4e0e6df /layouts/_partials/scripts | |
| parent | f839c9ce6277a5f0bc19e2a1e23a2c225715b1a6 (diff) | |
perf: load like function lazily
also disable 'like' when host is not 'www.geedea.pro' (the server rejects such requests anyway)
Diffstat (limited to 'layouts/_partials/scripts')
| -rw-r--r-- | layouts/_partials/scripts/action-menu-js.html | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/layouts/_partials/scripts/action-menu-js.html b/layouts/_partials/scripts/action-menu-js.html index 69f5189c..309043c8 100644 --- a/layouts/_partials/scripts/action-menu-js.html +++ b/layouts/_partials/scripts/action-menu-js.html @@ -58,6 +58,8 @@ document.addEventListener('DOMContentLoaded', initializeCommentCount); // 点赞功能初始化 function initializeLikes(pageId) { + if (window.location.host !== 'www.geedea.pro') return; + const elements = { count: document.getElementById("like-count-" + pageId), btn: document.getElementById("like-btn-" + pageId), @@ -117,7 +119,14 @@ function initializeLikes(pageId) { } }; - fetchLikes(); + // fetch likes when action menu is visible + const observer = new IntersectionObserver((entries, obs) => { + if (entries[0].isIntersecting) { + fetchLikes(); + obs.disconnect(); + } + }); + observer.observe(document.getElementById("action-menu")); } // 在 DOM 加载完成后初始化所有功能 |
