My goal is to create a Google Chrome extension that monitors mouse movements.
If there is no mouse movement for 5 minutes (I have set it to 0.1 and 0.2 in the code for testing purposes), the extension will open another website (an alert box is displayed in the code).
The issue I am facing is that I cannot reset the alarm if the mouse starts moving again. Everything works correctly, except for resetting or re-setting the alarm that I created.
I believe I made an error somewhere.
This is my first attempt at developing a Google Chrome extension, although I have experience with php, vb.net, html, and vbscript.
However, I cannot get the alarm reset to work on Google Chrome version 63 (I have tried older versions and Chromium as well, but it didn't work).
Thank you for your help ^^
The code starts here:
MANIFEST.JSON
{
"name": "Chrome-extension",
"version": "1.0",
"manifest_version": 2,
"permissions": [
"alarms"
],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["http://www.google.hu/*"],
"js": ["jquery1.7.2.js", "detectclicks.js"]
}
],
"description": "Chrome-extension",
"browser_action": {
"default_icon": "icon.png"
"default_popup": "popup.html"
}
}
DETECTCLICKS.JS (resets the alarm when the mouse moves)
$('html').on('mousemove', '*',function(event) {
chrome.alarms.clearAll();
chrome.alarms.create("myAlarm", {delayInMinutes: 0.1,
periodInMinutes: 0.2});
alert("OK");
});
BACKGROUND.JS (displays a message when the alarm triggers)
chrome.alarms.onAlarm.addListener(function(alarm) {
alert("Beep");
});
POPUP.JS (Enables and disables the extension with start and stop alarms)
var alarmClock = {
onHandler : function(e) {
chrome.alarms.create("myAlarm", {
delayInMinutes: 0.1,
periodInMinutes: 0.2
});
window.close();
},
offHandler : function(e) {
chrome.alarms.clear("myAlarm");
window.close();
},
setup: function() {
var a = document.getElementById('alarmOn');
a.addEventListener('click', alarmClock.onHandler);
var a = document.getElementById('alarmOff');
a.addEventListener('click', alarmClock.offHandler);
}
};
document.addEventListener('DOMContentLoaded', function() {
alarmClock.setup();
});