Skip to content

Commit

Permalink
version 0.12: "page" context, %%TAB-{URL,TITLE}%% keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
DB committed Mar 30, 2018
1 parent 770b509 commit 53e364a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
}
]
}
Expand All @@ -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

Expand Down
28 changes: 8 additions & 20 deletions addon/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
5 changes: 3 additions & 2 deletions addon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
Expand All @@ -21,7 +21,8 @@
"permissions": [
"menus",
"nativeMessaging",
"storage"
"storage",
"tabs"
],
"icons": {
"16": "icons/runwith-16.png",
Expand Down
2 changes: 1 addition & 1 deletion addon/settings/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function createTableRow(data){

var contexts = [ 'link', 'selection', 'image' ];
var contexts = [ 'link', 'selection', 'image', 'page' ];

var tr = document.createElement('tr');

Expand Down

0 comments on commit 53e364a

Please sign in to comment.