forked from kc596/Facebook_Timer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
51 lines (42 loc) · 1.22 KB
/
timer.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
50
51
/**
* timer.js - content script for Facebook Timer Chrome Extension
* @author Kunal Chaudhary
*/
var _curr, _total, time; //timer variables
/**
* Selecting the place on facebook's page to display timer
*/
var myElement = document.createElement("div");
myElement.setAttribute("class", "timer-style");
document.getElementsByTagName("body")[0].appendChild(myElement);
var child = document.createElement("div");
child.setAttribute("class","timer_bg");
child.innerHTML=time;
//Function to display timer
function displayTimer(){
time = getHours(_curr)+" : "+getMinutes(_curr)+" : "+getSeconds(_curr);
child.innerHTML = time;
myElement.appendChild(child);
}
//Monitor function
function set_timer(){
_curr++; _total++;
displayTimer();
setTimerValue();
}
/**
* Retriving the timer value as soon as facebook is opened
* Refreshing the timer every second
*/
getTimerValue();
setInterval(set_timer, 1000);
/*
* Handling timer reset request from popup.js
*/
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log("current timer cleared :D ");
if (request.clear == "true"){
_curr=0;
sendResponse({message: "timer successfully reset"});
}
});