From b94b88e6898492e2b1b6632bfb941a560f586f73 Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Sun, 26 Nov 2017 23:22:20 +0100 Subject: [PATCH 1/7] Fix share current tab function to handle given tab in parameter --- src/background.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/background.js b/src/background.js index 3227082..9c61344 100644 --- a/src/background.js +++ b/src/background.js @@ -17,21 +17,16 @@ function openInPopup(url) { * Share Current Tab * @return {void} - */ -function shareCurrentTab() { - browser.tabs.query({ - active: true, - currentWindow: true, - }).then((tabs) => { - const url = tabs[0].url; - const title = tabs[0].title || url; - browser.storage.local.get('url').then((storage) => { - if(storage.url){ - const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`; - openInPopup(shareUrl); - }else{ - browser.runtime.openOptionsPage() - } - }); +function shareCurrentTab(tab) { + const url = tab.url; + const title = tab.title || url; + browser.storage.local.get('url').then((storage) => { + if(!storage.url){ + browser.runtime.openOptionsPage(); + return; + } + const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`; + openInPopup(shareUrl); }); } From ff775a9c7d378d705ba5e5ce0110244a94f9db0e Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Sun, 26 Nov 2017 23:40:29 +0100 Subject: [PATCH 2/7] Fix storage init and usage --- src/background.js | 2 +- src/storage.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index 9c61344..e9e3b61 100644 --- a/src/background.js +++ b/src/background.js @@ -20,7 +20,7 @@ function openInPopup(url) { function shareCurrentTab(tab) { const url = tab.url; const title = tab.title || url; - browser.storage.local.get('url').then((storage) => { + browser.storage.local.get().then((storage) => { if(!storage.url){ browser.runtime.openOptionsPage(); return; diff --git a/src/storage.js b/src/storage.js index 20ae517..942fd9b 100644 --- a/src/storage.js +++ b/src/storage.js @@ -18,7 +18,7 @@ If we don't, then store the default settings. */ function checkStoredSettings(storedSettings) { if (!storedSettings.storage) { - browser.storage.local.set({storage}); + browser.storage.local.set(storage); } } From 75b40ece5235e08ffef3ae136ea8ea522b5fb7e1 Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Sun, 26 Nov 2017 23:24:10 +0100 Subject: [PATCH 3/7] PageAction: init in config, storage and background click listener --- manifest.json | 5 +++++ src/background.js | 4 ++++ src/storage.js | 1 + 3 files changed, 10 insertions(+) diff --git a/manifest.json b/manifest.json index b70501c..0eb1e34 100644 --- a/manifest.json +++ b/manifest.json @@ -20,5 +20,10 @@ "browser_action": { "default_icon": "resources/icons/icon-24.png", "default_title": "Share" + }, + "page_action": { + "browser_style": false, + "default_icon": "resources/icons/icon-24.png", + "default_title": "Share" } } diff --git a/src/background.js b/src/background.js index e9e3b61..4ec9323 100644 --- a/src/background.js +++ b/src/background.js @@ -30,4 +30,8 @@ function shareCurrentTab(tab) { }); } +/* +Listeners + */ browser.browserAction.onClicked.addListener(shareCurrentTab); +browser.pageAction.onClicked.addListener(shareCurrentTab); diff --git a/src/storage.js b/src/storage.js index 942fd9b..238a76a 100644 --- a/src/storage.js +++ b/src/storage.js @@ -3,6 +3,7 @@ Default settings. Initialize storage to these values. */ var storage = { url: '', + pageAction: false, } /* From 56131220a2be29e856286eb49f0f9ea7c7ddf351 Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Sun, 26 Nov 2017 23:54:55 +0100 Subject: [PATCH 4/7] PageAction: display on init and tab switch if activated --- src/background.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/background.js b/src/background.js index 4ec9323..1e4d8c7 100644 --- a/src/background.js +++ b/src/background.js @@ -30,8 +30,38 @@ function shareCurrentTab(tab) { }); } +/** + * Show Page Action on current page if activated + * @param {string} tabId - Current tab id + * @return {void} - + */ +function showPageAction(tabId){ + browser.storage.local.get().then((storage) => { + if(storage.pageAction){ + browser.pageAction.show(tabId); + } + }); +} + +/** + * Show page action with given active information + * @param {object} activeInfo - + * @return {void} - + */ +function tabActivation(activeInfo){ + showPageAction(activeInfo.tabId); +} + +/* +Initialize + */ +browser.tabs.query({active: true, currentWindow: true}).then((tabs) => { + showPageAction(tabs[0].id); +}); + /* Listeners */ +browser.tabs.onActivated.addListener(tabActivation); browser.browserAction.onClicked.addListener(shareCurrentTab); browser.pageAction.onClicked.addListener(shareCurrentTab); From 308d9585783d793aad34f04fe2c89e96149510cb Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Mon, 27 Nov 2017 23:04:10 +0100 Subject: [PATCH 5/7] PageAction: create settings input --- src/background.js | 4 +--- src/options/options.html | 1 + src/options/options.js | 42 ++++++++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/background.js b/src/background.js index 1e4d8c7..bc5dfe8 100644 --- a/src/background.js +++ b/src/background.js @@ -37,9 +37,7 @@ function shareCurrentTab(tab) { */ function showPageAction(tabId){ browser.storage.local.get().then((storage) => { - if(storage.pageAction){ - browser.pageAction.show(tabId); - } + storage.pageAction ? browser.pageAction.show(tabId) : browser.pageAction.hide(tabId); }); } diff --git a/src/options/options.html b/src/options/options.html index 681b6de..20aeb68 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -9,6 +9,7 @@
URL:
+
Address Bar:
diff --git a/src/options/options.js b/src/options/options.js index 481e2f5..e61677b 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -1,26 +1,40 @@ -/* -Store options UI using browser.storage.local. -*/ +/** + * Store options UI using browser.storage.local. + * @return {void} - + */ function storeSettings() { - const url = document.querySelector("#url"); - // console.log('storeSettings url'); - // console.log(url); - browser.storage.local.set({ - url: url.value, - }); + const settings = { + url: document.querySelector("#url").value, + pageAction: document.querySelector("#pageAction").checked, + }; + // console.log('storeSettings settings'); + // console.log(settings); + browser.storage.local.set(settings); } -/* -Update the options UI with the settings values retrieved from storage, -or the default settings if the stored settings are empty. -*/ +/** + * Update the options UI with the settings values retrieved from storage, + * or the default settings if the stored settings are empty. + * @param {object} restoredSettings - + * @return {void} - + */ function updateUI(restoredSettings) { const url = document.querySelector("#url"); + url.value = restoredSettings.url; // console.log('restoredSettings url'); // console.log(url); - url.value = restoredSettings.url || ""; + + const pageAction = document.querySelector("#pageAction"); + pageAction.checked = restoredSettings.pageAction; + // console.log('restoredSettings pageAction'); + // console.log(pageAction); } +/** + * Display on error + * @param {object} error - + * @return {void} - + */ function onError(e) { console.error(e); } From a2c236b42171c510fe548cf7bb59e9965986a67d Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Tue, 28 Nov 2017 00:15:40 +0100 Subject: [PATCH 6/7] Settings: better looking form --- src/options/options.css | 78 +++++++++++++++++++++++++++++++++------- src/options/options.html | 22 +++++++++--- 2 files changed, 83 insertions(+), 17 deletions(-) diff --git a/src/options/options.css b/src/options/options.css index 19f36be..a2a80d2 100644 --- a/src/options/options.css +++ b/src/options/options.css @@ -1,18 +1,70 @@ - -body { - width: 25em; - font-family: "Open Sans Light", sans-serif; - font-size: 0.9em; - font-weight: 300; +.main{ + font: 14px sans-serif; } -input#url { - margin: 0.5em; - width: 50em; - height: 2.5em; +.main .row{ + text-align: left; } -input { - width: 20em; - height: 2.5em; +/* The form title */ + +.main .row > label span{ + color: #1a1a1a; + width: 100em; + vertical-align: center; + padding-left: 5px; + padding-right: 30px; } + +.main input{ + color: #1a1a12; + width: 31em; + box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.08); + padding: 5px; + border: 1px solid #dbdbdb; +} + +.main input[type=checkbox]{ + box-shadow: none; + width: auto; + margin-top: 13px; +} + +.main button{ + display: block; + border-radius: 2px; + font-weight: bold; + padding: 8px 22px; + margin-left: 10em; +} + +/* Making the form responsive. Remove this media query + if you don't need the form to work on mobile devices. */ + +/*@media (max-width: 600px) { + + .main{ + padding: 30px; + max-width: 480px; + } + + .main .row{ + max-width: 300px; + margin: 25px auto; + text-align: left; + } + + .main .row > label span{ + display: block; + text-align: left; + padding: 0 0 15px; + } + + .main input[type=checkbox]{ + margin-top:0; + } + + .main button{ + margin: 0; + } +}*/ diff --git a/src/options/options.html b/src/options/options.html index 20aeb68..1c6b7ef 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -7,10 +7,24 @@ - -
URL:
-
Address Bar:
- +
+
+ +
+
+ +
+
+   + +
+
From 09ffed5cbcc117f48df3a7cc340aa151cbe3c937 Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Tue, 28 Nov 2017 13:39:03 +0100 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bac8beb..214cefc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## Changed +- Improved share current tab function +- Improved browser storage initialilisation +- Better looking settings form + +## Added +- New share button in address bar + Share button in address bar can be enabled in settings, disabled by default + ## [0.0.2][] - 2017-11-23 - Create extension settings - Allow to set your Shaarli URL