mirror of
https://git.mirrors.martin98.com/https://github.com/cilame/v_jstools
synced 2025-07-05 03:45:12 +08:00
add
This commit is contained in:
parent
fca47bf425
commit
f19f9d1b3d
19
inject.js
19
inject.js
@ -339,7 +339,6 @@ function make_domhooker_funcs(){
|
|||||||
return ret.join('')
|
return ret.join('')
|
||||||
}
|
}
|
||||||
|
|
||||||
var script = document.createElement('script');
|
|
||||||
var hookers = [
|
var hookers = [
|
||||||
"config-hook-global",
|
"config-hook-global",
|
||||||
"config-hook-test",
|
"config-hook-test",
|
||||||
@ -379,15 +378,6 @@ function add_config_hook(input){
|
|||||||
}
|
}
|
||||||
add_config_hook(getsets)
|
add_config_hook(getsets)
|
||||||
add_config_hook(funcs)
|
add_config_hook(funcs)
|
||||||
chrome.storage.local.get(hookers, function (result) {
|
|
||||||
var replacer_injectfunc = (injectfunc + '').replace('$domobj_placeholder', make_domhooker_funcs())
|
|
||||||
script.text = `(${replacer_injectfunc})(${JSON.stringify(result)},window)`;
|
|
||||||
script.onload = function(){
|
|
||||||
script.parentNode.removeChild(script)
|
|
||||||
}
|
|
||||||
var scriptin = (document.head || document.documentElement)
|
|
||||||
scriptin.appendChild(script);
|
|
||||||
})
|
|
||||||
|
|
||||||
function inject_script(code){
|
function inject_script(code){
|
||||||
var script = document.createElement("script");
|
var script = document.createElement("script");
|
||||||
@ -399,8 +389,9 @@ function inject_script(code){
|
|||||||
(head || document.body).appendChild( script );
|
(head || document.body).appendChild( script );
|
||||||
(head || document.body).removeChild( script );
|
(head || document.body).removeChild( script );
|
||||||
}
|
}
|
||||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
|
|
||||||
var key = Object.keys(request)[0]
|
chrome.storage.local.get(hookers, function (result) {
|
||||||
var val = request[key]
|
var replacer_injectfunc = (injectfunc + '').replace('$domobj_placeholder', make_domhooker_funcs())
|
||||||
inject_script(`window.globalConfig['${key}']=${val}`)
|
inject_script(`(${replacer_injectfunc})(${JSON.stringify(result)},window)`);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
12
popup.js
12
popup.js
@ -1,14 +1,3 @@
|
|||||||
// 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){
|
document.querySelectorAll("input").forEach(function(v){
|
||||||
chrome.storage.local.get([v.dataset.key], function (result) {
|
chrome.storage.local.get([v.dataset.key], function (result) {
|
||||||
if (v.type == 'checkbox'){
|
if (v.type == 'checkbox'){
|
||||||
@ -19,7 +8,6 @@ document.querySelectorAll("input").forEach(function(v){
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
v.addEventListener("change", function (e) {
|
v.addEventListener("change", function (e) {
|
||||||
sendMessageToContentScript({[e.target.dataset.key]: e.target.checked})
|
|
||||||
if (v.type == 'checkbox'){
|
if (v.type == 'checkbox'){
|
||||||
chrome.storage.local.set({
|
chrome.storage.local.set({
|
||||||
[e.target.dataset.key]: e.target.checked
|
[e.target.dataset.key]: e.target.checked
|
||||||
|
Loading…
x
Reference in New Issue
Block a user