Kaynağa Gözat

修复userAgent设置无效

PUGE 4 ay önce
ebeveyn
işleme
9d93889b80

+ 1 - 1
config.json

@@ -1,5 +1,5 @@
 {
-    "enterURL": "https://mms.pinduoduo.com/chat-service/status?msfrom=mms_sidenav",
+    "enterURL": "https://web.whatsapp.com/",
     "width": 800,
     "height": 600,
     "webPreferences": {

+ 23 - 0
dist/whatsapp发消息/config.json

@@ -0,0 +1,23 @@
+{
+    "enterURL": "https://web.whatsapp.com/",
+    "width": 800,
+    "height": 600,
+    "webPreferences": {
+        "webSecurity": false,
+        "nodeIntegration": false,
+        "nativeWindowOpen": false,
+        "preload": "<dir>/preload.js",
+        "worldSafeExecuteJavaScript": true,
+        "enableRemoteModule": false,
+        "safeDialogs": false
+    },
+    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36",
+    "autoHideMenuBar": true,
+    "redirect":[],
+    "redirectURL":"",
+    "proxy":"",
+    "noCache": false,
+    "interceptor":[
+    ],
+    "preLoadFile": "<dir>/preLoadFile.js"
+}

+ 114 - 0
dist/whatsapp发消息/preLoadFile.js

@@ -0,0 +1,114 @@
+function simulateTyping(searchBox, text, callBack) {
+
+    if (!searchBox) return;
+    
+    // 确保搜索框获得焦点
+    searchBox.focus();
+    
+    // 模拟逐个字符输入
+    text.split('').forEach((char, index) => {
+        setTimeout(() => {
+            // 创建键盘事件
+            const keyDownEvent = new KeyboardEvent('keydown', {
+                key: char,
+                code: `Key${char.toUpperCase()}`,
+                bubbles: true
+            });
+            
+            const keyPressEvent = new KeyboardEvent('keypress', {
+                key: char,
+                bubbles: true
+            });
+            
+            const keyUpEvent = new KeyboardEvent('keyup', {
+                key: char,
+                bubbles: true
+            });
+            
+            // 触发事件
+            searchBox.dispatchEvent(keyDownEvent);
+            searchBox.dispatchEvent(keyPressEvent);
+            
+            // 插入字符
+            document.execCommand('insertText', false, char);
+            
+            searchBox.dispatchEvent(keyUpEvent);
+            
+            // 如果是最后一个字符,触发搜索
+            if (index === text.length - 1) {
+                const inputEvent = new Event('input', { bubbles: true });
+                searchBox.dispatchEvent(inputEvent);
+            }
+        }, index * 100 + 500); // 100ms 间隔模拟打字
+    });
+    setTimeout(() => {
+        // 触发所有可能的事件
+        const events = ['input', 'change', 'keyup', 'keydown', 'keypress', 'blur', 'focus'];
+        
+        events.forEach(eventType => {
+            const event = eventType.startsWith('key') 
+                ? new KeyboardEvent(eventType, { bubbles: true })
+                : new Event(eventType, { bubbles: true });
+            
+            searchBox.dispatchEvent(event);
+        });
+        if (callBack) callBack()
+    }, text.split('').length * 100);
+    
+}
+
+
+function simulateFullClick(element) {
+    // 鼠标按下
+    const mouseDownEvent = new MouseEvent('mousedown', {
+        view: window,
+        bubbles: true,
+        cancelable: true,
+        buttons: 1
+    });
+    
+    // 鼠标抬起
+    const mouseUpEvent = new MouseEvent('mouseup', {
+        view: window,
+        bubbles: true,
+        cancelable: true,
+        buttons: 1
+    });
+    
+    // 点击事件
+    const clickEvent = new MouseEvent('click', {
+        view: window,
+        bubbles: true,
+        cancelable: true,
+        buttons: 1
+    });
+    
+    // 按顺序触发事件
+    element.dispatchEvent(mouseDownEvent);
+    element.dispatchEvent(mouseUpEvent);
+    element.dispatchEvent(clickEvent);
+}
+
+
+
+
+function searchText(text, sendText) {
+    const searchBox = document.querySelector('div[contenteditable="true"][aria-label="搜索输入内容文本框"]');
+    if (document.querySelector('._ah_y.x1eu8d0j')) {
+        document.querySelector('._ah_y.x1eu8d0j').click()
+    }
+    setTimeout(() => {
+        simulateTyping(searchBox, text, () => {
+            setTimeout(() => {
+                const gridcellList = document.querySelectorAll('.x1n2onr6[role="gridcell"]')
+                if (gridcellList.length > 0) {
+                    simulateFullClick(gridcellList[0].querySelector('._ak72'))
+                    setTimeout(() => {
+                        simulateTyping(document.querySelector('[aria-placeholder="输入消息"]'), sendText)
+                    }, 2000);
+                }
+            }, 2000);
+        });
+    }, 1000);
+}
+

+ 33 - 0
dist/whatsapp发消息/preload.js

@@ -0,0 +1,33 @@
+const { contextBridge, ipcRenderer } = require('electron');
+
+
+
+// window.open = (url)=>{console.log(url)}
+window.lastText = ''
+window.lastText2 = ''
+
+
+
+contextBridge.exposeInMainWorld('electronAPI', {
+  openWindow: (msg) => ipcRenderer.invoke('openWindow', msg),
+  closeAllWindow: (msg) => ipcRenderer.send('closeAllWindow', msg),
+  getData: (msg) => ipcRenderer.send('getData', msg),
+  postData: (msg) => ipcRenderer.send('postData', msg),
+  setProxy: (msg) => ipcRenderer.send('setProxy', msg),
+  addPreLoadCode: (msg) => ipcRenderer.send('addPreLoadCode', msg),
+  setStoData: (msg) => ipcRenderer.send('setStoData', msg),
+  getStoData: (msg) => ipcRenderer.send('getStoData', msg),
+  closeWindow: (msg) => ipcRenderer.send('closeWindow', msg),
+  changeProxy: (msg) => ipcRenderer.send('changeProxy', msg),
+  readConfig: (msg) => ipcRenderer.send('readConfig', msg),
+  saveConfig: (msg) => ipcRenderer.send('saveConfig', msg),
+  setMaxWindowOpenNum: (msg) => ipcRenderer.send('setMaxWindowOpenNum', msg),
+  readdir: (msg) => ipcRenderer.send('readdir', msg),
+  download: (msg) => ipcRenderer.send('download', msg),
+  broadcast: (msg) => ipcRenderer.send('broadcast-message', msg),
+  saveFile: (msg) => ipcRenderer.invoke('saveFile', msg),
+  readFile: (msg) => ipcRenderer.invoke('readFile', msg),
+  onBroadcast: (callback) => ipcRenderer.on('message-broadcast', (event, data) => callback(data))
+});
+
+

+ 1 - 1
dist/拼多多客服提醒/preLoadFile.js

@@ -43,4 +43,4 @@ function sendMessage (text) {
 
 setInterval(() => {
   if(document.querySelector('.update')) document.querySelector('.update').click()
-}, 10000);
+}, 120000);

+ 14 - 9
dist/油管数据/preLoadFile.js

@@ -89,20 +89,20 @@ function cutString (original, before, after, index) {
     if (P > -1) {
       if (after) {
         const f = original.indexOf(after, P + before.length);
-        return (f>-1)? original.slice(P + before.toString().length, f):console.error("Tool [在文本中找不到 参数三 "+after+"]");
+        return (f>-1)? original.slice(P + before.toString().length, f):"";
       } else {
         return original.slice(P + before.toString().length);
       }
     } else {
       console.error("Tool [在文本中找不到 参数一 " + before + "]");
-      return
+      return ''
     }
   } else {
     console.error("Tool [sizeTransition:" + index + "不是一个整数!]");
   }
 }
 
