This commit is contained in:
cilame 2021-09-26 23:34:49 +08:00
parent 73b85cf3de
commit 29c464bfe0
5 changed files with 151 additions and 45 deletions

View File

@ -1,2 +1 @@
// background.js
// background.js

157
inject.js

File diff suppressed because one or more lines are too long

View File

@ -2,13 +2,13 @@
"name": "v_jstools",
"version": "0.0.0",
"description": "v_jstools js hook工具",
"permissions": ["storage", "activeTab", "tabs", "debugger", "storage"],
"permissions": ["storage", "activeTab", "tabs", "debugger", "storage", "extension", "scripting"],
"browser_action": {
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"],
"persistent": false
"persistent": true
},
"content_scripts": [
{

View File

@ -9,6 +9,8 @@
<body style="width: 600px;">
<label ><input type="checkbox" data-key="config-hook-test">test</label>
<br/>
<label ><input type="checkbox" data-key="config-hook-console">hook-console</label>
<br/>
<label ><input type="checkbox" data-key="config-hook-Function">hook-Function</label>
<br/>
<label ><input type="checkbox" data-key="config-hook-eval">hook-eval</label>
@ -37,8 +39,8 @@
<br/>
<label ><input type="checkbox" data-key="config-hook-unescape">hook-unescape</label>
<br/>
<label ><input type="checkbox" data-key="config-hook-domobj">hook-domobj</label>
<br/>

View File

@ -1,10 +1,22 @@
// var background = chrome.extension.getBackgroundPage();
// var gettabid = background.gettabid
function sendMessageToContentScript(message, callback){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, message, function(response){
if(callback) callback(response);
});
});
}
document.querySelectorAll("input").forEach(function(v){
chrome.storage.sync.get([v.dataset.key], function (result) {
v.checked = result[v.dataset.key];
})
v.addEventListener("change", function (e) {
chrome.storage.sync.set({
[e.target.dataset.key]: e.target.checked
})
chrome.storage.sync.get([v.dataset.key], function (result) {
v.checked = result[v.dataset.key];
})
v.addEventListener("change", function (e) {
sendMessageToContentScript({[e.target.dataset.key]: e.target.checked})
chrome.storage.sync.set({
[e.target.dataset.key]: e.target.checked
})
})
})