Просмотр файла js/online.js

Размер файла: 1.6Kb
  1. var caution = false
  2. function setCookie(name, value, expires, path, domain, secure) {
  3. var curCookie = name + "=" + escape(value) +
  4. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  5. ((path) ? "; path=" + path : "") +
  6. ((domain) ? "; domain=" + domain : "") +
  7. ((secure) ? "; secure" : "")
  8. if (!caution || (name + "=" + escape(value)).length <= 4000)
  9. document.cookie = curCookie
  10. else
  11. if (confirm("Cookie exceeds 4KB and will be cut!"))
  12. document.cookie = curCookie
  13. }
  14.  
  15. function getCookie(name) {
  16. var prefix = name + "="
  17. var cookieStartIndex = document.cookie.indexOf(prefix)
  18. if (cookieStartIndex == -1)
  19. return null
  20. var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
  21. if (cookieEndIndex == -1)
  22. cookieEndIndex = document.cookie.length
  23. return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
  24. }
  25. function deleteCookie(name, path, domain) {
  26. if (getCookie(name)) {
  27. document.cookie = name + "=" +
  28. ((path) ? "; path=" + path : "") +
  29. ((domain) ? "; domain=" + domain : "") +
  30. "; expires=Thu, 01-Jan-70 00:00:01 GMT"
  31. }
  32. }
  33. function fixDate(date) {
  34. var base = new Date(0)
  35. var skew = base.getTime()
  36. if (skew > 0)
  37. date.setTime(date.getTime() - skew)
  38. }
  39. var now = new Date()
  40. fixDate(now)
  41. now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
  42. var visits = getCookie("counter")
  43. if (!visits)
  44. visits = 1
  45. else
  46. visits = parseInt(visits) + 1
  47. setCookie("counter", visits, now)
  48. document.write("кликнул " + visits + " раз.")