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 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 3227082..bc5dfe8 100644 --- a/src/background.js +++ b/src/background.js @@ -17,22 +17,49 @@ 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().then((storage) => { + if(!storage.url){ + browser.runtime.openOptionsPage(); + return; + } + const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`; + openInPopup(shareUrl); }); } +/** + * 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) => { + storage.pageAction ? browser.pageAction.show(tabId) : browser.pageAction.hide(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); 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 681b6de..1c6b7ef 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -7,9 +7,24 @@
- -