当用户单击并按住 chrome 扩展程序中的任何页面时,如何触发功能?这是我正在使用的,但它不起作用:
清单.json
{
"manifest_version": 2,
"name": "Harvix extension",
"description": "Shortcut to search on Harvix",
"version": "0.0.1",
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["jquery.js", "core.js"]
}
],
"permissions": [
"tabs", "<all_urls>"
]
}
核心.js
var timeout;
function open(text) {
$('#myElement').mousedown(function() {
timeout = setTimeout(null, 1000);
}).bind('mouseup mouseleave', function() {
clearTimeout(timeout);
});
alert('hello');
}
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {code: open(window.getSelection().toString())});
});