Skip to content

Commit

Permalink
修改获取页面title bug
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Sep 13, 2024
1 parent 1f3db29 commit 6bc8ba8
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 197 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ https://github.com/027xiguapi/code-box
- 未登录`php中文网`状态下,不会再出现强制登录弹窗
- 未登录`php中文网`状态下,移动端代码右上角按钮一键复制

![img](https://raw.githubusercontent.com/027xiguapi/code-box/main/public/8.jpg)
![img](https://raw.githubusercontent.com/027xiguapi/code-box/main/public/8.png)
![img](https://raw.githubusercontent.com/027xiguapi/code-box/main/public/1.jpg)
![img](https://raw.githubusercontent.com/027xiguapi/code-box/main/public/2.png)
![img](https://raw.githubusercontent.com/027xiguapi/code-box/main/public/3.jpg)
Expand Down
20 changes: 4 additions & 16 deletions contents/51cto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,15 @@ 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,
saveMarkdown,
setIcon
} from "~tools"
import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
matches: ["https://*.51cto.com/*"]
}

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

export default function Cto51() {
const [copyCode] = useStorage<boolean>("51cto-copyCode")
Expand Down Expand Up @@ -204,12 +192,12 @@ export default function Cto51() {
function downloadMarkdown() {
const html = document.querySelector("article")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
}

function downloadHtml() {
const dom = document.querySelector("article")
saveHtml(dom, article.title)
saveHtml(dom, articleTitle)
}

return <div style={{ display: "none" }}></div>
Expand Down
20 changes: 4 additions & 16 deletions contents/baidu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@ import { useEffect } from "react"
import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"

import { Readability } from "~node_modules/@mozilla/readability"
import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
matches: ["https://*.baidu.com/*"]
}

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

export default function Custom() {
const [closeAIBox] = useStorage<boolean>("baidu-closeAIBox")
Expand Down Expand Up @@ -58,12 +46,12 @@ export default function Custom() {
function downloadMarkdown() {
const html = document.querySelector(".wd-ai-index-pc")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
}

function downloadHtml() {
const dom = document.querySelector(".wd-ai-index-pc")
saveHtml(dom, article.title)
saveHtml(dom, articleTitle)
}

return <div style={{ display: "none" }}></div>
Expand Down
19 changes: 4 additions & 15 deletions contents/cnblogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ 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,
saveMarkdown,
setIcon
} from "~tools"
import { saveHtml, saveMarkdown, setIcon } from "~tools"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
Expand All @@ -20,12 +14,7 @@ export const config: PlasmoCSConfig = {
}

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

export default function cnblogs() {
const [copyCode] = useStorage<boolean>("cnblogs-copyCode")
Expand Down Expand Up @@ -127,12 +116,12 @@ export default function cnblogs() {
function downloadMarkdown() {
const html = document.querySelector("#post_detail")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
}

function downloadHtml() {
const dom = document.querySelector("#post_detail")
saveHtml(dom, article.title)
saveHtml(dom, articleTitle)
}

return <div style={{ display: "none" }}></div>
Expand Down
20 changes: 4 additions & 16 deletions contents/csdn.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import { Readability } from "@mozilla/readability"
import type { PlasmoCSConfig } from "plasmo"
import { useEffect, useRef } from "react"
import { v4 as uuidv4 } from "uuid"

import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"

import {
addCss,
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
matches: ["https://*.blog.csdn.net/*"]
}

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

const csdn = () => {
const [closeAds] = useStorage<boolean>("csdn-closeAds")
Expand Down Expand Up @@ -251,12 +239,12 @@ const csdn = () => {
function downloadMarkdown() {
const html = document.querySelector(".blog-content-box")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
}

function downloadHtml() {
const dom = document.querySelector(".blog-content-box")
saveHtml(dom, article.title)
saveHtml(dom, articleTitle)
}

return <div style={{ display: "none" }}></div>
Expand Down
15 changes: 7 additions & 8 deletions contents/custom.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Readability } from "@mozilla/readability"
import { useEffect, useState } from "react"

import { useMessage } from "@plasmohq/messaging/hook"
Expand All @@ -9,8 +8,8 @@ import Dom2Pdf from "~utils/html2Pdf"
import Turndown from "~utils/turndown"

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

setIcon(false)

let isSelect = false
Expand Down Expand Up @@ -93,7 +92,7 @@ export default function Custom() {
if (code && code.querySelector("code")) {
code = code.querySelector("code")
}
code && saveTxt(code.innerText, article.title)
code && saveTxt(code.innerText, articleTitle)
}

function getSelection(type) {
Expand Down Expand Up @@ -127,30 +126,30 @@ export default function Custom() {
function downloadHtml() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
saveHtml(currentDom, article.title)
saveHtml(currentDom, articleTitle)
isSelect = false
}

function downloadMarkdown() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
const markdown = turndownService.turndown(currentDom)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
isSelect = false
}

function downloadPdf() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
const pdf = new Dom2Pdf(currentDom, article.title)
const pdf = new Dom2Pdf(currentDom, articleTitle)
pdf.downloadPdf()
isSelect = false
}

function downloadImg() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
const img = new Dom2Pdf(currentDom, article.title)
const img = new Dom2Pdf(currentDom, articleTitle)
img.downloadImg()
isSelect = false
}
Expand Down
20 changes: 4 additions & 16 deletions contents/jb51.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,15 @@ 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,
saveMarkdown,
setIcon
} from "~tools"
import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
matches: ["https://*.jb51.net/*"]
}

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

export default function jb51() {
const [closeAds] = useStorage<boolean>("jb51-closeAds")
Expand Down Expand Up @@ -208,12 +196,12 @@ export default function jb51() {
function downloadMarkdown() {
const html = document.querySelector("#article")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
}

function downloadHtml() {
const dom = document.querySelector("#article")
saveHtml(dom, article.title)
saveHtml(dom, articleTitle)
}

return <div style={{ display: "none" }}></div>
Expand Down
20 changes: 4 additions & 16 deletions contents/jianshu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,15 @@ 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,
saveMarkdown,
setIcon
} from "~tools"
import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
matches: ["https://*.jianshu.com/*"]
}

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

export default function Jianshu() {
const [closeLoginModal] = useStorage<boolean>("jianshu-closeLoginModal")
Expand Down Expand Up @@ -158,12 +146,12 @@ export default function Jianshu() {
function downloadMarkdown() {
const html = document.querySelector("section.ouvJEz")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
}

function downloadHtml() {
const dom = document.querySelector("section.ouvJEz")
saveHtml(dom, article.title)
saveHtml(dom, articleTitle)
}

return <div style={{ display: "none" }}></div>
Expand Down
19 changes: 4 additions & 15 deletions contents/juejin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,15 @@ import { useEffect } from "react"

import { useMessage } from "@plasmohq/messaging/hook"

import { Readability } from "~node_modules/@mozilla/readability"
import {
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
import { saveHtml, saveMarkdown, setIcon } from "~tools"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
matches: ["https://*.juejin.cn/*"]
}

const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
const articleTitle = document.querySelector<HTMLElement>("head title").innerText

export default function Juejin() {
useEffect(() => {
Expand All @@ -44,12 +33,12 @@ export default function Juejin() {
function downloadMarkdown() {
const html = document.querySelector("article.article")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
saveMarkdown(markdown, articleTitle)
}

function downloadHtml() {
const dom = document.querySelector("article.article")
saveHtml(dom, article.title)
saveHtml(dom, articleTitle)
}

return <div style={{ display: "none" }}></div>
Expand Down
Loading

0 comments on commit 6bc8ba8

Please sign in to comment.