将网页下载成markdown

This commit is contained in:
fzk
2024-08-28 09:43:16 +08:00
parent 46b486ccb2
commit 8e4e8fe74e
18 changed files with 193 additions and 11 deletions
+9
View File
@@ -12,6 +12,12 @@ export default function Cto51() {
(v) => (v === undefined ? true : v)
)
function downloadMarkdown() {
sendToContentScript({
name: "51cto-downloadMarkdown"
})
}
function downloadHtml() {
sendToContentScript({
name: "51cto-downloadHtml"
@@ -47,6 +53,9 @@ export default function Cto51() {
htmlFor="51cto-closeLoginModal"
className="codebox-switch"></label>
</div>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
</div>
+9
View File
@@ -8,6 +8,12 @@ export default function Custom() {
v === undefined ? false : v
)
function downloadMarkdown() {
sendToContentScript({
name: "baidu-downloadMarkdown"
})
}
function downloadHtml() {
sendToContentScript({
name: "baidu-downloadHtml"
@@ -29,6 +35,9 @@ export default function Custom() {
/>
<label className="codebox-switch" htmlFor="baidu-closeAIBox"></label>
</div>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
</div>
+9
View File
@@ -14,6 +14,12 @@ export default function Cnblogs() {
})
}
function downloadMarkdown() {
sendToContentScript({
name: "cnblogs-downloadMarkdown"
})
}
return (
<fieldset>
<legend>{i18n("cnblogsConfig")}</legend>
@@ -29,6 +35,9 @@ export default function Cnblogs() {
/>
<label className="codebox-switch" htmlFor="cnblogs-copyCode"></label>
</div>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
</div>
+1 -1
View File
@@ -133,7 +133,7 @@ export default function Csdn() {
htmlFor="csdn-closeRedirectModal"
className="codebox-switch"></label>
</div>
<div className="item download hide" onClick={downloadMarkdown}>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
+9
View File
@@ -11,6 +11,12 @@ export default function Jb51() {
v === undefined ? true : v
)
function downloadMarkdown() {
sendToContentScript({
name: "jb51-downloadMarkdown"
})
}
function downloadHtml() {
sendToContentScript({
name: "jb51-downloadHtml"
@@ -44,6 +50,9 @@ export default function Jb51() {
/>
<label className="codebox-switch" htmlFor="jb51-copyCode"></label>
</div>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
</div>
+9
View File
@@ -16,6 +16,12 @@ export default function Jianshu() {
(v) => (v === undefined ? true : v)
)
function downloadMarkdown() {
sendToContentScript({
name: "jianshu-downloadMarkdown"
})
}
function downloadHtml() {
sendToContentScript({
name: "jianshu-downloadHtml"
@@ -65,6 +71,9 @@ export default function Jianshu() {
className="codebox-switch"
htmlFor="jianshu-autoOpenCode"></label>
</div>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
</div>
+9
View File
@@ -18,6 +18,12 @@ export default function Php() {
})
}
function downloadMarkdown() {
sendToContentScript({
name: "php-downloadMarkdown"
})
}
return (
<fieldset>
<legend>{i18n("phpConfig")}</legend>
@@ -45,6 +51,9 @@ export default function Php() {
/>
<label htmlFor="php-closeLoginModal" className="codebox-switch"></label>
</div>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
</div>
+9
View File
@@ -22,6 +22,12 @@ export default function Zhihu() {
})
}
function downloadMarkdown() {
sendToContentScript({
name: "zhihu-downloadMarkdown"
})
}
return (
<fieldset>
<legend>{i18n("zhihuConfig")}</legend>
@@ -63,6 +69,9 @@ export default function Zhihu() {
/>
<label className="codebox-switch" htmlFor="zhihu-autoOpenCode"></label>
</div>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
</div>
+17 -1
View File
@@ -1,17 +1,26 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect } from "react"
import TurndownService from "turndown"
import { v4 as uuidv4 } from "uuid"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { Readability } from "~node_modules/@mozilla/readability"
import { addCss, getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.51cto.com/*"]
}
const turndownService = new TurndownService()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
@@ -39,6 +48,7 @@ export default function Cto51() {
res.send({ isShow: true })
}
if (req.name == "51cto-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "51cto-downloadHtml") {
downloadHtml()
@@ -192,6 +202,12 @@ export default function Cto51() {
addCss(css)
}
function downloadMarkdown() {
const html = document.querySelector("article")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector("article")
saveHtml(dom, article.title)
+16 -2
View File
@@ -1,16 +1,23 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect } from "react"
import TurndownService from "turndown"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { Readability } from "~node_modules/@mozilla/readability"
import { addCss, getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.baidu.com/*"]
}
const turndownService = new TurndownService()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
@@ -33,6 +40,7 @@ export default function Custom() {
res.send({ isShow: true })
}
if (req.name == "baidu-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "baidu-downloadHtml") {
downloadHtml()
@@ -46,6 +54,12 @@ export default function Custom() {
}`)
}
function downloadMarkdown() {
const html = document.querySelector(".wd-ai-index-pc")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector(".wd-ai-index-pc")
saveHtml(dom, article.title)
+15 -1
View File
@@ -1,18 +1,25 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect, useRef } from "react"
import TurndownService from "turndown"
import { v4 as uuidv4 } from "uuid"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { Readability } from "~node_modules/@mozilla/readability"
import { getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.cnblogs.com/*"],
all_frames: true
}
const turndownService = new TurndownService()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
@@ -36,6 +43,7 @@ export default function cnblogs() {
res.send({ isShow: true })
}
if (req.name == "cnblogs-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "cnblogs-downloadHtml") {
downloadHtml()
@@ -116,6 +124,12 @@ export default function cnblogs() {
})
}
function downloadMarkdown() {
const html = document.querySelector("#post_detail")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector("#post_detail")
saveHtml(dom, article.title)
+8 -1
View File
@@ -7,7 +7,13 @@ import { v4 as uuidv4 } from "uuid"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { addCss, getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.blog.csdn.net/*"]
@@ -246,6 +252,7 @@ const csdn = () => {
function downloadMarkdown() {
const html = document.querySelector(".blog-content-box")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
+16 -1
View File
@@ -1,17 +1,25 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect } from "react"
import TurndownService from "turndown"
import { v4 as uuidv4 } from "uuid"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { Readability } from "~node_modules/@mozilla/readability"
import { addCss, getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.jb51.net/*"]
}
const turndownService = new TurndownService()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
@@ -37,6 +45,7 @@ export default function jb51() {
res.send({ isShow: true })
}
if (req.name == "jb51-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "jb51-downloadHtml") {
downloadHtml()
@@ -196,6 +205,12 @@ export default function jb51() {
}`)
}
function downloadMarkdown() {
const html = document.querySelector("#article")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector("#article")
saveHtml(dom, article.title)
+16 -1
View File
@@ -1,17 +1,25 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect, useRef } from "react"
import TurndownService from "turndown"
import { v4 as uuidv4 } from "uuid"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { Readability } from "~node_modules/@mozilla/readability"
import { addCss, getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.jianshu.com/*"]
}
const turndownService = new TurndownService()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
@@ -40,6 +48,7 @@ export default function Jianshu() {
res.send({ isShow: true })
}
if (req.name == "jianshu-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "jianshu-downloadHtml") {
downloadHtml()
@@ -146,6 +155,12 @@ export default function Jianshu() {
}
}
function downloadMarkdown() {
const html = document.querySelector("section.ouvJEz")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector("section.ouvJEz")
saveHtml(dom, article.title)
+16 -1
View File
@@ -1,17 +1,25 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect } from "react"
import TurndownService from "turndown"
import { v4 as uuidv4 } from "uuid"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { Readability } from "~node_modules/@mozilla/readability"
import { addCss, getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.php.cn/*"]
}
const turndownService = new TurndownService()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
@@ -39,6 +47,7 @@ export default function Php() {
res.send({ isShow: true })
}
if (req.name == "php-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "php-downloadHtml") {
downloadHtml()
@@ -186,6 +195,12 @@ export default function Php() {
addCss(css)
}
function downloadMarkdown() {
const html = document.querySelector(".phpscMain .php-article")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector(".phpscMain .php-article")
saveHtml(dom, article.title)
+16 -1
View File
@@ -1,17 +1,25 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect, useRef } from "react"
import TurndownService from "turndown"
import { v4 as uuidv4 } from "uuid"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"
import { Readability } from "~node_modules/@mozilla/readability"
import { addCss, getMetaContentByProperty, saveHtml, setIcon } from "~tools"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
export const config: PlasmoCSConfig = {
matches: ["https://*.zhihu.com/*"]
}
const turndownService = new TurndownService()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
@@ -40,6 +48,7 @@ export default function zhihu() {
res.send({ isShow: true })
}
if (req.name == "zhihu-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "zhihu-downloadHtml") {
downloadHtml()
@@ -166,6 +175,12 @@ export default function zhihu() {
}
}
function downloadMarkdown() {
const html = document.querySelector("article.Post-Main")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector("article.Post-Main")
saveHtml(dom, article.title)
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "code-box",
"displayName": "__MSG_extensionName__",
"version": "0.5.2",
"version": "0.5.3",
"description": "__MSG_extensionDescription__",
"author": "027xiguapi. <458813868@qq.com>",
"scripts": {
+8
View File
@@ -35,6 +35,14 @@ export function saveHtml(dom: Element, filename?: string) {
}
}
export function saveMarkdown(markdown: string, filename?: string) {
if (markdown) {
const blob = new Blob([markdown], { type: "text/markdown;charset=utf-8" })
filename = filename || "CodeBox-page"
saveAs(blob, `${filename}.md`)
}
}
export function i18n(key: string) {
return chrome.i18n.getMessage(key)
}