Browse Source

截图功能

PUGE 1 tháng trước cách đây
mục cha
commit
91b06c3463
6 tập tin đã thay đổi với 98 bổ sung35 xóa
  1. 1 0
      .gitignore
  2. 48 33
      dist/自动举报/preLoadFile.js
  3. 2 0
      dist/自动举报/preload.js
  4. 44 1
      main.js
  5. 1 1
      preLoadFile.js
  6. 2 0
      preload.js

+ 1 - 0
.gitignore

@@ -13,3 +13,4 @@ LICENSE.electron.txt
 vk_swiftshader_icd.json
 LICENSES.chromium.html
 *.zip
+screenshots/*

+ 48 - 33
dist/自动举报/preLoadFile.js

@@ -103,43 +103,58 @@ function triggerHoverEvents() {
 
 
 
-setTimeout(() => {
-  if (location.href.startsWith('https://www.douyin.com/user/')) {
-    // 执行触发
-    triggerHoverEvents();
-    setTimeout(() => {
-      document.querySelectorAll('.ug0uBNhF div').forEach(element => {
-          if (element.querySelector('span')) {
-              const typeText = element.querySelector('span').innerText
-              console.log(typeText)
-              if (typeText == window.darw.jbxx.split('-')[0]) {
-                  element.querySelector('.A9Seu0Hm').click()
-              }
-          }
+// setTimeout(() => {
+//   if (location.href.startsWith('https://www.douyin.com/user/')) {
+//     // 执行触发
+//     triggerHoverEvents();
+//     setTimeout(() => {
+//       document.querySelectorAll('.ug0uBNhF div').forEach(element => {
+//           if (element.querySelector('span')) {
+//               const typeText = element.querySelector('span').innerText
+//               console.log(typeText)
+//               if (typeText == window.darw.jbxx.split('-')[0]) {
+//                   element.querySelector('.A9Seu0Hm').click()
+//               }
+//           }
           
-      });
-      // 二级举报
-      setTimeout(() => {
-        document.querySelectorAll('.ug0uBNhF div').forEach(element => {
-            if (element.querySelector('span')) {
-                const typeText = element.querySelector('span').innerText
-                console.log(typeText)
-                if (typeText == window.darw.jbxx.split('-')[1]) {
-                    element.querySelector('.A9Seu0Hm').click()
-                }
-            }
-        });
+//       });
+//       // 二级举报
+//       setTimeout(() => {
+//         document.querySelectorAll('.ug0uBNhF div').forEach(element => {
+//             if (element.querySelector('span')) {
+//                 const typeText = element.querySelector('span').innerText
+//                 console.log(typeText)
+//                 if (typeText == window.darw.jbxx.split('-')[1]) {
+//                     element.querySelector('.A9Seu0Hm').click()
+//                 }
+//             }
+//         });
         
-      }, 3000);
-      document.querySelector('.mlG4sNlr textarea').value = window.darw.jbly
+//       }, 3000);
+//       document.querySelector('.mlG4sNlr textarea').value = window.darw.jbly
 
-      setTimeout(() => {
-        document.querySelector('button.GPAlcn2R').click()
-      }, 5000);
-    }, 5000);
-  }
-}, 5000);
+//       setTimeout(() => {
+//         // document.querySelector('button.GPAlcn2R').click()
+//       }, 5000);
+//     }, 5000);
+//   }
+// }, 5000);
 
+loadJS('https://html2canvas.hertzen.com/dist/html2canvas.min.js')
+function captureAndDownload(element) {
+    
+    html2canvas(element, {
+    scale: 2, // 提高截图质量
+    useCORS: true, // 允许跨域图片
+    backgroundColor: null // 透明背景
+    }).then(canvas => {
+    // 创建下载链接
+    const link = document.createElement('a');
+    link.download = '截图.png';
+    link.href = canvas.toDataURL('image/png');
+    link.click();
+    });
+}
 loadJS('https://cunchu.site/puge/ws.js', () => {
   let wsOptions = {
     isAdmin: false,

+ 2 - 0
dist/自动举报/preload.js

@@ -20,6 +20,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
   broadcast: (msg) => ipcRenderer.send('broadcast-message', msg),
   saveFile: (msg) => ipcRenderer.invoke('saveFile', msg),
   readFile: (msg) => ipcRenderer.invoke('readFile', msg),
+  // 截屏
+  capture: () => ipcRenderer.send('capture'),
   onBroadcast: (callback) => ipcRenderer.on('message-broadcast', (event, data) => callback(data)),
   // 下载文件
   downloadFile: (url, filename, path) => {

+ 44 - 1
main.js

@@ -1,5 +1,5 @@
 // Modules to control application life and create native browser window
-const {app, ipcMain, BrowserWindow, session} = require('electron')
+const {app, ipcMain, BrowserWindow, session, dialog } = require('electron')
 const path = require('path')
 const fs = require('fs')
 const iconv = require('iconv-lite');
@@ -892,6 +892,49 @@ ipcMain.on("download", (event, message) => {
   event.returnValue = {err: 0}
 })
 
+// 网页截屏
+ipcMain.on('capture', async (event, options = {}) => {
+  console.log('收到截图请求,静默保存');
+  
+  try {
+    const targetWindow = BrowserWindow.getFocusedWindow() || mainWindow;
+    if (!targetWindow) {
+      console.error('没有找到可用的窗口');
+      event.reply('capture-error', '没有找到可用的窗口');
+      return;
+    }
+
+    // 截取整个页面
+    const image = await targetWindow.webContents.capturePage();
+    
+    // 固定保存路径 - 不再弹出对话框
+    const baseDir = app.isPackaged 
+      ? path.dirname(app.getPath('exe'))
+      : process.cwd();
+    
+    const downloadDir = path.join(baseDir, 'screenshots');
+    
+    // 确保目录存在
+    if (!fs.existsSync(downloadDir)) {
+      fs.mkdirSync(downloadDir, { recursive: true });
+    }
+    
+    // 生成文件名(带时间戳)
+    const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
+    const filePath = path.join(downloadDir, `screenshot-${timestamp}.png`);
+    
+    // 保存文件
+    fs.writeFileSync(filePath, image.toPNG());
+    
+    console.log('截图已静默保存到:', filePath);
+    event.reply('capture-success', filePath);
+    
+  } catch (error) {
+    console.error('截图失败:', error);
+    event.reply('capture-error', error.message);
+  }
+});
+
 // 窗口间通信
 ipcMain.on('broadcast-message', (event, message) => {
   // 获取发送者

+ 1 - 1
preLoadFile.js

@@ -134,7 +134,7 @@ setTimeout(() => {
       document.querySelector('.mlG4sNlr textarea').value = window.darw.jbly
 
       setTimeout(() => {
-        document.querySelector('button.GPAlcn2R').click()
+        // document.querySelector('button.GPAlcn2R').click()
       }, 5000);
     }, 5000);
   }

+ 2 - 0
preload.js

@@ -20,6 +20,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
   broadcast: (msg) => ipcRenderer.send('broadcast-message', msg),
   saveFile: (msg) => ipcRenderer.invoke('saveFile', msg),
   readFile: (msg) => ipcRenderer.invoke('readFile', msg),
+  // 截屏
+  capture: () => ipcRenderer.send('capture'),
   onBroadcast: (callback) => ipcRenderer.on('message-broadcast', (event, data) => callback(data)),
   // 下载文件
   downloadFile: (url, filename, path) => {