Skip to content

Commit

Permalink
use APIs only if they exist (atempt at making it work on Android)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Cristian Petcu committed May 27, 2017
1 parent dd54b3e commit bd62afc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_appName__",
"version": "1.2.4",
"version": "1.2.5",
"homepage_url": "https://github.com/andreicristianpetcu/google_translate_this",
"manifest_version": 2,
"description": "__MSG_appDescription__",
Expand Down
67 changes: 38 additions & 29 deletions scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function showPageActionOnTab(tabInfo){
}

function translateCurrentPage() {
chrome.tabs.query({
browser.tabs.query({
currentWindow: true,
active: true
}, function (foundTabs) {
Expand All @@ -26,33 +26,42 @@ function translateCurrentPage() {
});
}

chrome.commands.onCommand.addListener(function(action) {
if (action == "translate-current-page") {
translateCurrentPage();
}
});
if (browser.commands) {
browser.commands.onCommand.addListener(function(action) {
if (action == "translate-current-page") {
translateCurrentPage();
}
});
}

browser.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == "translate-current-page") {
translateCurrentPage();
}
});

browser.browserAction.onClicked.addListener(translateCurrentPage);
browser.contextMenus.create({
id: "translate-current-page",
title: "Translate Current Page",
contexts: ["all"]
});
browser.pageAction.onClicked.addListener(translateCurrentPage);

browser.tabs.query({}).then((tabs) => {
var tab;
for (tab of tabs) {
showPageActionOnTab(tab);
}
});
if (browser.contextMenus) {
browser.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == "translate-current-page") {
translateCurrentPage();
}
});
browser.contextMenus.create({
id: "translate-current-page",
title: "Translate Current Page",
contexts: ["all"]
});
}

browser.tabs.onUpdated.addListener((id, changeInfo, tab) => {
showPageActionOnTab(tab);
});
if (browser.browserAction) {
browser.browserAction.onClicked.addListener(translateCurrentPage);
}


if (browser.pageAction) {
browser.pageAction.onClicked.addListener(translateCurrentPage);
browser.tabs.query({}).then((tabs) => {
var tab;
for (tab of tabs) {
showPageActionOnTab(tab);
}
});

browser.tabs.onUpdated.addListener((id, changeInfo, tab) => {
showPageActionOnTab(tab);
});
}
4 changes: 3 additions & 1 deletion updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
{ "version": "1.2.3",
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.2.3/google_translate_this_page-1.2.3-an.fx.xpi" },
{ "version": "1.2.4",
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.2.4/google_translate_this_page-1.2.4-an.fx.xpi" }
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.2.4/google_translate_this_page-1.2.4-an.fx.xpi" },
{ "version": "1.2.5",
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.2.5/google_translate_this_page-1.2.5-an.fx.xpi" }
]
}
}
Expand Down

0 comments on commit bd62afc

Please sign in to comment.