diff --git a/bg.js b/bg.js new file mode 100644 index 0000000..585e2ef --- /dev/null +++ b/bg.js @@ -0,0 +1,7 @@ +chrome.runtime.onConnect.addListener(function(port){ + port.onMessage.addListener(function(request) { + console.log('バックグラウンドアンドページに出力'); + + chrome.tabs.create({url:request.url}) + }); +}); diff --git a/main.js b/main.js index e7d200f..f900b59 100644 --- a/main.js +++ b/main.js @@ -1 +1,9 @@ -window.alert('Hello, World'); +window.addEventListener('keydown', function(evt){ + let port = chrome.extension.connect(); + + switch ( evt.keyCode ){ + case 65: // 'a' + port.postMessage({'url':'https://www.google.co.jp'}); + break; + } +}); diff --git a/manifest.json b/manifest.json index fe1cfaa..5914c09 100644 --- a/manifest.json +++ b/manifest.json @@ -2,9 +2,14 @@ "name": "sample extension", "description": "sample code", "manifest_version": 2, + "background": { + "scripts": [ "bg.js" ], + "persistent": false + }, "content_scripts": [ { "matches": [ "http://*/*", "https://*/*" ], "js": [ "main.js" ] } ], + "permissions": [ "http://*/*", "https://*/*", "tabs" ], "version": "1.0.0.0" }