From 46ed97e66d2c5675254671a119f09fe2aad6dd2d Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Sun, 24 Sep 2017 18:18:34 +0300 Subject: [PATCH] make sure filter cookie is for this page only! --- index.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 5c7a14b..a2e97ae 100644 --- a/index.html +++ b/index.html @@ -324,15 +324,31 @@ function filter_load() { function get_cookie(name) { var nameEQ = name+"="; var ca = document.cookie.split(";"); + var cookies = Array(); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==" ") c = c.substring(1,c.length); - if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); } + if (c.indexOf(nameEQ) == 0) { cookies.push(c.substring(nameEQ.length,c.length)); } + } + return filter_cookies(cookies,name) +} +function filter_cookies(cookies,name) { + // return only cookies that have the pathname + for(var i=0;i < cookies.length;i++) { + var c = cookies[i]; + var split = c.split("&"); + if (split.length == 2) { + if (split[1] == window.location.pathname) { + return split[0]; + } + } } return null } function set_cookie(name,value) { - document.cookie = name + "=" + value.toString() + "; path=" + window.location.pathname + ";"; + // Save cookies for 2 hours + document.cookie = name + "=" + value.toString() + "&" + window.location.pathname + + ";path=" + window.location.pathname + ";max-age="+ (60*60*2).toString() + ";"; } document.onkeyup=keyboard_entry; document.onkeydown=keyboard_control;