diff --git a/inject.js b/inject.js index 58b4304..61d7ee7 100644 --- a/inject.js +++ b/inject.js @@ -339,7 +339,6 @@ function make_domhooker_funcs(){ return ret.join('') } -var script = document.createElement('script'); var hookers = [ "config-hook-global", "config-hook-test", @@ -379,15 +378,6 @@ function add_config_hook(input){ } add_config_hook(getsets) 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){ var script = document.createElement("script"); @@ -399,8 +389,9 @@ function inject_script(code){ (head || document.body).appendChild( script ); (head || document.body).removeChild( script ); } -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){ - var key = Object.keys(request)[0] - var val = request[key] - inject_script(`window.globalConfig['${key}']=${val}`) -}) \ No newline at end of file + +chrome.storage.local.get(hookers, function (result) { + var replacer_injectfunc = (injectfunc + '').replace('$domobj_placeholder', make_domhooker_funcs()) + inject_script(`(${replacer_injectfunc})(${JSON.stringify(result)},window)`); +}) + diff --git a/popup.js b/popup.js index c378d9c..eded867 100644 --- a/popup.js +++ b/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){ chrome.storage.local.get([v.dataset.key], function (result) { if (v.type == 'checkbox'){ @@ -19,7 +8,6 @@ document.querySelectorAll("input").forEach(function(v){ } }) v.addEventListener("change", function (e) { - sendMessageToContentScript({[e.target.dataset.key]: e.target.checked}) if (v.type == 'checkbox'){ chrome.storage.local.set({ [e.target.dataset.key]: e.target.checked