Compare commits
8
Commits
803b6b8e10
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f245b14ea | ||
|
|
834048c8ba | ||
|
|
cdcc2c3172 | ||
|
|
df179792e7 | ||
|
|
daad7aeecd | ||
|
|
c252ceafb2 | ||
|
|
3733461807 | ||
|
|
ea1fe98c20 |
+2
-2
@@ -5,9 +5,9 @@ export default {
|
||||
printWidth: 80,
|
||||
tabWidth: 2,
|
||||
useTabs: false,
|
||||
semi: false,
|
||||
semi: true,
|
||||
singleQuote: false,
|
||||
trailingComma: "none",
|
||||
trailingComma: "all",
|
||||
bracketSpacing: true,
|
||||
bracketSameLine: true,
|
||||
plugins: ["@ianvs/prettier-plugin-sort-imports"],
|
||||
|
||||
@@ -3,6 +3,10 @@ import type { PlasmoMessaging } from "@plasmohq/messaging";
|
||||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
||||
|
||||
if (!token || !siteUrl) {
|
||||
throw new Error("未指定 Token 或站点地址");
|
||||
}
|
||||
|
||||
// 更新追番进度
|
||||
if (req.body.action === "updateBangumiProgress") {
|
||||
const { values } = req.body;
|
||||
|
||||
@@ -3,6 +3,10 @@ import type { PlasmoMessaging } from "@plasmohq/messaging";
|
||||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
||||
|
||||
if (!token || !siteUrl) {
|
||||
throw new Error("未指定 Token 或站点地址");
|
||||
}
|
||||
|
||||
if (req.body.action === "addRead") {
|
||||
const { values } = req.body;
|
||||
const formData = new FormData();
|
||||
|
||||
@@ -3,6 +3,10 @@ import type { PlasmoMessaging } from "@plasmohq/messaging";
|
||||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
||||
|
||||
if (!token || !siteUrl) {
|
||||
throw new Error("未指定 Token 或站点地址");
|
||||
}
|
||||
|
||||
if (req.body.action === "addSay") {
|
||||
const { values } = req.body;
|
||||
const formData = new FormData();
|
||||
|
||||
@@ -3,6 +3,10 @@ import type { PlasmoMessaging } from "@plasmohq/messaging";
|
||||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
||||
|
||||
if (!token || !siteUrl) {
|
||||
throw new Error("未指定 Token 或站点地址");
|
||||
}
|
||||
|
||||
// 添加手办
|
||||
if (req.body.action === "addToy") {
|
||||
const { values } = req.body;
|
||||
|
||||
@@ -9,7 +9,7 @@ interface FormValue {
|
||||
content: string;
|
||||
author: string;
|
||||
origin: string;
|
||||
links: string;
|
||||
link: string;
|
||||
is_comment: boolean;
|
||||
}
|
||||
|
||||
@@ -55,8 +55,12 @@ function Say() {
|
||||
<input {...bindInput("author")} placeholder="作者" />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="links">链接</label>
|
||||
<input {...bindInput("links")} placeholder="链接" />
|
||||
<label htmlFor="origin">来源</label>
|
||||
<input {...bindInput("origin")} placeholder="来源" />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="link">链接</label>
|
||||
<input {...bindInput("link")} placeholder="链接" />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="is_comment">摘抄</label>
|
||||
|
||||
@@ -17,6 +17,7 @@ interface FormValue {
|
||||
type: number;
|
||||
desc: string;
|
||||
productId: string;
|
||||
link: string;
|
||||
}
|
||||
|
||||
const getInfo = async () => {
|
||||
@@ -127,6 +128,10 @@ function Toy() {
|
||||
<label htmlFor="productId">B 站产品 ID</label>
|
||||
<input {...bindInput("productId")} placeholder="B 站产品 ID" />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="link">手办维基链接</label>
|
||||
<input {...bindInput("link")} placeholder="https://www.hpoi.net/hobby/xxxxx" />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="desc">描述</label>
|
||||
<textarea {...bindInput("desc")} rows={5} placeholder="描述"></textarea>
|
||||
|
||||
@@ -6,6 +6,47 @@ export const config: PlasmoCSConfig = {
|
||||
|
||||
chrome.runtime.onMessage.addListener((req, sender, send) => {
|
||||
if (req.type === "toolbox:getBiliToy") {
|
||||
// 疑似新版?
|
||||
if (window.location.pathname.includes("neul-next")) {
|
||||
const item = document.querySelectorAll<HTMLDivElement>(".franky-swiper-item.image-list");
|
||||
|
||||
if (!item.length) {
|
||||
send(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const project = document.querySelector<HTMLDivElement>(".tagC-ip .tagC-ip-con")?.innerText || "";
|
||||
const made = document.querySelector<HTMLDivElement>(".tagC-ip .tagC-ip-con-brand")?.innerText || "";
|
||||
const sale = document.querySelector<HTMLDivElement>(".item-complex:nth-child(4) .item-complex-value")?.innerText || "";
|
||||
|
||||
const projectExp = new RegExp(`\s?${project}\s?`);
|
||||
const madeExp = new RegExp(`\s?${made}\s?`);
|
||||
const name = document.querySelector<HTMLDivElement>(".clamp-real-text")
|
||||
.innerText.replace(/\[\S+\]/, "")
|
||||
.replace(projectExp, "")
|
||||
.replace(madeExp, "")
|
||||
.replaceAll(/\s?Q版手办\s?|\s?粘土人\s?/g, "")
|
||||
.trim();
|
||||
|
||||
const images = [];
|
||||
|
||||
item.forEach((item) => {
|
||||
images.push(
|
||||
item.querySelector("img").src
|
||||
);
|
||||
});
|
||||
|
||||
send({
|
||||
name,
|
||||
project: project.replace(":", ":"),
|
||||
made,
|
||||
sale: sale.replace("-", "/"),
|
||||
images,
|
||||
productId: new URLSearchParams(location.search).get("itemsId"),
|
||||
});
|
||||
}
|
||||
|
||||
// 旧版,不确定是否还在使用
|
||||
const item = document.querySelectorAll<HTMLDivElement>(".silde-item");
|
||||
|
||||
if (item.length) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { PlasmoCSConfig } from "plasmo";
|
||||
|
||||
export const config: PlasmoCSConfig = {
|
||||
matches: ["https://c.pc.qq.com/*"],
|
||||
};
|
||||
|
||||
const url = new URL(location.href);
|
||||
const redirectUrl = url.searchParams.get("url");
|
||||
|
||||
const titleEl = document.querySelector(".container .title");
|
||||
const descEl = document.querySelector(".container .p");
|
||||
|
||||
if (titleEl) {
|
||||
if (titleEl.innerHTML === "已停止访问该网页") {
|
||||
titleEl.innerHTML = "傻逼腾讯,我就要访问这个网页!";
|
||||
}
|
||||
}
|
||||
|
||||
if (descEl) {
|
||||
descEl.innerHTML = "小窝工具箱扩展,将自动为你跳转到对应的链接";
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if (redirectUrl) {
|
||||
window.location.href = redirectUrl;
|
||||
}
|
||||
}, 1000);
|
||||
+30
-17
@@ -121,26 +121,31 @@ const getHTML = () => {
|
||||
if (location.host === "mp.weixin.qq.com") {
|
||||
console.log("微信");
|
||||
|
||||
return formatHTML(document.querySelector(".rich_media_content").innerHTML);
|
||||
return formatHTML(document.querySelector(".rich_media_content").innerHTML, {
|
||||
baseURL: location.origin,
|
||||
});
|
||||
}
|
||||
|
||||
// 腾讯云开发者社区
|
||||
if (location.host === "cloud.tencent.com") {
|
||||
console.log("腾讯云");
|
||||
|
||||
return formatHTML(document.querySelector(".rno-markdown").innerHTML, (doc) => {
|
||||
// 替换掉腾讯云自己的链接
|
||||
const qcloudLinkEl = doc.querySelectorAll("a");
|
||||
qcloudLinkEl.forEach((el) => {
|
||||
if (el.href.includes("qcloud")) {
|
||||
el.parentNode.replaceChild(document.createTextNode(el.innerText), el);
|
||||
}
|
||||
});
|
||||
return formatHTML(document.querySelector(".rno-markdown").innerHTML, {
|
||||
formatter: (doc) => {
|
||||
// 替换掉腾讯云自己的链接
|
||||
const qcloudLinkEl = doc.querySelectorAll("a");
|
||||
qcloudLinkEl.forEach((el) => {
|
||||
if (el.href.includes("qcloud")) {
|
||||
el.parentNode.replaceChild(document.createTextNode(el.innerText), el);
|
||||
}
|
||||
});
|
||||
|
||||
const mdTextEl = doc.querySelectorAll(".rno-markdown__textlink-new") as NodeListOf<HTMLElement>;
|
||||
mdTextEl.forEach((el) => {
|
||||
el.parentNode.replaceChild(document.createTextNode(el.innerText), el);
|
||||
});
|
||||
const mdTextEl = doc.querySelectorAll(".rno-markdown__textlink-new") as NodeListOf<HTMLElement>;
|
||||
mdTextEl.forEach((el) => {
|
||||
el.parentNode.replaceChild(document.createTextNode(el.innerText), el);
|
||||
});
|
||||
},
|
||||
baseURL: location.origin,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -150,7 +155,9 @@ const getHTML = () => {
|
||||
if (itemPropArticle) {
|
||||
console.log("掘金");
|
||||
|
||||
return formatHTML(itemPropArticle.innerHTML);
|
||||
return formatHTML(itemPropArticle.innerHTML, {
|
||||
baseURL: location.origin,
|
||||
});
|
||||
}
|
||||
|
||||
// CSDN
|
||||
@@ -159,7 +166,9 @@ const getHTML = () => {
|
||||
if (contentViews) {
|
||||
console.log("CSDN");
|
||||
|
||||
return formatHTML(contentViews.innerHTML);
|
||||
return formatHTML(contentViews.innerHTML, {
|
||||
baseURL: location.origin,
|
||||
});
|
||||
}
|
||||
|
||||
// 通用模式
|
||||
@@ -168,7 +177,9 @@ const getHTML = () => {
|
||||
if (articleEl) {
|
||||
console.log("文章标签");
|
||||
|
||||
return formatHTML(articleEl.innerHTML);
|
||||
return formatHTML(articleEl.innerHTML, {
|
||||
baseURL: location.origin,
|
||||
});
|
||||
}
|
||||
|
||||
// 尝试匹配到文章
|
||||
@@ -196,7 +207,9 @@ const getHTML = () => {
|
||||
}
|
||||
}
|
||||
|
||||
return formatHTML(parentEl.innerHTML);
|
||||
return formatHTML(parentEl.innerHTML, {
|
||||
baseURL: location.origin,
|
||||
});
|
||||
}
|
||||
|
||||
return "";
|
||||
|
||||
+9
-9
@@ -11,23 +11,23 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@plasmohq/messaging": "^0.6.2",
|
||||
"plasmo": "0.85.2",
|
||||
"plasmo": "0.90.5",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ianvs/prettier-plugin-sort-imports": "4.1.0",
|
||||
"@types/chrome": "0.0.266",
|
||||
"@types/node": "20.5.0",
|
||||
"@types/react": "18.2.20",
|
||||
"@types/react-dom": "18.2.7",
|
||||
"@ianvs/prettier-plugin-sort-imports": "4.1.1",
|
||||
"@types/chrome": "0.0.258",
|
||||
"@types/node": "20.11.5",
|
||||
"@types/react": "18.2.48",
|
||||
"@types/react-dom": "18.2.18",
|
||||
"less": "^4.2.0",
|
||||
"prettier": "3.0.2",
|
||||
"typescript": "5.1.6"
|
||||
"prettier": "3.2.4",
|
||||
"typescript": "5.3.3"
|
||||
},
|
||||
"manifest": {
|
||||
"permissions": [
|
||||
"tabs", "storage", "scripting", "contextMenus"
|
||||
"tabs", "storage", "scripting", "contextMenus", "clipboardWrite"
|
||||
],
|
||||
"host_permissions": [
|
||||
"https://*/*"
|
||||
|
||||
Generated
+4503
-3353
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
allowBuilds:
|
||||
'@parcel/watcher': true
|
||||
'@swc/core': true
|
||||
esbuild: true
|
||||
lmdb: true
|
||||
msgpackr-extract: true
|
||||
sharp: true
|
||||
+39
-7
@@ -25,8 +25,15 @@ const removeAttributes = (el: HTMLElement) => {
|
||||
});
|
||||
}
|
||||
|
||||
interface FormatHTMLOptions {
|
||||
formatter?: (doc: Document) => void;
|
||||
baseURL?: string;
|
||||
}
|
||||
|
||||
// 格式化 HTML 内容
|
||||
export const formatHTML = (html: string, extraFormatter?: (doc: Document) => void) => {
|
||||
export const formatHTML = (html: string, options: FormatHTMLOptions = {}) => {
|
||||
const { formatter, baseURL } = options;
|
||||
|
||||
// 删除空格
|
||||
html = html.replaceAll(" ", "");
|
||||
|
||||
@@ -64,11 +71,30 @@ export const formatHTML = (html: string, extraFormatter?: (doc: Document) => voi
|
||||
// 优化 img 标签,仅保留有效内容
|
||||
const imgEl = nextDocument.querySelectorAll("img") as NodeListOf<HTMLImageElement>;
|
||||
imgEl.forEach((el) => {
|
||||
const nextImgEl = document.createElement("img");
|
||||
nextImgEl.src = el.src;
|
||||
nextImgEl.alt = el.alt;
|
||||
const tempImg = document.createElement("img");
|
||||
|
||||
el.parentNode.replaceChild(nextImgEl, el);
|
||||
// 创建一个临时的 a 元素来解析相对路径
|
||||
const tempLink = document.createElement("a");
|
||||
tempLink.href = el.src;
|
||||
|
||||
// 如果提供了 baseURL 且图片链接是相对路径,则使用 baseURL 构建完整链接
|
||||
if (baseURL && !tempLink.href.startsWith('http')) {
|
||||
tempImg.src = new URL(el.src, baseURL).href;
|
||||
} else {
|
||||
tempImg.src = tempLink.href;
|
||||
}
|
||||
|
||||
tempImg.alt = el.alt;
|
||||
|
||||
// 复制 width 和 height 属性
|
||||
if (el.width) {
|
||||
tempImg.width = el.width;
|
||||
}
|
||||
if (el.height) {
|
||||
tempImg.height = el.height;
|
||||
}
|
||||
|
||||
el.parentNode.replaceChild(tempImg, el);
|
||||
});
|
||||
|
||||
// 删除 figure 标签
|
||||
@@ -88,6 +114,12 @@ export const formatHTML = (html: string, extraFormatter?: (doc: Document) => voi
|
||||
el.remove();
|
||||
});
|
||||
|
||||
// 删除 script 标签
|
||||
const scriptEl = nextDocument.querySelectorAll("script");
|
||||
scriptEl.forEach((el) => {
|
||||
el.remove();
|
||||
});
|
||||
|
||||
// 提取 pre 下面的内容
|
||||
const preEl = nextDocument.querySelectorAll("pre");
|
||||
preEl.forEach((el) => {
|
||||
@@ -105,8 +137,8 @@ export const formatHTML = (html: string, extraFormatter?: (doc: Document) => voi
|
||||
}
|
||||
});
|
||||
|
||||
if (extraFormatter) {
|
||||
extraFormatter(nextDocument);
|
||||
if (formatter) {
|
||||
formatter(nextDocument);
|
||||
}
|
||||
|
||||
return nextDocument.documentElement.innerHTML;
|
||||
|
||||
Reference in New Issue
Block a user