숫자 또는 텍스트의 선택 여부에 따라 다른 메뉴 옵션을 표시하려고합니다.선택에 따라 컨텍스트 메뉴 렌더링
콘텐츠 스크립트를 사용해 보았지만 작동에 필요한 gmail에서 작동하지 못했습니다. 다음은 Gmail이 아닌 다른 사이트 (그것이 HTTPS 것입니까?)
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);
에서 작동, 내가 가진 무엇
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