我想根據是否選擇數字或文本來顯示不同的菜單選項。根據選擇渲染上下文菜單
我試過玩內容腳本,但我不能讓他們在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