-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
59 lines (52 loc) · 1.42 KB
/
Copy pathcontentScript.js
File metadata and controls
59 lines (52 loc) · 1.42 KB
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
50
51
52
53
54
55
56
57
58
59
// OverLayer constructor
function OverLayer() {
this.color = "#000";
this.alpha = 0.1;
this.alphaOffset = 0.02;
}
let overLayer = {};
// Check if #overLayer exists on the DOM
function overLayerExists() {
return $("#overLayer").length > 0;
}
// Create, redraw the overLayer opacity, remove if specified
function drawOverlay(removeAfter) {
if (!overLayerExists()) {
overLayer = new OverLayer();
$("body").append("<div id='overLayer'></div>");
}
$("#overLayer").fadeTo(200, overLayer.alpha, function() {
if (removeAfter) $("#overLayer").remove();
});
}
// Toggle the overLayer. Kill if it exists already
function toggleOverlay() {
let killOverLay = overLayerExists();
if (killOverLay) overLayer.alpha = 0;
drawOverlay(killOverLay);
}
// Apply an offset to the alpha
function offsetOverlayOpacity(offset) {
if (offset == "increment" && overLayer.alpha <= 1 - overLayer.alphaOffset) {
overLayer.alpha += overLayer.alphaOffset;
} else if (
offset == "decrement" &&
overLayer.alpha >= overLayer.alphaOffset
) {
overLayer.alpha -= overLayer.alphaOffset;
}
drawOverlay();
}
// Listen from popup for button clicks
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
let method = request.method;
switch (method) {
case "toggle":
toggleOverlay();
break;
case "increment":
case "decrement":
offsetOverlayOpacity(method);
break;
}
});