From 4b0c115cd3b053ac9a9d3d204d88af602a0b87c0 Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Wed, 22 Nov 2017 14:21:30 +0100 Subject: [PATCH] Open add-on settings when url is not set --- src/background.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/background.js b/src/background.js index 0977326..85f14c1 100644 --- a/src/background.js +++ b/src/background.js @@ -1,3 +1,17 @@ + +/** + * Open the given url in a popup + * @param {string} url - + * @return {void} - + */ +function openInPopup(url) { + browser.windows.create({ + url, + type: 'popup', + allowScriptsToClose: true, + }); +} + /** * Share Current Tab * @return {void} - @@ -10,13 +24,12 @@ function shareCurrentTab() { const url = tabs[0].url; const title = tabs[0].title || url; browser.storage.local.get('url').then((storage) => { - const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`; - - browser.windows.create({ - url: shareUrl, - type: 'popup', - allowScriptsToClose: true, - }); + if(storage.url){ + const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`; + openInPopup(shareUrl); + }else{ + browser.runtime.openOptionsPage() + } }); }); }