Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions entrypoints/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default defineContentScript({
showConfetti,
useDeffudle,
wrapInTripleBackticks,
removeRedundantNewlines,
enableSourceTracking,
} = options

const html = msg.payload
Expand Down Expand Up @@ -140,6 +142,24 @@ export default defineContentScript({
.turndown(html)
}

if (removeRedundantNewlines) {
markdown = markdown.replace(/\n{3,}/g, "\n\n")
}

if (enableSourceTracking) {
const pageTitle = document.title || "Untitled Page"
const pageUrl = window.location.href
const copyTime = new Date().toLocaleString("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
})

markdown = `${markdown}\n\n---\n\n**来源信息**\n- 标题:${pageTitle}\n- 链接:${pageUrl}\n- 复制时间:${copyTime}`
}

await copyAndNotify({
markdown,
wrapInTripleBackticks,
Expand All @@ -155,8 +175,13 @@ export default defineContentScript({
if (msg.type === "COPY_YOUTUBE_SUBTITLE") {
const options = await getOptions()

const { showSuccessToast, showConfetti, wrapInTripleBackticks } =
options
const {
showSuccessToast,
showConfetti,
wrapInTripleBackticks,
removeRedundantNewlines,
enableSourceTracking,
} = options

const videoId = msg.payload

Expand All @@ -177,6 +202,24 @@ export default defineContentScript({

markdown = `# ${title}\n\n\n${markdown}`

if (removeRedundantNewlines) {
markdown = markdown.replace(/\n{3,}/g, "\n\n")
}

if (enableSourceTracking) {
const pageTitle = document.title || title
const pageUrl = window.location.href
const copyTime = new Date().toLocaleString("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
})

markdown = `${markdown}\n\n---\n\n**来源信息**\n- 标题:${pageTitle}\n- 链接:${pageUrl}\n- 复制时间:${copyTime}`
}

await copyAndNotify({
markdown,
wrapInTripleBackticks,
Expand Down
22 changes: 22 additions & 0 deletions entrypoints/options/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ export const App = () => {
}
infoLink="https://x.com/raycastapp/status/1691464764516343808"
/>

<div className="border-border border-t"></div>

<ToggleOption
title="排版优化 - 去除冗余换行"
description="开启后自动清理复制内容中多余的空行,让文本阅读更整洁流畅"
checked={options.removeRedundantNewlines}
onCheckedChange={(checked) =>
handleOptionChange("removeRedundantNewlines", checked)
}
/>

<div className="border-border border-t"></div>

<ToggleOption
title="资料溯源增强"
description="开启后复制正文时,自动拼接附带网页标题、原始来源链接、实时复制时间信息,统一排版展示"
checked={options.enableSourceTracking}
onCheckedChange={(checked) =>
handleOptionChange("enableSourceTracking", checked)
}
/>
</>
)}
</div>
Expand Down
4 changes: 4 additions & 0 deletions lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type OptionsState = {
wrapInTripleBackticks: boolean
showSuccessToast: boolean
showConfetti: boolean
removeRedundantNewlines: boolean
enableSourceTracking: boolean
}

export const defaultOptions: OptionsState = {
Expand All @@ -14,6 +16,8 @@ export const defaultOptions: OptionsState = {
wrapInTripleBackticks: true,
showSuccessToast: true,
showConfetti: false,
removeRedundantNewlines: false,
enableSourceTracking: false,
}

export async function getOptions(): Promise<OptionsState> {
Expand Down
Loading
Loading