This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,61 @@ | ||
var tlm = null; | ||
function onError(error) { | ||
port.postMessage(error); | ||
} | ||
|
||
// Establish connection with app | ||
let port = browser.runtime.connectNative("browser"); | ||
port.onMessage.addListener(response => { | ||
try { | ||
let code = ''; | ||
let code = null; | ||
if(response.zoomIn) { | ||
code = 'document.getElementById("zoomin").click()'; | ||
} else if(response.zoomOut) { | ||
code = 'document.getElementById("zoomout").click()'; | ||
} else if (response.toggleNight) { | ||
code = 'document.getElementById("toolbar-nightbutton").click()'; | ||
} else if(response.setCss) { | ||
browser.tabs.insertCSS({file: "abrptransmitter.css"}); | ||
browser.tabs.query({}).then((tabs) => { | ||
try { | ||
for (let tab of tabs) { | ||
browser.tabs.insertCSS(tab.id, {file: "abrptransmitter.css"}); | ||
} | ||
} catch (e) { | ||
onError(e); | ||
} | ||
}).catch(onError); | ||
} else if(response.removeCss) { | ||
browser.tabs.removeCSS({file: "abrptransmitter.css"}); | ||
browser.tabs.query({}).then((tabs) => { | ||
try { | ||
for (let tab of tabs) { | ||
browser.tabs.removeCSS(tab.id, {file: "abrptransmitter.css"}); | ||
} | ||
} catch (e) { | ||
onError(e); | ||
} | ||
}).catch(onError); | ||
} else if(response.lat && response.lon) { | ||
tlm = response; | ||
browser.tabs.query({ currentWindow: true, active: true }).then(sendMessageToTabs).catch(onError); | ||
browser.tabs.query({}).then((tabs) => { | ||
try { | ||
for (let tab of tabs) { | ||
browser.tabs.sendMessage(tab.id, {"tlm": response}); | ||
} | ||
} catch (e) { | ||
onError(e); | ||
} | ||
}).catch(onError); | ||
} | ||
if(code != '') { | ||
browser.tabs.executeScript({ | ||
code: code | ||
}); | ||
if(code != null) { | ||
browser.tabs.query({}).then((tabs) => { | ||
try { | ||
for (let tab of tabs) { | ||
browser.tabs.executeScript(tab.id, {code: code}); | ||
} | ||
} catch (e) { | ||
onError(e); | ||
} | ||
}).catch(onError); | ||
} | ||
} catch (e) { | ||
onError(e); | ||
} | ||
}); | ||
|
||
function onError(error) { | ||
//console.log(error); | ||
port.postMessage(error); | ||
} | ||
|
||
function sendMessageToTabs(tabs) { | ||
try { | ||
for (let tab of tabs) { | ||
browser.tabs.sendMessage(tab.id, {"tlm": tlm}); | ||
} | ||
} catch (e) { | ||
onError(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
"name": "ABRPTransmitter", | ||
"version": "1.0", | ||
"description": "Adds support for native messaging to abrp.", | ||
"browser_specific_settings": { | ||
"gecko": { | ||
"id": "[email protected]" | ||
} | ||
}, | ||
"background": { | ||
"scripts": ["background.js"] | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters