From 3f4e02e8f9023a76c2396949e94766a7d8526f19 Mon Sep 17 00:00:00 2001 From: BigCoke233 Date: Sat, 31 Jan 2026 00:12:02 +0800 Subject: remove: like button --- assets/js/like.js | 150 --------------------- i18n/en.yml | 2 - i18n/zh.yml | 2 - layouts/_partials/posts/action-menu.html | 3 - .../_partials/posts/action-menu/like-button.html | 27 ---- layouts/_partials/scripts.html | 1 - 6 files changed, 185 deletions(-) delete mode 100644 assets/js/like.js delete mode 100644 layouts/_partials/posts/action-menu/like-button.html diff --git a/assets/js/like.js b/assets/js/like.js deleted file mode 100644 index 94e3ab30..00000000 --- a/assets/js/like.js +++ /dev/null @@ -1,150 +0,0 @@ -// implement features of like buttons in action menu -// 1. fetch likes -// 2. send like to server -// 3. visualize like data (orgam farm) -// 4. update like states - -const LIKE_SERVER_URL = "https://like.eltr.ac/" - -function initLikeButton() { - if (window.likeButtonInitialized) { - return; - } - - const likeBtn = document.getElementById("like-btn"); - if (!likeBtn) { - return; - } - - const pageId = likeBtn.dataset.pageid;; - - // get required elements - const elements = { - count: document.getElementById("like-count-" + pageId), - btn: document.getElementById("like-btn"), // Main button doesn't have page ID suffix - container: document.getElementById("like-container-" + pageId), - icon: document.getElementById("like-icon-" + pageId) - }; - // return if no page ID found or not in production or no elements - if ( - !pageId || !elements.count || !elements.btn || !elements.container - ) { - return; - } - - function setLikedState() { - // update classes - elements.icon?.classList.add('liked-heart'); - elements.icon?.classList.add('animate-heart-beat'); - elements.count?.classList.add('liked-count'); - elements.btn.disabled = true; - elements.container.classList.add('liked'); - // update tooltip - elements.btn.setAttribute('title', - elements.container.classList.contains('liked') - ? elements.btn.getAttribute('data-liked-title') - : '为这篇文章献上心脏' - ); - } - - async function fetchLikes() { - try { - const response = await fetch(LIKE_SERVER_URL + "like/" + pageId); - const data = await response.json(); - elements.count.innerText = data.likes ?? 0; - if (localStorage.getItem("liked_" + pageId)) { - setLikedState(); - updateOrganFarm(data.likes); - } - } catch(e) { - console.log(e); - elements.count.innerText = "❌"; - } - } - - async function sendLike(pageId) { - if (localStorage.getItem("liked_" + pageId)) return; - - try { - const response = await fetch(LIKE_SERVER_URL + "like/" + pageId, { method: "POST" }); - const data = await response.json(); - localStorage.setItem("liked_" + pageId, "1"); - elements.count.innerText = data.likes ?? 1; - updateOrganFarm(data.likes); - setLikedState(); - } catch(e) { - console.log(e); - alert("点赞失败,请稍后再试"); - } - }; - - function updateOrganFarm(count) { - const organFarm = document.getElementById("organ-farm"); - const organCount = count || parseInt(elements.count.innerText); - const organImages = [ - "https://r2.eltr.ac/picgo2025/oragn-3.png", - "https://r2.eltr.ac/picgo2025/organ-1.png", - "https://r2.eltr.ac/picgo2025/organ-2.png" - ]; - - if (!organFarm) return; - if (organFarm.classList.contains("hidden")) { - organFarm.classList.remove("hidden"); - organFarm.classList.add("animate-slide-in-down"); - } - - organFarm.innerHTML = ""; - for (let i = 0; i < organCount; i++) { - const img = document.createElement("img"); - img.className = "transition hover:scale-150 dark:invert"; - - const sizeRange = [6, 10]; - const size = Math.floor(Math.random() * (sizeRange[1] - sizeRange[0] + 1)) + sizeRange[0]; - img.classList.add(`w-${size}`, `h-${size}`); - - img.src = organImages[Math.floor(Math.random() * organImages.length)]; - // randomly offset and rotate - img.classList.add("rotate-" + Math.floor(Math.random() * 5)); - img.classList.add("translate-x-" + Math.floor(Math.random() * 5)); - img.classList.add("translate-y-" + Math.floor(Math.random() * 5)); - img.classList.add("opacity" + (100 - Math.floor(Math.random() * 3)*10)); - - organFarm.appendChild(img); - } - } - - // fetch likes when action menu is visible - const actionMenuEl = document.getElementById("action-menu"); - if (actionMenuEl) { - const observer = new IntersectionObserver((entries, obs) => { - if (entries[0].isIntersecting) { - fetchLikes(); - obs.disconnect(); - } - }); - observer.observe(actionMenuEl); - } else { - fetchLikes(); - } - - // add click event listener to like button - likeBtn.addEventListener("click", () => { - sendLike(pageId) - }) - - window.likeButtonInitialized = true; -} - -// Initialize when DOM is ready -if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', initLikeButton); -} else { - initLikeButton(); -} - -// Fallback initialization -window.addEventListener('load', () => { - if (!window.likeButtonInitialized) { - initLikeButton(); - } -}); diff --git a/i18n/en.yml b/i18n/en.yml index 8bb3bfc6..aa04e276 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -55,8 +55,6 @@ actionMenu: telegramChannel: Telegram Channel sponsor: Buy me a coffee comment: Comment - like: Offer up your heart - liked: You've already made your sacrifice webmention: Webmention rss_comment_link: "Come and leave a comment" webmention: diff --git a/i18n/zh.yml b/i18n/zh.yml index a4e45517..416f2fb1 100644 --- a/i18n/zh.yml +++ b/i18n/zh.yml @@ -54,8 +54,6 @@ actionMenu: telegramChannel: 'Telegram 频道' sponsor: 赞助作者 comment: 评论 - like: 为这篇文章献上心脏 - liked: 你已经献上心脏了 webmention: Webmention rss_comment_link: "读完啦?来坐坐吧" webmention: diff --git a/layouts/_partials/posts/action-menu.html b/layouts/_partials/posts/action-menu.html index 6b824409..ab4c87d5 100644 --- a/layouts/_partials/posts/action-menu.html +++ b/layouts/_partials/posts/action-menu.html @@ -4,7 +4,6 @@
{{ partial "posts/action-menu/comment-button" . }} {{ partial "posts/action-menu/webmention-button" . }} - {{ partial "posts/action-menu/like-button" . }}
{{ partial "posts/action-menu/info-links" . }} @@ -12,6 +11,4 @@ {{ partial "posts/action-menu/comment-section" . }} {{ partial "posts/action-menu/webmention-section" . }} - - diff --git a/layouts/_partials/posts/action-menu/like-button.html b/layouts/_partials/posts/action-menu/like-button.html deleted file mode 100644 index bd5e209e..00000000 --- a/layouts/_partials/posts/action-menu/like-button.html +++ /dev/null @@ -1,27 +0,0 @@ -{{ $pageID := .File.UniqueID | urlize }} - -
- -
- - diff --git a/layouts/_partials/scripts.html b/layouts/_partials/scripts.html index 17906c31..2875f27d 100644 --- a/layouts/_partials/scripts.html +++ b/layouts/_partials/scripts.html @@ -12,7 +12,6 @@ (resources.Get "js/toc.js") (resources.Get "js/inject-footnotes.js") (resources.Get "js/back2top.js") - (resources.Get "js/like.js") }} {{ $articleBundle := $articleJS | resources.Concat "js/article-bundle.js" | minify | fingerprint }} -- cgit v1.2.3