From c5a6d8fc532cc2bd43e1ce7dc6eb0f89f22cc353 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Wed, 22 Aug 2018 17:42:02 +0300 Subject: [PATCH] Add current url detection --- manifest.json | 17 +++++++---------- postify.js | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/manifest.json b/manifest.json index b5d414c..0fae2c4 100644 --- a/manifest.json +++ b/manifest.json @@ -9,18 +9,15 @@ "strict_min_version": "45.0" } }, - "content_scripts": [ - { - "matches": [ - "*://*.mozilla.org/*" - ], - "js": [ - "postify.js" - ] - } + "permissions": [ + "activeTab", + "tabs" ], + "background": { + "scripts": ["postify.js"] + }, "browser_action": { "default_icon": "icons/postify-32.png", - "default_title": "Beastify" + "default_title": "Postify" } } \ No newline at end of file diff --git a/postify.js b/postify.js index 59627ae..040b240 100644 --- a/postify.js +++ b/postify.js @@ -1 +1,17 @@ -console.log('Yeah!') \ No newline at end of file +console.log('Load!'); + +function onGot(tabInfo) { + var tab = tabInfo[0]; + var url = tab.url; + console.log(url); +} + +function onError(error) { + console.log(`Error: ${error}`); +} + +function sendCurrentUrl() { + browser.tabs.query({currentWindow: true, active: true}).then(onGot, onError); +} + +browser.browserAction.onClicked.addListener(sendCurrentUrl);