-function checkText () {
+function checkText (adtaArr, index) {
   if (window.noRun) return
   if (document.querySelector('.style-scope.ytd-about-channel-renderer') || document.querySelector('ytm-about-channel-renderer').innerText) {
     window.noRun = true
@@ -110,15 +110,20 @@ function checkText () {
     if (!pdInfo) {
       pdInfo = document.querySelector('ytm-about-channel-renderer').innerText
     }
-    let bfsl = parseInt(cutString(pdInfo,'视频\n\n\t', '次观看'))
-    let spsl = parseInt(cutString(pdInfo,'订阅者\n\n\t', '个视频'))
-    let dyrs = parseInt(cutString(pdInfo,'注册\n\n\t', '位订阅者'))
+    let bfsl = parseInt(cutString(pdInfo,'视频\n\n\t', '次观看').replaceAll(',', ''))
+    let spsl = parseInt(cutString(pdInfo,'订阅者\n\n\t', '个视频').replaceAll(',', ''))
+    let dyrs = parseInt(cutString(pdInfo,'注册\n\n\t', '位订阅者').replaceAll(',', ''))
     if (!spsl) {
-      spsl = parseInt(cutString(pdInfo,'注册\n', '个视频'))
+      spsl = parseInt(cutString(pdInfo,'注册\n', '个视频').replaceAll(',', ''))
     }
     bfsl = bfsl ? bfsl : 0
     spsl = spsl ? spsl : 0
     dyrs = dyrs ? dyrs : 0
+    if (document.title.includes('404')) {
+      bfsl = -1
+      spsl = -1
+      dyrs = -1
+    }
     console.log(bfsl, spsl, dyrs)
     adtaArr[index][5] = bfsl
     adtaArr[index][6] = spsl
@@ -140,10 +145,10 @@ function checkData (adtaArr) {
         setTimeout(() => {
           document.querySelector('.yt-truncated-text__absolute-button').click()
           setTimeout(() => {
-            checkText()
+            checkText(adtaArr, index)
           }, 3000);
           setTimeout(() => {
-            checkText()
+            checkText(adtaArr, index)
           }, 8000);
           setTimeout(() => {
             location.reload()

+ 4 - 0
main.js

@@ -233,6 +233,10 @@ function createWindow (partitionSession) {
     mainWindow.loadURL(url); // 当前窗口跳转
     return { action: 'deny' }; // 阻止 Electron 弹出窗口
   });
+  
+  // 使用纯 Chrome User Agent,完全移除 Electron 相关标识
+  
+  mainWindow.webContents.setUserAgent(webConfig.userAgent ? webConfig.userAgent : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
   if (enterURL.startsWith('http')) {
     mainWindow.loadURL(enterURL)
   } else {