From 2ec418479b3d85c1eeb14ddf345f8334814907e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 17 May 2021 14:42:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BD=91=E7=BB=9C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 ++++--- src/js/app.js | 6 ++++++ src/main.js | 33 ++++++++------------------------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 07e8155..5a45e6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "io.yutent.gaystat", - "version": "2.1.3", + "version": "2.2.0", "description": "搞基数据", "main": "src/main.js", "scripts": { @@ -26,7 +26,7 @@ "version": "11.0.4", "mirror": "https://npm.taobao.org/mirrors/electron/" }, - "files": ["src/**/*", "node_modules/iofs/*"], + "files": ["src/**/*", "node_modules/iofs/*", "node_modules/node-fetch/*"], "mac": { "category": "public.app-category.developer-tools", "target": "dmg", @@ -39,6 +39,7 @@ "electron-builder": "^22.1.0" }, "dependencies": { - "iofs": "^1.3.2" + "iofs": "^1.5.2", + "node-fetch": "^2.6.1" } } diff --git a/src/js/app.js b/src/js/app.js index 35653d4..97f4fcb 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -144,6 +144,7 @@ Anot({ 'fetch', `https://fundgz.1234567.com.cn/js/${id}.js` ) + return getJsonp(res) }, @@ -201,6 +202,11 @@ Anot({ let info = this.getGayStat(it.code) let time, needUpdate + if (!info) { + console.log(it) + continue + } + it.cm = +info.gsz it.cp = +info.gszzl diff --git a/src/main.js b/src/main.js index 40fd494..46f7f04 100644 --- a/src/main.js +++ b/src/main.js @@ -14,6 +14,7 @@ const { } = require('electron') const path = require('path') const fs = require('iofs') +const fetch = require('node-fetch') const { createMainWindow, createFloatWindow } = require('./tools/window') const createMenu = require('./tools/menu') @@ -35,29 +36,6 @@ const ROOT = __dirname var timer -function fetch(url) { - return new Promise((y, n) => { - var conn = net.request(url) - var r = [] - - conn.on('response', res => { - res.on('data', c => { - r.push(c) - }) - - res.on('end', _ => { - y(Buffer.concat(r).toString()) - }) - }) - - conn.on('error', e => { - n(e) - }) - - conn.end() - }) -} - function ring() { var n = 5 var t = setInterval(() => { @@ -120,9 +98,14 @@ app.once('ready', () => { ipcMain.on('app', (ev, conn) => { switch (conn.type) { case 'fetch': - fetch(conn.data).then(r => { - ev.returnValue = r + fetch(conn.data, { + headers: { + 'user-agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36' + } }) + .then(r => r.text()) + .then(r => (ev.returnValue = r)) break case 'notify':