Compare commits
2 Enmetoj
9000b2a3b0
...
a1578a12ef
Author | SHA1 | Date | |
---|---|---|---|
Jaidyn Ann | a1578a12ef | ||
Jaidyn Ann | 55edbb1fc7 |
|
@ -1,4 +1,14 @@
|
||||||
let port = browser.runtime.connectNative("shellfox");
|
let port = undefined;
|
||||||
|
|
||||||
|
|
||||||
|
// Run the shellfox helper program.
|
||||||
|
function init_shellfox_port() {
|
||||||
|
port = browser.runtime.connectNative("shellfox");
|
||||||
|
port.onDisconnect.addListener((port) => {
|
||||||
|
console.log(port.error);
|
||||||
|
port = undefined;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return the command-string associated with a URL, if any.
|
// Return the command-string associated with a URL, if any.
|
||||||
|
@ -26,8 +36,9 @@ function getUrlCommand(url) {
|
||||||
|
|
||||||
// Execute the shell command associated with the given URL, if any.
|
// Execute the shell command associated with the given URL, if any.
|
||||||
function runUrlCommand(url) {
|
function runUrlCommand(url) {
|
||||||
console.log("Executing…");
|
|
||||||
let command = getUrlCommand(url);
|
let command = getUrlCommand(url);
|
||||||
|
if (!port)
|
||||||
|
init_shellfox_port();
|
||||||
if (command && port) {
|
if (command && port) {
|
||||||
port.postMessage(command);
|
port.postMessage(command);
|
||||||
}
|
}
|
||||||
|
@ -46,20 +57,15 @@ function compareRegexComplexity(a, b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
port.onDisconnect.addListener((port) => {
|
// When the address-bar button is clicked, run the according command (if any).
|
||||||
console.log(port.error);
|
|
||||||
port = undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
browser.pageAction.onClicked.addListener((tab) => {
|
browser.pageAction.onClicked.addListener((tab) => {
|
||||||
console.log("onClicked");
|
|
||||||
runUrlCommand(tab.url);
|
runUrlCommand(tab.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// When a tab’s URL has been changed, enable/disable the address-bar button
|
||||||
|
// based on whether or not there is an according command.
|
||||||
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||||
console.log("onUpdated");
|
|
||||||
if (getUrlCommand(tab.url))
|
if (getUrlCommand(tab.url))
|
||||||
browser.pageAction.show(tabId);
|
browser.pageAction.show(tabId);
|
||||||
else
|
else
|
||||||
|
@ -67,8 +73,11 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// When the active tab has changed, enable/disable the address-bar button based
|
||||||
|
// on whether or not there is an according command for it.
|
||||||
browser.tabs.onActivated.addListener((activeInfo) => {
|
browser.tabs.onActivated.addListener((activeInfo) => {
|
||||||
console.log("activated");
|
browser.tabs.get(activeInfo.tabId).then((tab) => {
|
||||||
let url = browser.tabs.get(activeInfo.tabId).url;
|
if (getUrlCommand(tab.url))
|
||||||
|
browser.pageAction.show(tab.id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
13
shellfox.sh
13
shellfox.sh
|
@ -25,8 +25,15 @@ read_message() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Deescape a JSON stream from input.
|
||||||
|
json_deescape() {
|
||||||
|
sed 's/^"//' \
|
||||||
|
| sed 's/"$//' \
|
||||||
|
| sed 's/\"/"/g'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
message="$(read_message)"
|
command="$(read_message | json_deescape)"
|
||||||
command="$(echo "$message" | sed 's/^"//' | sed 's/"$//')"
|
nohup "$SHELL" -c "$command" > /dev/null &
|
||||||
"$SHELL" -c "$command"
|
|
||||||
done
|
done
|
||||||
|
|
Ŝarĝante…
Reference in New Issue