From 1e5f8eb33bc41cb59faf059e83701152785cabea Mon Sep 17 00:00:00 2001
From: yingyu5658
Date: Sat, 13 Dec 2025 08:33:08 +0800
Subject: Initial commit
---
static/js/webmention.min.js | 196 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 196 insertions(+)
create mode 100644 static/js/webmention.min.js
(limited to 'static/js/webmention.min.js')
diff --git a/static/js/webmention.min.js b/static/js/webmention.min.js
new file mode 100644
index 0000000..61f107d
--- /dev/null
+++ b/static/js/webmention.min.js
@@ -0,0 +1,196 @@
+// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt
+!(function () {
+ "use strict";
+ window.i18next = window.i18next || {
+ t: function t(e) {
+ return e;
+ },
+ };
+ let t = window.i18next.t.bind(window.i18next);
+ function e(t, e) {
+ return document.currentScript.getAttribute("data-" + t) || e;
+ }
+ let o = e("page-url", window.location.href.replace(/#.*$/, "")),
+ n = e("add-urls", void 0),
+ r = e("id", "webmentions"),
+ s = e("wordcount"),
+ l = e("max-webmentions", 30),
+ i = e("prevent-spoofing") ? "wm-source" : "url",
+ a = e("sort-by", "published"),
+ u = e("sort-dir", "up"),
+ p = e("comments-are-reactions", !1),
+ c = {
+ "in-reply-to": t("replied"),
+ "like-of": t("liked"),
+ "repost-of": t("reposted"),
+ "bookmark-of": t("bookmarked"),
+ "mention-of": t("mentioned"),
+ rsvp: t("RSVPed"),
+ "follow-of": t("followed"),
+ },
+ f = {
+ "in-reply-to": "\uD83D\uDCAC",
+ "like-of": "❤️",
+ "repost-of": "\uD83D\uDD04",
+ "bookmark-of": "⭐️",
+ "mention-of": "\uD83D\uDCAC",
+ rsvp: "\uD83D\uDCC5",
+ "follow-of": "\uD83D\uDC1C",
+ },
+ m = {
+ yes: "✅",
+ no: "❌",
+ interested: "\uD83D\uDCA1",
+ maybe: "\uD83D\uDCAD",
+ };
+ function d(t) {
+ return t.replace(
+ /[&<>"]/g,
+ (t) =>
+ ({ "&": "&", "<": "<", ">": ">", '"': """ })[
+ t
+ ] || t,
+ );
+ }
+ function h(e, o) {
+ let n = d(e.author?.name || e.url.split("/")[2]),
+ r = c[e["wm-property"]] || t("reacted");
+ !o && e.content && e.content.text && (r += ": " + x(e));
+ let s = "";
+ s =
+ e.author && e.author.photo
+ ? `
+
+ `
+ : `
+
+ `;
+ let l = "";
+ return (
+ e.rsvp && m[e.rsvp] && (l = `${m[e.rsvp]}`),
+ `
+
+ ${s}
+ ${f[e["wm-property"]] || "\uD83D\uDCA5"}
+ ${l}
+
+ `
+ );
+ }
+ function g(t) {
+ return t.substr(t.indexOf("//"));
+ }
+ function w(t) {
+ let e = [],
+ o = {};
+ return (
+ t.forEach(function (t) {
+ let n = g(t.url);
+ o[n] || (e.push(t), (o[n] = !0));
+ }),
+ e
+ );
+ }
+ function x(t) {
+ let e = d(t.content.text);
+ if (s) {
+ let o = e.replace(/\s+/g, " ").split(" ", s + 1);
+ o.length > s &&
+ ((o[s - 1] += "…"), (e = (o = o.slice(0, s)).join(" ")));
+ }
+ return e;
+ }
+ window.addEventListener("load", async function () {
+ let e = document.getElementById(r);
+ if (!e) return;
+ let s = [g(o)];
+ n &&
+ n.split("|").forEach(function (t) {
+ s.push(g(t));
+ });
+ let c = `https://webmention.io/api/mentions.jf2?per-page=${l}&sort-by=${a}&sort-dir=${u}`;
+ s.forEach(function (t) {
+ c += `&target[]=${encodeURIComponent("http:" + t)}&target[]=${encodeURIComponent("https:" + t)}`;
+ });
+ let f = {};
+ try {
+ let m = await window.fetch(c);
+ m.status >= 200 && m.status < 300
+ ? (f = await m.json())
+ : (console.error("Could not parse response"),
+ Error(m.statusText));
+ } catch (y) {
+ console.error("Request failed", y);
+ }
+ let b = [],
+ k = [];
+ p && (b = k);
+ let B = {
+ "in-reply-to": b,
+ "like-of": k,
+ "repost-of": k,
+ "bookmark-of": k,
+ "follow-of": k,
+ "mention-of": b,
+ rsvp: b,
+ };
+ f.children.forEach(function (t) {
+ let e = B[t["wm-property"]];
+ e && e.push(t);
+ });
+ let S = "";
+ b.length > 0 &&
+ b !== k &&
+ (S = (function e(o) {
+ let n = `
${t("Responses")}
`,
+ r = o
+ .map((e) => {
+ let o = h(e, !0),
+ n = d(e.url.split("/")[2]);
+ e.author && e.author.name && (n = d(e.author.name));
+ let r = `${n}`,
+ s = "name",
+ l = `(${t("mention")})`;
+ e.name
+ ? ((s = "name"), (l = d(e.name)))
+ : e.content &&
+ e.content.text &&
+ ((s = "text"), (l = x(e)));
+ let a = `${l}`;
+ return `${r}
+ `;
+ })(w(b)));
+ let D = "";
+ k.length > 0 &&
+ (D = (function e(o) {
+ let n = `${t("Reactions")}
`,
+ r = o.map((t) => h(t)).join("");
+ return `
+ ${n}
+ ${r}
+ `;
+ })(w(k)));
+ let $ = `${S}${D}`;
+ ($.trim() || ($ = '
暂无 Webmention 回应。
'), + (e.innerHTML = $)); + }); +})(); // @license-end -- cgit v1.2.3