From 40eb4842e47e895dda73e7fa11e580317b16397e Mon Sep 17 00:00:00 2001 From: sienori Date: Sun, 3 Jun 2018 01:14:35 +0900 Subject: [PATCH] Hide the menu item "translate this page" when selecting text --- simple-translate/background.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/simple-translate/background.js b/simple-translate/background.js index 9b83317..a4138bf 100644 --- a/simple-translate/background.js +++ b/simple-translate/background.js @@ -13,6 +13,7 @@ browser.runtime.onInstalled.addListener(function () { let S = new settingsObj() browser.storage.onChanged.addListener(showMenu); +if (typeof (browser.contextMenus.onShown) != 'undefined') browser.contextMenus.onShown.addListener(updateMenu); S.init().then(function () { showMenu(); @@ -25,6 +26,16 @@ function showMenu() { } else menuRemove(); } +//テキストまたはリンクの選択時はページ翻訳を非表示にする +function updateMenu(info, tab) { + if (info.contexts.includes('selection') || info.contexts.includes('link')) { + browser.contextMenus.update('translatePage', { contexts: ['password'] }); //passwordにすることで事実上無効にする + } else { + browser.contextMenus.update('translatePage', { contexts: ['all'] }); + } + browser.contextMenus.refresh(); +} + //メニューを表示 function menuCreate() { browser.contextMenus.create({