From ff8d2377e3cc742dc16c271e56879e63e73b7164 Mon Sep 17 00:00:00 2001 From: Erzbir Date: Thu, 13 Aug 2026 17:49:01 +0800 Subject: [PATCH] feat: add link application support --- i18n/default.properties | 16 +++++ i18n/en.properties | 16 +++++ i18n/es.properties | 16 +++++ i18n/zh_CN.properties | 16 +++++ i18n/zh_TW.properties | 16 +++++ src/main.js | 1 + src/module/links.js | 153 ++++++++++++++++++++++++++++++++++++++++ src/styles/links.scss | 120 ++++++++++++++++++++++++++++++- templates/links.html | 97 ++++++++++++++++++++++++- 9 files changed, 447 insertions(+), 4 deletions(-) create mode 100644 src/module/links.js diff --git a/i18n/default.properties b/i18n/default.properties index 120bf60..13d860b 100644 --- a/i18n/default.properties +++ b/i18n/default.properties @@ -38,3 +38,19 @@ moment.comments=Toggle comments moment.network_error=Network error. Please try again. media.photo=Photo page.error.title=Error +page.links.apply.title=Blogroll Application +page.links.apply.success=Your blogroll application has been submitted, please wait for review. +page.links.apply.error=Submission failed, please try again later. +page.links.apply.submit=Submit +page.links.apply.field.url=Website URL +page.links.apply.field.displayName=Website Name +page.links.apply.field.logo=Logo URL +page.links.apply.field.description=Website Description +page.links.apply.field.email=Contact Email +page.links.apply.field.backlink=Backlink URL +page.links.apply.field.feedUrls=Feed URLs +page.links.apply.field.feedUrls.placeholder=One URL per line +page.links.apply.field.captcha=CAPTCHA +page.links.apply.field.captcha.alt=CAPTCHA +page.links.apply.field.captcha.title=Click to refresh CAPTCHA +page.links.apply.field.captcha.expired=CAPTCHA expired \ No newline at end of file diff --git a/i18n/en.properties b/i18n/en.properties index 120bf60..13d860b 100644 --- a/i18n/en.properties +++ b/i18n/en.properties @@ -38,3 +38,19 @@ moment.comments=Toggle comments moment.network_error=Network error. Please try again. media.photo=Photo page.error.title=Error +page.links.apply.title=Blogroll Application +page.links.apply.success=Your blogroll application has been submitted, please wait for review. +page.links.apply.error=Submission failed, please try again later. +page.links.apply.submit=Submit +page.links.apply.field.url=Website URL +page.links.apply.field.displayName=Website Name +page.links.apply.field.logo=Logo URL +page.links.apply.field.description=Website Description +page.links.apply.field.email=Contact Email +page.links.apply.field.backlink=Backlink URL +page.links.apply.field.feedUrls=Feed URLs +page.links.apply.field.feedUrls.placeholder=One URL per line +page.links.apply.field.captcha=CAPTCHA +page.links.apply.field.captcha.alt=CAPTCHA +page.links.apply.field.captcha.title=Click to refresh CAPTCHA +page.links.apply.field.captcha.expired=CAPTCHA expired \ No newline at end of file diff --git a/i18n/es.properties b/i18n/es.properties index 03024d6..193d303 100644 --- a/i18n/es.properties +++ b/i18n/es.properties @@ -38,3 +38,19 @@ moment.comments=Mostrar u ocultar comentarios moment.network_error=Error de red. Inténtalo de nuevo. media.photo=Foto page.error.title=Error +page.links.apply.title=Solicitud de inclusión en el blogroll +page.links.apply.success=Tu solicitud para el blogroll ha sido enviada, espera a que sea revisada. +page.links.apply.error=No se pudo enviar, inténtalo de nuevo más tarde. +page.links.apply.submit=Enviar +page.links.apply.field.url=URL del sitio web +page.links.apply.field.displayName=Nombre del sitio web +page.links.apply.field.logo=URL del logo +page.links.apply.field.description=Descripción del sitio web +page.links.apply.field.email=Correo de contacto +page.links.apply.field.backlink=URL del enlace de retorno +page.links.apply.field.feedUrls=URLs de suscripción +page.links.apply.field.feedUrls.placeholder=Una URL por línea +page.links.apply.field.captcha=CAPTCHA +page.links.apply.field.captcha.alt=CAPTCHA +page.links.apply.field.captcha.title=Haz clic para actualizar el CAPTCHA +page.links.apply.field.captcha.expired=El CAPTCHA ha caducado \ No newline at end of file diff --git a/i18n/zh_CN.properties b/i18n/zh_CN.properties index 7a53dfd..db225d8 100644 --- a/i18n/zh_CN.properties +++ b/i18n/zh_CN.properties @@ -38,3 +38,19 @@ moment.comments=展开或收起评论 moment.network_error=网络错误,请稍后重试 media.photo=图片 page.error.title=错误 +page.links.apply.title=申请友链 +page.links.apply.success=友链申请已提交, 请等待审核. +page.links.apply.error=提交失败, 请稍后再试 +page.links.apply.submit=提交 +page.links.apply.field.url=网站地址 +page.links.apply.field.displayName=网站名称 +page.links.apply.field.logo=Logo 地址 +page.links.apply.field.description=网站描述 +page.links.apply.field.email=联系邮箱 +page.links.apply.field.backlink=反向链接地址 +page.links.apply.field.feedUrls=订阅地址 +page.links.apply.field.feedUrls.placeholder=每行填写一个地址 +page.links.apply.field.captcha=验证码 +page.links.apply.field.captcha.alt=验证码 +page.links.apply.field.captcha.title=点击刷新验证码 +page.links.apply.field.captcha.expired=验证码已过期 \ No newline at end of file diff --git a/i18n/zh_TW.properties b/i18n/zh_TW.properties index 5dc4aed..0c7ae11 100644 --- a/i18n/zh_TW.properties +++ b/i18n/zh_TW.properties @@ -38,3 +38,19 @@ moment.comments=展開或收合評論 moment.network_error=網路錯誤,請稍後再試 media.photo=圖片 page.error.title=錯誤 +page.links.apply.title=申請友鏈 +page.links.apply.success=友鏈申請已提交, 請等待審核. +page.links.apply.error=提交失敗, 請稍後再試 +page.links.apply.submit=提交 +page.links.apply.field.url=網站地址 +page.links.apply.field.displayName=網站名稱 +page.links.apply.field.logo=Logo 地址 +page.links.apply.field.description=網站描述 +page.links.apply.field.email=聯絡信箱 +page.links.apply.field.backlink=反向連結地址 +page.links.apply.field.feedUrls=訂閱地址 +page.links.apply.field.feedUrls.placeholder=每行填寫一個地址 +page.links.apply.field.captcha=驗證碼 +page.links.apply.field.captcha.alt=驗證碼 +page.links.apply.field.captcha.title=點擊重新整理驗證碼 +page.links.apply.field.captcha.expired=驗證碼已過期 \ No newline at end of file diff --git a/src/main.js b/src/main.js index 1cc03f6..b67448a 100644 --- a/src/main.js +++ b/src/main.js @@ -4,6 +4,7 @@ import './module/post.js' import './module/header.js' import './module/effect.js' import './module/moments.js' +import './module/links.js' terminal.refresh(); diff --git a/src/module/links.js b/src/module/links.js new file mode 100644 index 0000000..3d8b67b --- /dev/null +++ b/src/module/links.js @@ -0,0 +1,153 @@ +import {terminal} from "../terminal.js"; + +const SECTION_ID = "plugin-links-apply-section"; +const FORM_ID = "link-application-form"; +const CAPTCHA_URL = "/links/apply/captcha"; +const CAPTCHA_EXPIRE_TIME = 5 * 60 * 1000; + +let captchaTimer = null; +let listenersRegistered = false; + +function clearCaptchaTimer() { + if (!captchaTimer) return; + + clearTimeout(captchaTimer); + captchaTimer = null; +} + +function refreshCaptcha() { + const section = document.getElementById(SECTION_ID); + if (!section) { + clearCaptchaTimer(); + return; + } + + const captcha = section.querySelector("#link-application-captcha"); + const overlay = section.querySelector("#captcha-expired-overlay"); + + if (!captcha || !overlay) return; + + captcha.src = `${CAPTCHA_URL}?t=${Date.now()}`; + overlay.style.display = "none"; + + clearCaptchaTimer(); + + captchaTimer = setTimeout(() => { + overlay.style.display = "flex"; + captchaTimer = null; + }, CAPTCHA_EXPIRE_TIME); +} + +function showMessage(type, text) { + const message = document.getElementById("link-application-message"); + if (!message) return; + + message.textContent = text; + message.dataset.type = type; + message.hidden = false; +} + +function hideMessage() { + const message = document.getElementById("link-application-message"); + if (!message) return; + + message.hidden = true; + message.textContent = ""; + delete message.dataset.type; +} + +async function submitApplication(form) { + const section = document.getElementById(SECTION_ID); + if (!section) return; + + const submitButton = form.querySelector('[type="submit"]'); + + hideMessage(); + + if (submitButton) { + submitButton.disabled = true; + submitButton.setAttribute("aria-busy", "true"); + } + + try { + const response = await fetch(form.action, { + method: form.method || "POST", + body: new FormData(form), + credentials: "same-origin", + }); + + const resultUrl = new URL(response.url); + const applied = resultUrl.searchParams.get("applied"); + + if (applied === "success") { + showMessage( + "success", + section.dataset.successMessage + ); + + form.reset(); + } else { + showMessage( + "error", + resultUrl.searchParams.get("message") || + section.dataset.errorMessage + ); + } + } catch { + showMessage( + "error", + section.dataset.errorMessage + ); + } finally { + refreshCaptcha(); + + const captchaCode = form.querySelector('[name="captchaCode"]'); + if (captchaCode) { + captchaCode.value = ""; + } + + if (submitButton) { + submitButton.disabled = false; + submitButton.removeAttribute("aria-busy"); + } + } +} + +function handleSubmit(event) { + const form = event.target.closest(`#${FORM_ID}`); + if (!form) return; + + event.preventDefault(); + submitApplication(form); +} + +function handleClick(event) { + const target = event.target.closest( + '[data-link-apply-action="refresh-captcha"]' + ); + + if (!target) return; + if (!target.closest(`#${SECTION_ID}`)) return; + + refreshCaptcha(); +} + +function registerLinkApplicationActions() { + if (listenersRegistered) return; + + document.addEventListener("submit", handleSubmit); + document.addEventListener("click", handleClick); + + listenersRegistered = true; +} + +function initLinkApplication() { + clearCaptchaTimer(); + + if (!document.getElementById(SECTION_ID)) return; + + refreshCaptcha(); +} + +terminal.registerInitFunc(registerLinkApplicationActions); +terminal.registerRefresh(initLinkApplication); \ No newline at end of file diff --git a/src/styles/links.scss b/src/styles/links.scss index 562e7ae..8ebff1b 100644 --- a/src/styles/links.scss +++ b/src/styles/links.scss @@ -99,6 +99,107 @@ opacity: 0.8; } + &-apply-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + column-gap: calc(var(--size-theme-font) * 1); + row-gap: calc(var(--size-theme-font) * 0.9); + } + + &-apply-item { + display: flex; + flex-direction: column; + gap: calc(var(--size-theme-font) * 0.3); + min-width: 0; + + label { + display: flex; + align-items: baseline; + gap: calc(var(--size-theme-font) * 0.25); + margin: 0; + color: var(--color-theme-foreground); + font-size: calc(var(--size-theme-font) * 0.85); + } + + &-full { + grid-column: 1 / -1; + } + + &-submit { + grid-column: 1 / -1; + align-items: flex-start; + margin-top: calc(var(--size-theme-font) * 0.3); + } + } + + &-required { + color: var(--color-theme-accent); + font-style: normal; + } + + &-apply-captcha { + .captcha-row { + display: flex; + align-items: stretch; + gap: calc(var(--size-theme-font) * 0.5); + + input { + flex: 1; + } + } + + .captcha-img-wrapper { + position: relative; + flex-shrink: 0; + width: 140px; + height: 40px; + } + + img { + width: 140px; + max-width: none !important; + height: 40px; + margin: 0; + padding: 0; + object-fit: contain; + background: #fff; + cursor: pointer; + border: calc(var(--width-theme-border) / 2) var(--style-theme-border) var(--color-theme-foreground); + + &:hover { + border-color: var(--color-theme-accent); + } + } + + .captcha-expired { + display: none; + position: absolute; + inset: 0; + align-items: center; + justify-content: center; + cursor: pointer; + background: var(--color-theme-background); + border: calc(var(--width-theme-border) / 2) var(--style-theme-border) var(--color-theme-accent); + + span { + color: var(--color-theme-accent); + font-size: calc(var(--size-theme-font) * 0.75); + text-align: center; + } + } + } + + &-apply-message { + margin-bottom: calc(var(--size-theme-font) * 1); + padding: calc(var(--size-theme-font) * 0.5) 0; + color: var(--color-theme-accent); + border-bottom: calc(var(--width-theme-border) / 2) var(--style-theme-table-border) var(--color-theme-accent); + } + + &-apply-submit-btn { + width: auto; + } + @media (max-width: 600px) { &-url { display: none; @@ -111,5 +212,22 @@ &-container { grid-template-columns: calc(var(--size-theme-font) * 3) 1fr; } + + &-apply-grid { + grid-template-columns: 1fr; + } + + &-apply-item { + &-full, + &-submit { + grid-column: auto; + } + } + + &-apply-captcha { + .captcha-row { + flex-wrap: wrap; + } + } } -} +} \ No newline at end of file diff --git a/templates/links.html b/templates/links.html index 0017103..b1ee078 100644 --- a/templates/links.html +++ b/templates/links.html @@ -12,9 +12,9 @@
@@ -40,6 +40,97 @@
+
+ + + +