From 4d7b0ba906d8594453207604a1780f618790f8f7 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 1 Feb 2024 22:20:18 +0800 Subject: [PATCH] feat: popup and options data --- src/background/rss.ts | 3 +-- src/lib/report.ts | 8 ++++++-- src/options/routes/About.tsx | 8 ++++++++ src/options/routes/General.tsx | 4 ++++ src/options/routes/Rules.tsx | 4 ++++ src/popup/RSSItem.tsx | 31 ++++++++++++++++++++++++++++--- src/popup/index.tsx | 4 ++-- 7 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/background/rss.ts b/src/background/rss.ts index 37f3f4c..c940e8c 100644 --- a/src/background/rss.ts +++ b/src/background/rss.ts @@ -32,8 +32,7 @@ export const getRSS = async (tabId, url) => { report({ url, - name: "get-rss" - }) + }) const html = await sendToContentScript({ name: "requestHTML", tabId diff --git a/src/lib/report.ts b/src/lib/report.ts index d3d2fe2..8e1e984 100644 --- a/src/lib/report.ts +++ b/src/lib/report.ts @@ -1,6 +1,9 @@ function report({ - url, + url = "https://radar.rsshub", name, +}: { + url?: string + name?: string }) { if (process.env.PLASMO_PUBLIC_UMAMI_ID && process.env.PLASMO_PUBLIC_UMAMI_URL) { let hostname = "" @@ -25,7 +28,8 @@ function report({ headers: { "content-type": "application/json", }, - body: JSON.stringify(umamiData) + body: JSON.stringify(umamiData), + keepalive: true }) } } diff --git a/src/options/routes/About.tsx b/src/options/routes/About.tsx index 9f40452..11e227f 100644 --- a/src/options/routes/About.tsx +++ b/src/options/routes/About.tsx @@ -1,9 +1,17 @@ +import { useEffect } from "react" import { Card, CardContent, } from "~/lib/components/Card" +import report from "~/lib/report" function About() { + useEffect(() => { + report({ + name: "options-about" + }) + }, []) + return (

{chrome.i18n.getMessage("about")}

diff --git a/src/options/routes/General.tsx b/src/options/routes/General.tsx index cf51c80..4c66ec9 100644 --- a/src/options/routes/General.tsx +++ b/src/options/routes/General.tsx @@ -18,6 +18,7 @@ import type { Rules as IRules } from "~/lib/types" import { sendToBackground } from "@plasmohq/messaging" import { Loader2 } from "lucide-react" import toast from "react-hot-toast" +import report from "~/lib/report" function General() { let [config] = useStorage("config") @@ -27,6 +28,9 @@ function General() { sendToBackground({ name: "requestDisplayedRules" }).then((res) => setRules(parseRules(res, true))) + report({ + name: "options-general" + }) }, []) const [count, setCount] = useState(0) diff --git a/src/options/routes/Rules.tsx b/src/options/routes/Rules.tsx index 40c3a09..a72a895 100644 --- a/src/options/routes/Rules.tsx +++ b/src/options/routes/Rules.tsx @@ -12,6 +12,7 @@ import { import { Card, CardContent } from "~/lib/components/Card" import { parseRules, getRulesCount } from "~/lib/rules" import type { Rules as IRules } from "~/lib/types" +import report from "~/lib/report" function Rules() { const [rules, setRules] = useState({}) @@ -19,6 +20,9 @@ function Rules() { sendToBackground({ name: "requestDisplayedRules" }).then((res) => setRules(parseRules(res, true))) + report({ + name: "options-rules" + }) }, []) const [count, setCount] = useState(0) diff --git a/src/popup/RSSItem.tsx b/src/popup/RSSItem.tsx index 38815c1..c62853a 100644 --- a/src/popup/RSSItem.tsx +++ b/src/popup/RSSItem.tsx @@ -7,6 +7,7 @@ import RSSHubIcon from "data-base64:~/assets/icon.png" import { useCopyToClipboard } from 'usehooks-ts' import MD5 from 'md5.js'; import { quickSubscriptions } from "~/lib/quick-subscriptions" +import report from "~/lib/report" function RSSItem({ item, @@ -52,7 +53,15 @@ function RSSItem({ {item.isDocs && ( - )} {!item.isDocs && !hidePreview && ( -