Skip to content

Commit 53e364a

Browse files
author
DB
committed
version 0.12: "page" context, %%TAB-{URL,TITLE}%% keywords
1 parent 770b509 commit 53e364a

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ For each configuration line specify:
2424

2525
- The menu text for the entry (will be shown when you right-click)
2626
- The NM host to use. Use **`runwith`** unless you know what you're doing.
27-
- The context in which you want the menu entry to appear (link, selection, image)
28-
- 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.
27+
- 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.
28+
- 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.
2929
- 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.
3030
- 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.
3131

@@ -96,6 +96,20 @@ Save the following in `/tmp/config.json` and import it in RunWith configuration:
9696
],
9797
"shell": false,
9898
"wait": true
99+
},
100+
{
101+
"id": "3",
102+
"title": "Simple page command",
103+
"nmhost": "runwith",
104+
"contexts": [
105+
"page"
106+
],
107+
"action": [
108+
"/tmp/test.sh",
109+
"%%TAB-TITLE%%"
110+
],
111+
"shell": false,
112+
"wait": true
99113
}
100114
]
101115
}
@@ -104,7 +118,7 @@ Save the following in `/tmp/config.json` and import it in RunWith configuration:
104118

105119
After importing, save the configuration.
106120

107-
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.
121+
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.
108122

109123
## Detailed explanation
110124

addon/background.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,17 @@ function onNmError(error){
2424

2525
function actionFunc(action, nmhost, context, shell, wait, info, tab){
2626

27-
var placeholder, value;
28-
29-
switch(context){
30-
case "link":
31-
placeholder = "%%LINK%%";
32-
value = info.linkUrl;
33-
break;
34-
35-
case "selection":
36-
placeholder = "%%SELECTION%%";
37-
value = info.selectionText;
38-
break;
39-
40-
case "image":
41-
placeholder = "%%IMAGE%%";
42-
value = info.srcUrl;
43-
break;
44-
}
45-
4627
var realAction = []
4728

4829
action.forEach(function(act){
49-
realAction.push(act.replace(placeholder, value));
30+
var word = act;
31+
32+
word = word.replace('%%LINK%%', info.linkUrl || "");
33+
word = word.replace('%%SELECTION%%', info.selectionText || "");
34+
word = word.replace('%%IMAGE%%', info.srcUrl || "");
35+
word = word.replace('%%TAB-URL%%', tab.url || "");
36+
word = word.replace('%%TAB-TITLE%%', tab.title || "");
37+
realAction.push(word);
5038
});
5139

5240
var msg = {

addon/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "RunWith",
44
"description": "Run external commands on contextual elements",
5-
"version": "0.11",
5+
"version": "0.12",
66
"applications": {
77
"gecko": {
88
@@ -21,7 +21,8 @@
2121
"permissions": [
2222
"menus",
2323
"nativeMessaging",
24-
"storage"
24+
"storage",
25+
"tabs"
2526
],
2627
"icons": {
2728
"16": "icons/runwith-16.png",

addon/settings/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function createTableRow(data){
22

3-
var contexts = [ 'link', 'selection', 'image' ];
3+
var contexts = [ 'link', 'selection', 'image', 'page' ];
44

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

0 commit comments

Comments
 (0)