summaryrefslogtreecommitdiff
path: root/layouts/_partials/scripts/action-menu-js.html
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-08-29 15:02:13 +0800
committerEltrac <hi@guhub.cn>2025-08-29 15:02:13 +0800
commit96153c88d957102234c0ef4ad794dbe62d7ca4ef (patch)
tree7636f2a56e1e8079ba8c8cb2b4ed2076c4e0e6df /layouts/_partials/scripts/action-menu-js.html
parentf839c9ce6277a5f0bc19e2a1e23a2c225715b1a6 (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/action-menu-js.html')
-rw-r--r--layouts/_partials/scripts/action-menu-js.html11
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 加载完成后初始化所有功能