-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
executable file
·72 lines (64 loc) · 1.73 KB
/
util.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// encode(decode) html text into html entity
function decodeHtmlEntity(str) {
return str.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
});
};
function twodigits(v)
{
var v2 = v > 9 ? v : '0' + v;
return(v2);
}
function format(cdate)
{
var date = new Date(cdate);
var day = twodigits(date.getDate());
var month = twodigits(date.getMonth() + 1);
var year = date.getFullYear();
var hours = twodigits(date.getHours());
var minutes = twodigits(date.getMinutes());
return(" "+day+"/"+month+" "+hours+"h"+minutes);
}
function decodeEntities(encodedString)
{
var textArea = document.createElement('textarea');
textArea.innerHTML = encodedString;
return decodeHtmlEntity(textArea.value);
}
// retourne l'index de l'objet o dans le tableau t si présent et -1 sinon
function indexOf(t,o)
{
var limit = t.length;
var trouve=false;
var i=0;
while( (!trouve) && (i<limit))
{
var c=t[i];
if ((c.titre == o.titre) && (c.date==o.date))
{
trouve=true;
}
i++;
}
if (trouve) {return (i-1);}
else { return -1; }
}
function getCookie(cname)
{
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
function setCookie(cname, cvalue, exdays)
{
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
}