Skip to content

Commit

Permalink
add context-menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
grmat committed May 22, 2018
1 parent c84b56c commit 80c88ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/_locales/de/messages.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"actionName": {
"message": "öffnen mit...",
"message": "abspielen mit...",
"description": "Action name for tooltips"
}
}
30 changes: 26 additions & 4 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,34 @@
* Hand the URL of the current tab over to the content script.
* TODO: user feedback for 'bad' URLs
*/
function invoke(tab) {
// console.log(tab.url);
browser.tabs.sendMessage(tab.id, {url: tab.url});
function invoke(info, tab) {
var url = tab.url;
if (info) {
url = info.linkUrl;
}
console.log("play-with attempting to play url " + url);
browser.tabs.sendMessage(tab.id, {url: url});
}

/*
* Create the context menu for links.
*/
browser.contextMenus.create({
id: "play-with",
title: browser.i18n.getMessage("actionName"),
contexts: ["all"]
});

/*
* Register listener for the button.
*/
browser.browserAction.onClicked.addListener(invoke);
browser.browserAction.onClicked.addListener((tab) => {
invoke(null, tab);
});

/*
* Register listener for the context menu.
*/
browser.contextMenus.onClicked.addListener((info, tab) => {
invoke(info, tab);
});
7 changes: 5 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "Play media on current URL in external application.",
"manifest_version": 2,
"name": "play-with",
"version": "1.2.3",
"version": "1.3",
"default_locale": "en",

"background": {
Expand All @@ -14,7 +14,7 @@
"js": ["play.js"]
}],

"permissions": ["activeTab"],
"permissions": ["activeTab", "contextMenus"],

"browser_action": {
"browser_style": true,
Expand All @@ -25,5 +25,8 @@
"dark": "icons/play-16-dark.svg",
"size": 16
}]
},
"icons": {
"16": "icons/play-16.svg"
}
}

0 comments on commit 80c88ab

Please sign in to comment.