|
1 | 1 | import type { SyncData, VideoData } from '../common'; |
2 | 2 |
|
3 | 3 | export async function VideoKuaishou(data: SyncData) { |
4 | | - const { content, video, title, tags = [], cover } = data.data as VideoData; |
5 | | - |
6 | | - // function formatDate(date: Date): string { |
7 | | - // const year = date.getFullYear(); |
8 | | - // const month = String(date.getMonth() + 1).padStart(2, '0'); |
9 | | - // const day = String(date.getDate()).padStart(2, '0'); |
10 | | - // const hours = String(date.getHours()).padStart(2, '0'); |
11 | | - // const minutes = String(date.getMinutes()).padStart(2, '0'); |
12 | | - // const seconds = String(date.getSeconds()).padStart(2, '0'); |
13 | | - // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
14 | | - // } |
| 4 | + const { content, video, title, tags = [], cover, scheduledPublishTime } = data.data as VideoData; |
| 5 | + |
| 6 | + function formatDate(date: Date): string { |
| 7 | + const year = date.getFullYear(); |
| 8 | + const month = String(date.getMonth() + 1).padStart(2, '0'); |
| 9 | + const day = String(date.getDate()).padStart(2, '0'); |
| 10 | + const hours = String(date.getHours()).padStart(2, '0'); |
| 11 | + const minutes = String(date.getMinutes()).padStart(2, '0'); |
| 12 | + const seconds = String(date.getSeconds()).padStart(2, '0'); |
| 13 | + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| 14 | + } |
15 | 15 |
|
16 | 16 | // 辅助函数:等待元素出现 |
17 | 17 | function waitForElement(selector: string, timeout = 10000): Promise<Element> { |
@@ -209,48 +209,44 @@ export async function VideoKuaishou(data: SyncData) { |
209 | 209 | } |
210 | 210 |
|
211 | 211 | // 定时发布功能 |
212 | | - // if (videoData.publishTime) { |
213 | | - // const labels = document.querySelectorAll('label'); |
214 | | - // const scheduledPublishLabel = Array.from(labels).find((el) => el.textContent?.includes('定时发布')); |
215 | | - |
216 | | - // if (scheduledPublishLabel) { |
217 | | - // scheduledPublishLabel.click(); |
218 | | - // await new Promise((resolve) => setTimeout(resolve, 500)); |
219 | | - |
220 | | - // const publishTimeInput = document.querySelector('input[placeholder="选择日期时间"]') as HTMLInputElement; |
221 | | - // if (publishTimeInput) { |
222 | | - // const publishDate = |
223 | | - // typeof videoData.publishTime === 'string' ? new Date(videoData.publishTime) : videoData.publishTime; |
224 | | - // publishTimeInput.value = formatDate(publishDate); |
225 | | - // publishTimeInput.dispatchEvent(new Event('input', { bubbles: true })); |
226 | | - // publishTimeInput.dispatchEvent(new Event('change', { bubbles: true })); |
227 | | - // await new Promise((resolve) => setTimeout(resolve, 2000)); |
228 | | - |
229 | | - // const confirmLis = document.querySelectorAll('li.ant-picker-ok'); |
230 | | - // const confirmLi = Array.from(confirmLis).find((el) => el.textContent === '确定'); |
231 | | - // if (confirmLi) { |
232 | | - // const confirmButton = confirmLi.querySelector('button'); |
233 | | - // if (confirmButton) { |
234 | | - // confirmButton.click(); |
235 | | - // } |
236 | | - // } |
237 | | - // } |
238 | | - // } |
239 | | - // } |
240 | | - |
241 | | - // 等待内容更新 |
242 | | - await new Promise((resolve) => setTimeout(resolve, 5000)); |
243 | | - |
244 | | - // 发布按钮逻辑 |
245 | | - const divElements = document.querySelectorAll('div'); |
246 | | - const publishButton = Array.from(divElements).find((el) => el.textContent === '发布') as HTMLElement; |
247 | | - |
248 | | - if (publishButton) { |
249 | | - if (data.isAutoPublish) { |
| 212 | + if (scheduledPublishTime && scheduledPublishTime > 0) { |
| 213 | + const labels = document.querySelectorAll('label'); |
| 214 | + const scheduledPublishLabel = Array.from(labels).find((el) => el.textContent?.includes('定时发布')); |
| 215 | + |
| 216 | + if (scheduledPublishLabel) { |
| 217 | + scheduledPublishLabel.click(); |
| 218 | + await new Promise((resolve) => setTimeout(resolve, 500)); |
| 219 | + |
| 220 | + const publishTimeInput = document.querySelector('input[placeholder="选择日期时间"]') as HTMLInputElement; |
| 221 | + if (publishTimeInput) { |
| 222 | + const publishDate = new Date(scheduledPublishTime); |
| 223 | + publishTimeInput.value = formatDate(publishDate); |
| 224 | + publishTimeInput.dispatchEvent(new Event('input', { bubbles: true })); |
| 225 | + publishTimeInput.dispatchEvent(new Event('change', { bubbles: true })); |
| 226 | + await new Promise((resolve) => setTimeout(resolve, 2000)); |
| 227 | + |
| 228 | + const confirmLis = document.querySelectorAll('li.ant-picker-ok'); |
| 229 | + const confirmLi = Array.from(confirmLis).find((el) => el.textContent === '确定'); |
| 230 | + if (confirmLi) { |
| 231 | + const confirmButton = confirmLi.querySelector('button'); |
| 232 | + if (confirmButton) { |
| 233 | + confirmButton.click(); |
| 234 | + } |
| 235 | + } |
| 236 | + } |
| 237 | + } |
| 238 | + // 等待内容更新 |
| 239 | + await new Promise((resolve) => setTimeout(resolve, 5000)); |
| 240 | + |
| 241 | + // 发布按钮逻辑 |
| 242 | + const divElements = document.querySelectorAll('div'); |
| 243 | + const publishButton = Array.from(divElements).find((el) => el.textContent === '发布') as HTMLElement; |
| 244 | + |
| 245 | + if (publishButton) { |
250 | 246 | console.log('找到发布按钮,准备点击'); |
251 | 247 | publishButton.click(); |
| 248 | + } else { |
| 249 | + console.error('未找到"发布"按钮'); |
252 | 250 | } |
253 | | - } else { |
254 | | - console.error('未找到"发布"按钮'); |
255 | 251 | } |
256 | 252 | } |
0 commit comments