Skip to content

Commit

Permalink
added page action that actually works
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Cristian Petcu committed May 13, 2017
1 parent 5143eac commit ee3053f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 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.1.0",
"version": "1.2.0",
"homepage_url": "https://github.com/andreicristianpetcu/google_translate_this",
"manifest_version": 2,
"description": "__MSG_appDescription__",
Expand Down
28 changes: 24 additions & 4 deletions scripts/background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
'use strict';

const APPLICABLE_PROTOCOLS = ["http:", "https:"];

function protocolIsApplicable(url) {
var anchor = document.createElement('a');
anchor.href = url;
return APPLICABLE_PROTOCOLS.includes(anchor.protocol);
}

function showPageActionOnTab(tabInfo){
if (protocolIsApplicable(tabInfo.url)) {
browser.pageAction.show(tabInfo.id);
}
}

function translateCurrentPage() {
chrome.tabs.query({
currentWindow: true,
Expand All @@ -25,14 +39,20 @@ browser.contextMenus.onClicked.addListener(function(info, tab) {
});

browser.browserAction.onClicked.addListener(translateCurrentPage);

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

browser.tabs.onActivated.addListener(function(tabInfo){
browser.pageAction.show(tabInfo.tabId);
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 @@ -7,7 +7,9 @@
{ "version": "1.0.2",
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.0.2/google_translate_this_page-1.0.2-an.fx.xpi" },
{ "version": "1.0.3",
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.0.3/google_translate_this_page-1.0.3-an.fx.xpi" }
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.0.3/google_translate_this_page-1.0.3-an.fx.xpi" },
{ "version": "1.2.0",
"update_link": "https://github.com/andreicristianpetcu/google_translate_this/releases/download/v1.2.0/google_translate_this_page-1.2.0-an.fx.xpi" }
]
}
}
Expand Down

0 comments on commit ee3053f

Please sign in to comment.