-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimmer.js
49 lines (41 loc) · 1.09 KB
/
dimmer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var dimmerOverlayDivId = "chrome_dimmer_e592757f347a5f7558609639224dc38f";
var dimmerOverlay = $("<div/>", {"id": dimmerOverlayDivId});
/**
* Attachs the dimmerOverlay div and sets opacity.
*/
function showDimmer(opacity) {
if ($("#" + dimmerOverlayDivId).length == 0) {
$("body").append(dimmerOverlay);
dimmerOverlay.height($(window).height());
dimmerOverlay.css("opacity", "0");
dimmerOverlay.fadeTo("slow", opacity);
}
}
/**
* Removes dimmerOverlay from the document.
*/
function removeDimmer() {
dimmerOverlay.remove();
}
/**
* Tells the background.html to resetCountdown/Timer.
*/
function resetCountdown() {
chrome.extension.sendRequest({"greeting": "resetCountdown"});
}
$(document).ready(function() {
resetCountdown();
$(document).mouseover(function(e) {
removeDimmer();
});
$(document).mousemove(function(e) {
resetCountdown();
});
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.greeting == "lightsOut") {
showDimmer(request.opacity);
} else if (request.greeting == "lightsOn") {
removeDimmer();
}
});
});