我需要检测到我的扩展程序按钮上的双击,并打开一个不同的网站,我需要在当前选项卡中打开该网站。
index.js:
var myTimeSeries =
(from kvp in myOtherTimeSeries.Observations.AsParallel()
where /* and some other things */
select new KeyValuePair<...>(...)).ToSeries();
答案 0 :(得分:1)
我的一个扩展程序中有类似的要求。这是我用来确定按钮单击是单个还是双重的代码:
var clickCnt = 0; // Click counter
var delay = 250; // Maximum time (milliseconds) between clicks to be considered a double-click
var timer;
chrome.browserAction.onClicked.addListener(function(tab){
clickCnt++;
if(clickCnt > 1){
// Double-click detected
chrome.tabs.executeScript({
code: '// Code to execute on double-click'
});
clickCnt = 0;
clearTimeout(timer)
}else{
timer = setTimeout(function(){
// No clicked detected within (delay)ms, so consider this a single click
chrome.tabs.executeScript({
code: '// Code to execute on single-click'
});
clickCnt = 0;
}, delay);
}
return true;
});
答案 1 :(得分:0)
ActionButton本身没有onDoubleClick
处理程序。因此,您需要制定一些技巧来实现您想要的功能。
您可以为第一次单击指定处理程序,在此处理程序中,您将自行删除并为双击定义一个新处理程序,如下面的代码所示。
index.js:
var tabs = require("sdk/tabs");
var { ActionButton } = require("sdk/ui/button/action");
var { setTimeout } = require("sdk/timers");
var button = ActionButton({
id: "my-button",
label: "my button",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: firstClick
});
function firstClick(state) {
button.removeListener("click", firstClick);
button.on("click", subsequentClicks);
tabs.activeTab.url = "http://www.mozilla.org/";
tabs.activeTab.reload();
setTimeout(function() {
console.log("remove double click after an interval");
button.removeListener("click", subsequentClicks);
button.on("click", firstClick);
}, 1000);
}
function subsequentClicks(state) {
button.removeListener("click", subsequentClicks);
tabs.activeTab.url = "http://www.google.com/";
tabs.activeTab.reload();
}
另一个技巧是在firstClick
处理程序中定义了一个setTimeout函数,用于在1秒的间隔后恢复初始状态下的事物。
为了确保执行subsequentClicks
时的功能,它会将自己视为一个监听器。
正如评论中所提到的,问题是当双击它时首先加载mozilla.org然后google.com