shaarli-web-extension/background.js

25 lines
627 B
JavaScript
Raw Normal View History

2017-11-18 17:05:28 -08:00
/**
* 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) => {
const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`;
browser.windows.create({
url: shareUrl,
type: 'popup',
allowScriptsToClose: true,
});
});
});
}
browser.browserAction.onClicked.addListener(shareCurrentTab);