Hide the menu item "translate this page" when selecting text

This commit is contained in:
sienori 2018-06-03 01:14:35 +09:00
parent 9558bb49eb
commit 40eb4842e4

View file

@ -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({