可以跟踪单击和双击
a)浏览器动作
b)使用 chrome 扩展的页面操作。
默认情况下,chrome 有一个用于浏览器和页面操作的单鼠标单击事件侦听器,通过扩展它,您也可以捕获双击事件。
浏览器操作的单击和双击事件演示
此示例代码更改了单击和双击的浏览器操作图标,同样可以使用其Listener和setter扩展页面操作。
清单.json
在清单中注册浏览器操作和后台脚本
{
"name": "Mouse Clicks",
"version": "0.0.1",
"manifest_version": 2,
"description": "This demonstrates how mouse clicks are tracked",
"background":{
"scripts":["background.js"]
},
"browser_action":{
"default_icon":"normal.png"
}
}
背景.js
//Set click to false at beginning
var alreadyClicked = false;
//Declare a timer variable
var timer;
//Add Default Listener provided by chrome.api.*
chrome.browserAction.onClicked.addListener(function (tab) {
//Check for previous click
if (alreadyClicked) {
//Yes, Previous Click Detected
//Clear timer already set in earlier Click
clearTimeout(timer);
console.log("Double click");
//Change Icon
chrome.browserAction.setIcon({
"path": "double.png"
}, function () {
console.log("Changed Icon for Double Click");
});
//Clear all Clicks
alreadyClicked = false;
return;
}
//Set Click to true
alreadyClicked = true;
//Add a timer to detect next click to a sample of 250
timer = setTimeout(function () {
//No more clicks so, this is a single click
console.log("Single click");
//Chane Icon
chrome.browserAction.setIcon({
"path": "single.gif"
}, function () {
console.log("Changed Icon for Single Click");
});
//Clear all timers
clearTimeout(timer);
//Ignore clicks
alreadyClicked = false;
}, 250);
});
浏览器操作\页面操作图标的宽度和高度最多可达 19 个下降(与设备无关的像素)。较大的图标会调整大小以适应,理想情况下您不能scroll click
或scroll on
这些小图像。
如果您需要更多信息,请与我们联系