Compare commits
No commits in common. "a1578a12eff0d978b4a58f0374a78aafa4643a38" and "9000b2a3b0747b08b0c65c0a080857a9b2585c5a" have entirely different histories.
a1578a12ef
...
9000b2a3b0
|
@ -1,14 +1,4 @@
|
||||||
let port = undefined;
|
let port = browser.runtime.connectNative("shellfox");
|
||||||
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -36,9 +26,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -57,15 +46,20 @@ function compareRegexComplexity(a, b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// When the address-bar button is clicked, run the according command (if any).
|
port.onDisconnect.addListener((port) => {
|
||||||
|
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
|
||||||
|
@ -73,11 +67,8 @@ 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) => {
|
||||||
browser.tabs.get(activeInfo.tabId).then((tab) => {
|
console.log("activated");
|
||||||
if (getUrlCommand(tab.url))
|
let url = browser.tabs.get(activeInfo.tabId).url;
|
||||||
browser.pageAction.show(tab.id);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
13
shellfox.sh
13
shellfox.sh
|
@ -25,15 +25,8 @@ read_message() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Deescape a JSON stream from input.
|
|
||||||
json_deescape() {
|
|
||||||
sed 's/^"//' \
|
|
||||||
| sed 's/"$//' \
|
|
||||||
| sed 's/\"/"/g'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
command="$(read_message | json_deescape)"
|
message="$(read_message)"
|
||||||
nohup "$SHELL" -c "$command" > /dev/null &
|
command="$(echo "$message" | sed 's/^"//' | sed 's/"$//')"
|
||||||
|
"$SHELL" -c "$command"
|
||||||
done
|
done
|
||||||
|
|
Ŝarĝante…
Reference in New Issue