-
Notifications
You must be signed in to change notification settings - Fork 5
/
countTime-active-tab.html
44 lines (42 loc) · 1.03 KB
/
countTime-active-tab.html
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
<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml"
lang="ja"
xml:lang="ja"
dir="ltr"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml"
>
<head>
<title>CountTime Active Tab Browser</title>
</head>
<body>
<h2>CountTime Active Tab Browser</h2>
<div style="margin-top: 20px; text-align: center">
<h1>0</h1>
</div>
<script type="text/javascript">
let counter = document.querySelector("h1");
// window.addEventListener("DOMContentLoaded", () => {
// startCounter();
// });
window.addEventListener("blur", () => {
stopCounter();
});
window.addEventListener("focus", () => {
startCounter();
});
let intervalId;
let counterValue = 0;
function startCounter() {
intervalId = setInterval(() => {
counterValue++;
counter.innerText = counterValue;
}, 1000);
}
function stopCounter() {
clearInterval(intervalId);
}
</script>
</body>
</html>