qiushang 8 ماه پیش
والد
کامیت
b523cf9ad8
3فایلهای تغییر یافته به همراه41 افزوده شده و 51 حذف شده
  1. 1 1
      package.json
  2. 7 5
      src/renderer/components/header.vue
  3. 33 45
      src/renderer/components/home.vue

+ 1 - 1
package.json

@@ -9,7 +9,7 @@
 		"description": "这里是软件描述文档",
 		"downloadName": "XYCapture",
 		"softMid": "Ds8JqlRmiiGR",
-		"softName": "星优图片下载助手",
+		"softName": "图片下载助手",
 		"copyright": "苏州星优办公软件有限公司",
 		"popupAdvId": "30",
 		"linkId": "31",

+ 7 - 5
src/renderer/components/header.vue

@@ -299,15 +299,17 @@
 					type: 'warning'
 				}).then(() => {
 					this.cacheLoading = true;
-					let path = os.tmpdir() + '\\' + 'chrome-data-capture';
-					let path2 = os.tmpdir() + '\\' + 'chrome-data-capture-jd';
-					this.deleteFolder(path, false);
-					this.deleteFolder(path2, false);
+					setTimeout(() => {
+						let path = os.tmpdir() + '\\' + 'chrome-data-capture';
+						let path2 = os.tmpdir() + '\\' + 'chrome-data-capture-jd';
+						this.deleteFolder(path, false);
+						this.deleteFolder(path2, false);
+					}, 500);
 					setTimeout(() => {
 						this.$message({message: '缓存清除成功!', type: 'success'});
 						this.$emit('clear-cache', true);
 						this.cacheLoading = false;
-					}, 3000)
+					}, 2000)
 				}).catch(() => {
 				
 				});

+ 33 - 45
src/renderer/components/home.vue

@@ -425,9 +425,13 @@
 					shell.openExternal(url);
 				});
 			});
-			
 		},
 		methods: {
+			// 实时获取浏览器路径
+			initPath(){
+				let chromePath = puppeteer.executablePath().replace('win32-1', 'win64-1');
+				return chromePath;
+			},
 			// 删除文件夹内容
 			deleteAll(folderPath, flag) {
 				if (fs.existsSync(folderPath)) {
@@ -686,7 +690,7 @@
 						
 						const tbBrowser = await puppeteer.launch({
 							headless: false,
-							executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+							executablePath: this.initPath(),
 							args: ['--window-size=1280,800'],
 							userDataDir: userDataDir, 
 						});
@@ -877,7 +881,7 @@
 							urlInfo.num = 0;
 							puppeteer.use(StealthPlugin());
 							const browser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+								executablePath: this.initPath(),
 								userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
 								args: [
 									'--start-maximized',
@@ -1005,7 +1009,7 @@
 							urlInfo.num = 0;
 							puppeteer.use(StealthPlugin());
 							const browser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+								executablePath: this.initPath(),
 								userDataDir: os.tmpdir() + separator + 'chrome-data-capture', 
 							});
 							const page = await browser.newPage();
@@ -1079,7 +1083,7 @@
 					(async () => {
 						try{
 							const jdBrowser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+								executablePath: this.initPath(),
 								userDataDir: os.tmpdir() + separator + 'chrome-data-capture-jd', 
 							});
 							const page = await jdBrowser.newPage();
@@ -1110,6 +1114,7 @@
 							this.checkLoading = false;
 							jdBrowser.close();
 						}catch(e){
+							this.checkLoading = false;
 							reject(3);
 							this.showError(e);
 						}
@@ -1127,7 +1132,7 @@
 							urlInfo.num = 0;
 							puppeteer.use(StealthPlugin());
 							const jdBrowser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+								executablePath: this.initPath(),
 								userDataDir: os.tmpdir() + separator + 'chrome-data-capture-jd',
 								args: [
 									'--no-sandbox',
@@ -1348,11 +1353,12 @@
 									let mainImgUrl = arr1[i].src;
 									let reg = /\/n[0-9]+\/jfs\//;
 									let reg2 = /\/n[0-9]+\/s(54|50)x(54|66)_jfs\//;
+									let reg3 = /![a-z]+_[0-9]+x[0-9]+.avif/;
 									let replaceStr = '/n1/s800x800_jfs/';
 									if(mainImgUrl.match(/\/n[0-9]+\/s50x66_jfs\//)){
 										replaceStr = '/n1/s750x1000_jfs/';
 									}
-									mainImgUrl = mainImgUrl.replace(reg, replaceStr).replace(reg2, replaceStr).replace('.avif', '');
+									mainImgUrl = mainImgUrl.replace(reg, replaceStr).replace(reg2, replaceStr).replace(reg3, '').replace('.avif', '');
 								
 									if(!authority && i < execNum){
 										outObj.mainImg.push(mainImgUrl);
@@ -1455,7 +1461,7 @@
 					(async () => {
 						try{
 							const tbBrowser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+								executablePath: this.initPath(),
 								userDataDir: os.tmpdir() + separator + 'chrome-data-capture', 
 							});
 							const page = await tbBrowser.newPage();
@@ -1485,6 +1491,7 @@
 							this.checkLoading = false;
 							tbBrowser.close();
 						}catch(e){
+							this.checkLoading = false;
 							reject(3);
 							this.showError(e);
 						}
@@ -1503,7 +1510,7 @@
 							urlInfo.num = 0;
 							puppeteer.use(StealthPlugin());
 							const tbBrowser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+								executablePath: this.initPath(),
 								userDataDir: os.tmpdir() + separator + 'chrome-data-capture', 
 							});
 							const page = await tbBrowser.newPage();
@@ -1983,16 +1990,6 @@
 							outObj.detailImg.push(arr3[i].src);
 						}
 					}
-					//评论图片 -- 需要点击切换
-					// let arr4 = document.querySelectorAll('img.image-box');
-					// for(let i=0; i< arr4.length; i++){
-					// 	if(!authority && i < execNum){
-					// 		outObj.commentImg.push(arr4[i].src);
-					// 	}
-					// 	if(authority){
-					// 		outObj.commentImg.push(arr4[i].src);
-					// 	}
-					// }
 					// 视频
 					let arr5 = document.querySelectorAll('video.lib-video');
 					for(let i=0; i< arr5.length; i++){
@@ -2085,27 +2082,6 @@
 						}
 					}
 				}
