数字またはテキストのどちらを選択するかによって、別のメニューオプションを表示したい。選択に応じてコンテキストメニューをレンダリングする
私はコンテンツスクリプトで試してみましたが、動作するために必要な場所であるgmailで動作させることはできません。ここで
Background.html
<script src="driver.js"></script>
content_script.js
document.addEventListener("mousedown", function(event){
if(event.button == 2) {
var selection = window.getSelection().toString();
chrome.extension.sendRequest({cmd: selection});
}
}, true);
は、(それがhttpsの事です?)それはGmailの以外のサイト上で動作し、私が持っているものです
driver.js
chrome.extension.onRequest.addListener(function(request) {
alert(request.cmd);
});
manifest.jsonを
{
"name": "Context Menu Search",
"description": "Opens the selected text as keyword in a new window",
"version": "0.1",
"permissions": ["contextMenus"],
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["content_script.js"]
}
],
"background_page": "background.html"
}
http://stackoverflow.com/questions/6382467/chrome-extension-context-menus-how-to-display-a-menu-item-only-when-there-is-no – serg