From a5247c571d1f06ce98e963e15d28e390dc422d66 Mon Sep 17 00:00:00 2001 From: cilame Date: Tue, 22 Nov 2022 21:19:28 +0800 Subject: [PATCH] add --- background.js | 25 +++++++++++++++++-------- options.js | 23 ++++++++++++++++++----- popup.js | 25 ++++++++++++++++++------- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/background.js b/background.js index bd3947b..d1dc7ab 100644 --- a/background.js +++ b/background.js @@ -369,14 +369,23 @@ function getLocalFileUrl(url) { return ("data:" + (typeMap[type] || typeMap.txt) + ";charset=utf-8;base64," + base64); } -chrome.storage.local.get(['config-hook-global'], function(e){ - chrome.browserAction.setBadgeBackgroundColor({color: '#BC1717'}); - if (e['config-hook-global']){ - chrome.browserAction.setBadgeText({text: 'v'}); - }else{ - chrome.browserAction.setBadgeText({text: ''}); - } -}) +function sub_logger(){ + chrome.storage.local.get([ + 'config-hook-global', + 'config-myinject_toggle', + ], function(e){ + chrome.browserAction.setBadgeBackgroundColor({color: '#BC1717'}); + var info = '' + if (e['config-hook-global']){ + info += 'v' + } + if (e['config-myinject_toggle']){ + info += 'i' + } + chrome.browserAction.setBadgeText({text: info}); + }) +} +sub_logger() chrome.webRequest.onBeforeRequest.addListener(function (details) { var url = details.url; diff --git a/options.js b/options.js index 3e4274e..996550f 100644 --- a/options.js +++ b/options.js @@ -433,6 +433,23 @@ _mk_html(funcs_0, 'funcs_0', 0) _mk_html(getsets_1, 'getsets_1', 1) _mk_html(funcs_1, 'funcs_1', 1) +function sub_logger(){ + chrome.storage.local.get([ + 'config-hook-global', + 'config-myinject_toggle', + ], function(e){ + chrome.browserAction.setBadgeBackgroundColor({color: '#BC1717'}); + var info = '' + if (e['config-hook-global']){ + info += 'v' + } + if (e['config-myinject_toggle']){ + info += 'i' + } + chrome.browserAction.setBadgeText({text: info}); + }) +} + document.querySelectorAll("input").forEach(function(v){ chrome.storage.local.get([v.dataset.key], function (result) { if (v.type == 'checkbox'){ @@ -445,14 +462,10 @@ document.querySelectorAll("input").forEach(function(v){ v.addEventListener("change", function (e) { if (v.type == 'checkbox'){ // console.log(e.target.dataset.key, e.target.checked) - if (e.target.dataset.key == 'config-hook-global' && e.target.checked){ - chrome.browserAction.setBadgeText({text: 'v'}); - }else{ - chrome.browserAction.setBadgeText({text: ''}); - } chrome.storage.local.set({ [e.target.dataset.key]: e.target.checked }) + sub_logger() } if (v.type == 'text' || v.type == 'password'){ chrome.storage.local.set({ diff --git a/popup.js b/popup.js index 60f5047..2544e2a 100644 --- a/popup.js +++ b/popup.js @@ -1,3 +1,20 @@ +function sub_logger(){ + chrome.storage.local.get([ + 'config-hook-global', + 'config-myinject_toggle', + ], function(e){ + chrome.browserAction.setBadgeBackgroundColor({color: '#BC1717'}); + var info = '' + if (e['config-hook-global']){ + info += 'v' + } + if (e['config-myinject_toggle']){ + info += 'i' + } + chrome.browserAction.setBadgeText({text: info}); + }) +} + document.querySelectorAll("input").forEach(function(v){ chrome.storage.local.get([v.dataset.key], function (result) { if (v.type == 'checkbox'){ @@ -10,13 +27,6 @@ document.querySelectorAll("input").forEach(function(v){ v.addEventListener("change", function (e) { if (v.type == 'checkbox'){ // console.log(e.target.dataset.key, e.target.checked) - if (e.target.dataset.key == 'config-hook-global'){ - if (e.target.checked){ - chrome.browserAction.setBadgeText({text: 'v'}); - }else{ - chrome.browserAction.setBadgeText({text: ''}); - } - } if (e.target.dataset.key == 'config-hook-log-toggle'){ chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ chrome.tabs.sendMessage(tabs[0].id, {action: {type:'logtoggle', info: 'logtoggle'}}, function(response) {}); @@ -25,6 +35,7 @@ document.querySelectorAll("input").forEach(function(v){ chrome.storage.local.set({ [e.target.dataset.key]: e.target.checked }) + sub_logger() } if (v.type == 'text'){ chrome.storage.local.set({