From 9804d5c2a938ab15bf828fbc8ac2a9e7890ac452 Mon Sep 17 00:00:00 2001 From: duan602728596 Date: Tue, 14 May 2024 19:43:13 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/WebSocket2/Websocket2.pug | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/qqtools/src/components/basic/WebSocket2/Websocket2.pug b/packages/qqtools/src/components/basic/WebSocket2/Websocket2.pug index 205ba573..0ac46d0c 100644 --- a/packages/qqtools/src/components/basic/WebSocket2/Websocket2.pug +++ b/packages/qqtools/src/components/basic/WebSocket2/Websocket2.pug @@ -3,6 +3,20 @@ script. * Fix Pocket 48's verification problem for UA and client-type. */ (function() { + function objectSome(obj, callback) { + let result = false; + + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + result = callback(key, obj[key]); + + if (result) break; + } + } + + return result; + } + globalThis.WebSocket2 = WebSocket; WebSocket2.prototype.$_SEND = WebSocket2.prototype.send; @@ -16,10 +30,15 @@ script. data = JSON.parse(message); } catch {} - if (data && data?.SER === 1 && data?.Q?.[0]?.v) { - data.Q[0].v['3'] = 2; - data.Q[0].v['42'] = 'PocketFans201807/24020203'; - arguments[0] = `3:::${ JSON.stringify(data) }`; + if (data && data?.SER === 1 && data?.Q?.length) { + for (const Q of data.Q) { + if (/Property/i.test(Q.t) && Q.v && objectSome(Q.v, (k, v) => /Electron/i.test(v))) { + Q.v['3'] = 2; + Q.v['42'] = 'PocketFans201807/24020203'; + arguments[0] = `3:::${JSON.stringify(data)}`; + break; + } + } } }