diff --git a/README.md b/README.md index 0e29f75..524c606 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ For each configuration line specify: - The menu text for the entry (will be shown when you right-click) - The NM host to use. Use **`runwith`** unless you know what you're doing. -- The context in which you want the menu entry to appear (link, selection, image) -- The actual command you want to run. **Separate words using commas**. Use the following special words to indicate the current link, selected text or image URL respectively: **`%%LINK%%`**, **`%%SELECTION%%`**, **`%%IMAGE%%`** (only the one appropriate for the context). At runtime, the **`%%WORD%%`** will be replaced with the actual link, selection or image URL value. +- The context in which you want the menu entry to appear: `link`, `selection`, `image`, `page`. `page` applies when none of the more-specific ones does. +- The actual command you want to run. **Separate words using commas**. Use the following special words to indicate the current link, selected text or image URL respectively: **`%%LINK%%`**, **`%%SELECTION%%`**, **`%%IMAGE%%`** (only the one appropriate for the context). At runtime, the **`%%WORD%%`** will be replaced with the actual link, selection or image URL value. Additionally, the **`%%TAB-URL%%`** and **`TAB-TITLE`** keywords are available in all contexts, and contain, as their name implies, the current tab's URL and title. - Whether to run the command through a shell. This is normally needed only if you have special shell characters in the command (redirections, pipes, etc), and shouldn't be normally required. - Whether you want the NM host program to wait for the command to finish or not. Unless you want to run graphical or detached commands, you should check this field. @@ -96,6 +96,20 @@ Save the following in `/tmp/config.json` and import it in RunWith configuration: ], "shell": false, "wait": true + }, + { + "id": "3", + "title": "Simple page command", + "nmhost": "runwith", + "contexts": [ + "page" + ], + "action": [ + "/tmp/test.sh", + "%%TAB-TITLE%%" + ], + "shell": false, + "wait": true } ] } @@ -104,7 +118,7 @@ Save the following in `/tmp/config.json` and import it in RunWith configuration: After importing, save the configuration. -Now go to a webpage, right-click on a link, selection or image, and you should see the corresponding RunWith menu entry. If you run it, you will see our `/tmp/test.sh` being run and writing its output to `/tmp/output.txt`. Of course this is just a silly example. +Now go to a webpage, right-click on a link, selection or image (or on any point in the page), and you should see the corresponding RunWith menu entry. If you run it, you will see our `/tmp/test.sh` being run and writing its output to `/tmp/output.txt`. Of course this is just a silly example. ## Detailed explanation diff --git a/addon/background.js b/addon/background.js index 491d8e7..fd7764b 100644 --- a/addon/background.js +++ b/addon/background.js @@ -24,29 +24,17 @@ function onNmError(error){ function actionFunc(action, nmhost, context, shell, wait, info, tab){ - var placeholder, value; - - switch(context){ - case "link": - placeholder = "%%LINK%%"; - value = info.linkUrl; - break; - - case "selection": - placeholder = "%%SELECTION%%"; - value = info.selectionText; - break; - - case "image": - placeholder = "%%IMAGE%%"; - value = info.srcUrl; - break; - } - var realAction = [] action.forEach(function(act){ - realAction.push(act.replace(placeholder, value)); + var word = act; + + word = word.replace('%%LINK%%', info.linkUrl || ""); + word = word.replace('%%SELECTION%%', info.selectionText || ""); + word = word.replace('%%IMAGE%%', info.srcUrl || ""); + word = word.replace('%%TAB-URL%%', tab.url || ""); + word = word.replace('%%TAB-TITLE%%', tab.title || ""); + realAction.push(word); }); var msg = { diff --git a/addon/manifest.json b/addon/manifest.json index d9cdb17..a0df7a1 100644 --- a/addon/manifest.json +++ b/addon/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "RunWith", "description": "Run external commands on contextual elements", - "version": "0.11", + "version": "0.12", "applications": { "gecko": { "id": "run@runwith.run", @@ -21,7 +21,8 @@ "permissions": [ "menus", "nativeMessaging", - "storage" + "storage", + "tabs" ], "icons": { "16": "icons/runwith-16.png", diff --git a/addon/settings/settings.js b/addon/settings/settings.js index ec0e7b2..4d819e5 100644 --- a/addon/settings/settings.js +++ b/addon/settings/settings.js @@ -1,6 +1,6 @@ function createTableRow(data){ - var contexts = [ 'link', 'selection', 'image' ]; + var contexts = [ 'link', 'selection', 'image', 'page' ]; var tr = document.createElement('tr');