diff --git a/.env b/.env index 0d89c647..85675d0c 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ APP_NAME=mediago APP_ID=mediago.ziying.site APP_COPYRIGHT=caorushizi -APP_VERSION=2.2.0-beta.0 +APP_VERSION=2.2.0-beta.1 APP_SERVER_PORT=8433 diff --git a/packages/main/.eslintignore b/packages/main/.eslintignore index e69de29b..a0d025dc 100644 --- a/packages/main/.eslintignore +++ b/packages/main/.eslintignore @@ -0,0 +1 @@ +./types diff --git a/packages/main/.prettierignore b/packages/main/.prettierignore index e69de29b..a7c47537 100644 --- a/packages/main/.prettierignore +++ b/packages/main/.prettierignore @@ -0,0 +1 @@ +types/ diff --git a/packages/main/app/package.json b/packages/main/app/package.json index 1bba01d4..af6c8cec 100644 --- a/packages/main/app/package.json +++ b/packages/main/app/package.json @@ -1,6 +1,6 @@ { "name": "mediago", - "version": "2.2.0-beta.0", + "version": "2.2.0-beta.1", "description": "在线视频下载器", "main": "main/index.js", "author": "", diff --git a/packages/main/src/services/SniffingHelperService.ts b/packages/main/src/services/SniffingHelperService.ts index d84d565b..e63d52e5 100644 --- a/packages/main/src/services/SniffingHelperService.ts +++ b/packages/main/src/services/SniffingHelperService.ts @@ -10,7 +10,7 @@ import { OnBeforeRequestListenerDetails, } from "electron/main"; -interface SourceParams { +export interface SourceParams { id: number; url: string; filter: SourceFilter; @@ -19,7 +19,7 @@ interface SourceParams { type: DownloadType; } -interface SourceFilter { +export interface SourceFilter { matches: RegExp[]; type: DownloadType; schema?: Record; diff --git a/packages/main/src/services/WebviewService.ts b/packages/main/src/services/WebviewService.ts index d577fc8f..64a0389c 100644 --- a/packages/main/src/services/WebviewService.ts +++ b/packages/main/src/services/WebviewService.ts @@ -61,7 +61,7 @@ export default class WebviewService { try { if (isDev && process.env.DEBUG_PLUGINS === "true") { const content = - 'const script=document.createElement("script");script.src="http://localhost:8080/src/main.ts";script.type="module";document.body.appendChild(script);'; + 'function addScript(src){const script=document.createElement("script");script.src=src;script.type="module";document.body.appendChild(script)}addScript("http://localhost:8080/src/main.ts");'; await this.webContents.executeJavaScript(content); } else { const content = readFileSync(pluginPath, "utf-8"); diff --git a/packages/plugin/src/components/BilibiliButton.ts b/packages/plugin/src/components/BilibiliButton.ts index 560df19c..57bbb600 100644 --- a/packages/plugin/src/components/BilibiliButton.ts +++ b/packages/plugin/src/components/BilibiliButton.ts @@ -46,3 +46,26 @@ export class BilibiliButton extends LitElement { return html`
下载
`; } } + +function bilibili() { + const videoCards = document.querySelectorAll(".bili-video-card"); + videoCards.forEach((card, index) => { + const imageDOM = card.querySelector(BILIBILI_DOWNLOAD_BUTTON); + if (!imageDOM) return; + + const oldBtn = imageDOM.querySelectorAll("one-button"); + if (oldBtn.length) return; + + const isAd = $(card).find(".bili-video-card__info--ad"); + if (isAd.length) return; + + const downloadButton = document.createElement("bilibili-button"); + downloadButton.index = index; + card.appendChild(downloadButton); + }); +} + +bilibili(); +setInterval(() => { + bilibili(); +}, 3000); diff --git a/packages/plugin/src/components/FloatButton.ts b/packages/plugin/src/components/FloatButton.ts index 7ac44bbe..8013a551 100644 --- a/packages/plugin/src/components/FloatButton.ts +++ b/packages/plugin/src/components/FloatButton.ts @@ -1,7 +1,19 @@ +/** + * 适用于 m3u8 视频下载的浮动按钮 + */ import { LitElement, html, css } from "lit"; import { customElement, property } from "lit/decorators.js"; import logo from "../assets/logo.png"; -import { addIpcListener, showDownloadDialog } from "../helper"; +import { addIpcListener, pluginReady, showDownloadDialog } from "../helper"; +import { DownloadType } from "../../../main/types/interfaces"; + +interface SourceData { + id: number; + url: string; + documentURL: string; + name: string; + type: DownloadType; +} @customElement("float-button") export class FloatButton extends LitElement { @@ -43,7 +55,7 @@ export class FloatButton extends LitElement { } `; - data: any = {}; + data: SourceData | null = null; @property({ type: Number }) count = 0; @@ -51,6 +63,9 @@ export class FloatButton extends LitElement { onClick(e: Event) { e.preventDefault(); e.stopPropagation(); + console.log("this.data:", this.data); + + if (!this.data) return; showDownloadDialog({ name: this.data.name, @@ -79,3 +94,13 @@ export class FloatButton extends LitElement { `; } } + +function init() { + const floatButton = document.createElement("float-button"); + document.body.appendChild(floatButton); + + // 向主进程发送插件准备好的消息 + pluginReady(); +} + +init(); diff --git a/packages/plugin/src/main.ts b/packages/plugin/src/main.ts index 135e18d7..4c309070 100644 --- a/packages/plugin/src/main.ts +++ b/packages/plugin/src/main.ts @@ -1,35 +1 @@ import "./components"; -import { BILIBILI_DOWNLOAD_BUTTON, pluginReady } from "./helper"; -import $ from "jquery"; - -// 哔哩哔哩 -function bilibili() { - const videoCards = document.querySelectorAll(".bili-video-card"); - videoCards.forEach((card, index) => { - const imageDOM = card.querySelector(BILIBILI_DOWNLOAD_BUTTON); - if (!imageDOM) return; - - const oldBtn = imageDOM.querySelectorAll("one-button"); - if (oldBtn.length) return; - - const isAd = $(card).find(".bili-video-card__info--ad"); - if (isAd.length) return; - - const downloadButton = document.createElement("bilibili-button"); - downloadButton.index = index; - card.appendChild(downloadButton); - }); -} - -function sniffing() { - const floatButton = document.createElement("float-button"); - document.body.appendChild(floatButton); -} - -sniffing(); -pluginReady(); - -bilibili(); -setInterval(() => { - bilibili(); -}, 3000); diff --git a/packages/renderer/package.json b/packages/renderer/package.json index f081ebfe..c019de26 100644 --- a/packages/renderer/package.json +++ b/packages/renderer/package.json @@ -53,10 +53,10 @@ "eslint-plugin-promise": "^6.1.1", "eslint-plugin-react": "^7.33.2", "prettier": "3.2.5", + "sass": "^1.70.0", "stylelint": "^16.2.1", "stylelint-config-standard": "^36.0.0", "stylelint-config-standard-scss": "^13.0.0", - "sass": "^1.70.0", "typescript": "~5.3.3", "vite": "^5.0.12" },