forked from Sledge/Horloge-Geek
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorclock.js
More file actions
88 lines (69 loc) · 2.36 KB
/
colorclock.js
File metadata and controls
88 lines (69 loc) · 2.36 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function getPortWidth() {
var viewportwidth;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth;
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth;
}
// older versions of IE
else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
}
return viewportwidth;
}
function getPortHeight() {
var viewportwidth;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportheight = window.innerHeight;
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportheight = document.documentElement.clientWidth;
}
// older versions of IE
else
{
viewportheight = document.getElementsByTagName('body')[0].clientHeight;
}
return viewportheight;
}
function updateTime() {
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
var BB=format_part(s, 60)
var VV=format_part(m*60+s, 3600)
var RR=format_part(h * 3600 + m * 60 + s, 3600*24)
var hexa_clock = RR+VV+BB;
var hh = format_number(h),
mm = format_number(m),
ss = format_number(s);
$('#clock').html("0x"+hexa_clock+"<br /><small>"+hh+":"+mm+":"+ss+"</small>");
$('body').css('background-color', "#"+hexa_clock);
}
function format_part(n, base) {
var n_converted = Math.round (256 * n/base);
var part_hex=n_converted.toString(16).toUpperCase();
return (part_hex.length<2)?"0"+part_hex:part_hex;
}
function format_number(n) {
return (n < 10)?"0"+n:n;
}
$(document).ready(function() {
updateTime();
setInterval("updateTime()", 1000);
});