-				
-				//评论图下载
-				// if(this.settingArr.indexOf('commentImg') > -1){
-				// 	for(let j = 0; j < imgInfo.commentImg.length; j++){
-				// 		let fileName = imgInfo.commentImg[j].split('/').pop();
-				// 		if(fileName){
-				// 			let queryIndex = fileName.indexOf('?');
-				// 			if (queryIndex !== -1) {
-				// 				fileName = fileName.substr(0, queryIndex);  
-				// 			}
-							
-				// 			if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
-				// 				fs.mkdirSync(urlInfo.newPath + '\\评论图');
-				// 			}
-							
-				// 			let outputPath = urlInfo.newPath + '\\评论图\\' + fileName;
-				// 			await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
-				// 		}
-				// 	}
-				// }
-				
 				//视频下载
 				if(this.settingArr.indexOf('video') > -1){
 					for(let j = 0; j < imgInfo.video.length; j++){
@@ -2137,13 +2113,21 @@
 					(async () => {
 						try{
 							const redBrowser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
-								userDataDir: os.tmpdir() + separator + 'chrome-data-capture-jd', 
+								executablePath: this.initPath(),
+								args: ['--window-size=1280,800'],
+								userDataDir: os.tmpdir() + separator + 'chrome-data-capture'
 							});
 							const page = await redBrowser.newPage();
-							let testUrl = 'https://www.xiaohongshu.com';
-							await page.goto(testUrl, {waitUntil : 'networkidle2'});
+							await page.setViewport({ width: 1280, height: 800 });
 							
+							await page.evaluateOnNewDocument(() => {
+							    const newProto = navigator.__proto__;
+								delete newProto.webdriver;
+								navigator.__proto__ = newProto;
+							});
+							
+							let testUrl = "https://www.xiaohongshu.com";
+							await page.goto(testUrl, {waitUntil : 'networkidle2'});
 							let loginContainer = await page.$$('.login-container');
 							let loginBtn = await page.$$('#login-btn');
 							if(loginContainer.length > 0 || loginBtn.length > 0){
@@ -2156,6 +2140,7 @@
 							this.checkLoading = false;
 							redBrowser.close();
 						}catch(e){
+							this.checkLoading = false;
 							reject(3);
 							this.showError(e);
 						}
@@ -2173,7 +2158,8 @@
 							urlInfo.num = 0;
 							puppeteer.use(StealthPlugin());
 							const browser = await puppeteer.launch({
-								executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
+								headless: false,
+								executablePath: this.initPath(),
 								userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
 								args: [
 									'--start-maximized',
@@ -2463,6 +2449,8 @@
 					str = '权限受限,请以管理员权限运行软件!-5';
 				}else if(e.toString().indexOf('browser has disconnected') > -1){
 					str = '浏览器断开链接!-6';
+				}else if(e.toString().indexOf('Failed to launch the browser') > -1){
+					str = '请先关闭内置浏览器!-7';
 				}else{
 					str = e.toString();
 					//console.log(e);