From a8683092faed57ed46ea1f3c93335c828e240de9 Mon Sep 17 00:00:00 2001 From: ZHAO Hong Date: Thu, 18 Mar 2021 13:53:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=AD=A3IP/=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome/js/popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/js/popup.js b/chrome/js/popup.js index d492578..e95e429 100644 --- a/chrome/js/popup.js +++ b/chrome/js/popup.js @@ -150,7 +150,7 @@ function save() { viewStatusNotic(status); return false; } - if (!ipOk || !domainOk) { + if (!ipOk && !domainOk) { alert('不是合法的 IP 地址或域名'); var status = 'error'; viewStatusNotic(status); From 50f3aaeed78ba58a39486e6af6d365b712b0630b Mon Sep 17 00:00:00 2001 From: ZHAO Hong Date: Thu, 18 Mar 2021 13:55:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=9C=A8=E9=A1=B5=E9=9D=A2=E8=84=9A=E6=9C=AC=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=B9=8B=E5=89=8D=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome/js/background.js | 60 ++++++++++++++++++++++++++++++++++++++--- chrome/js/log.js | 11 +++++++- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/chrome/js/background.js b/chrome/js/background.js index 18e05a4..2514e66 100644 --- a/chrome/js/background.js +++ b/chrome/js/background.js @@ -7,6 +7,57 @@ var websocket_timeout = 0; var limit_connect = 1; // 断线重连次数 var count = 0; // 重连计数 +function Emitter() { + this.loggers = []; + this.fns_map = {}; +} + +Emitter.prototype.emit = function(logger, fn) { + if(this.loggers.indexOf(logger) >= 0) { + fn(); + } else { + if(!this.fns_map[logger]) { + this.fns_map[logger] = []; + } + this.fns_map[logger].push(fn); + } +}; + +Emitter.prototype.setLogger = function(logger) { + this.loggers.push(logger); + if(this.fns_map[logger]) { + this.fns_map[logger].forEach(function(fn){fn()}); + } + this.fns_map[logger] = []; +} + +Emitter.prototype.unsetLogger = function(logger) { + var loggers = []; + this.loggers.forEach(function(value){ + if(value != logger) { + loggers.push(value); + } + }); + this.loggers = loggers; +} + +var evt = new Emitter(); + +chrome.extension.onMessage.addListener( + function(method, sender, sendResponse) { + switch(method) { + case 'setLogger': + evt.setLogger(sender.tab.id); + break; + case 'unsetLogger': + evt.unsetLogger(sender.tab.id); + break; + default: + break; + } + } +); + function ws_init() { if (websocket) { //避免重复监听 @@ -103,6 +154,7 @@ function ws_init() { return; } var client_id = localStorage.getItem("client_id"); + //判断是否有强制日志 if (client_id && data.force_client_id == client_id) { //将强制日志输出到当前的tab页 @@ -110,10 +162,10 @@ function ws_init() { function(tabArray) { if (tabArray && tabArray[0]) { //延迟保证日志每次都能记录 - setTimeout(function() { + evt.emit(tabArray[0].id, function(){ check_error(); chrome.tabs.sendMessage(tabArray[0].id, data.logs); - }, 100); + }); } } ); @@ -125,10 +177,10 @@ function ws_init() { return; } //延迟保证日志每次都能记录 - setTimeout(function() { + evt.emit(parseInt(data.tabid), function(){ check_error(); chrome.tabs.sendMessage(parseInt(data.tabid), data.logs); - }, 100); + }); }; } diff --git a/chrome/js/log.js b/chrome/js/log.js index c10e558..e798668 100644 --- a/chrome/js/log.js +++ b/chrome/js/log.js @@ -2,6 +2,13 @@ * github: https://github.com/luofei614/SocketLog * @author luofei614 */ + +document.addEventListener("DOMContentLoaded", function(){ + document.body.onbeforeunload = function() { + chrome.extension.sendMessage('unsetLogger'); + } +}, true); + chrome.extension.onMessage.addListener( function(logs) { if ("object" != typeof logs) { @@ -24,4 +31,6 @@ chrome.extension.onMessage.addListener( } }); } -); \ No newline at end of file +); + +chrome.extension.sendMessage('setLogger'); \ No newline at end of file From dc0ce16fb63c08b05cbdf33f93662daeceef258b Mon Sep 17 00:00:00 2001 From: ZHAO Hong Date: Fri, 19 Mar 2021 10:53:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=85=B3=E9=97=AD=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8B=E4=B8=8D=E4=BF=AE=E6=94=B9requestHeaders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome/js/background.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/chrome/js/background.js b/chrome/js/background.js index 2514e66..1ddf31c 100644 --- a/chrome/js/background.js +++ b/chrome/js/background.js @@ -161,8 +161,7 @@ function ws_init() { chrome.tabs.query({ currentWindow: true, active: true }, function(tabArray) { if (tabArray && tabArray[0]) { - //延迟保证日志每次都能记录 - evt.emit(tabArray[0].id, function(){ + //延迟保证日志每次都能记录evt.emit(tabArray[0].id, function(){ check_error(); chrome.tabs.sendMessage(tabArray[0].id, data.logs); }); @@ -176,8 +175,7 @@ function ws_init() { //不是当前用户的日志不显示。 return; } - //延迟保证日志每次都能记录 - evt.emit(parseInt(data.tabid), function(){ + //延迟保证日志每次都能记录evt.emit(parseInt(data.tabid), function(){ check_error(); chrome.tabs.sendMessage(parseInt(data.tabid), data.logs); }); @@ -213,6 +211,11 @@ chrome.webRequest.onBeforeSendHeaders.addListener( function(details) { var header = "tabid=" + details.tabId; var client_id = localStorage.getItem("client_id"); + var open = localStorage.getItem("open"); + + if(open == 'false' || open == null) { + return { requestHeaders: details.requestHeaders }; + } if (!client_id) { client_id = "";