-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
177 lines (159 loc) · 6.24 KB
/
index.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Cookie Tester</title>
<link rel="icon" type="image/png" href="/favicon.png" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<h1>Cookie Tester</h1>
<p>Cookie Tester is an utility website that helps verifying cookies retention in the browser.</p>
<h2>Add a cookie</h2>
<form id="add-cookie-form">
<label for="add-cookie-form-name">Cookie name</label>
<input id="add-cookie-form-name" name="name" placeholder="cookie-name">
<label for="add-cookie-form-value">Cookie value</label>
<textarea id="add-cookie-form-value" name="value" placeholder="cookie-value"></textarea>
<label for=" add-cookie-form-expires">Cookie expires (days)</label>
<input id="add-cookie-form-expires" type="number" name="expires" min="1" placeholder="7" value="7">
<input id="add-cookie-form-submit" type="submit" value="Submit" onclick="addCookie(event)">
</form>
<h2>Cookies registered</h2>
<p><b id="cookies-count">0</b> cookie(s) registered on this website.</p>
<input id="clear-cookies" type="button" value="Clear cookies" onclick="clearCookies()">
<table id="cookies-table">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody id="cookies-table-tbody">
</tbody>
</table>
<h2>API and Lazy usage</h2>
<p>GET <a id="api-example-a"><code><span id="api-example-text"></span></code></a> to
add a new cookie.
</p>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2.2.1/src/js.cookie.min.js"></script>
<script type="text/javascript">
function addCookie(event) {
if (event != null) {
event.preventDefault();
}
var name = document.getElementById("add-cookie-form-name").value;
var value = document.getElementById("add-cookie-form-value").value;
var expires = document.getElementById("add-cookie-form-expires").value;
Cookies.set(name, value, { expires: Number(expires), path: '' });
loadCookiesTable();
preFillForm();
}
function clearCookies() {
var cookies = Cookies.get();
Object.keys(cookies).forEach(function (key) {
Cookies.remove(key);
});
loadCookiesTable();
}
function loadCookiesTable() {
var tbody = document.getElementById("cookies-table-tbody");
tbody.innerHTML = "";
var cookies = Cookies.get();
Object.keys(cookies).forEach(function (key) {
var tr = tbody.insertRow();
var td = tr.insertCell();
td.innerText = key;
td = tr.insertCell();
td.innerText = cookies[key];
})
var counter = document.getElementById("cookies-count");
counter.textContent = Object.keys(cookies).length;
}
function preFillForm() {
document.getElementById("add-cookie-form-name").value = Math.round(new Date().getTime());
var text = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
document.getElementById("add-cookie-form-value").textContent = text;
}
function handleUrlParameters() {
var queryString = window.location.search;
console.log(queryString)
if (queryString != null) {
var urlParams = new URLSearchParams(queryString);
document.getElementById("add-cookie-form-name").value = urlParams.get('name');
document.getElementById("add-cookie-form-value").textContent = urlParams.get('value');
document.getElementById("add-cookie-form-expires").textContent = urlParams.get('expires');
addCookie(null);
}
}
</script>
<script>loadCookiesTable();</script>
<script>preFillForm();</script>
<script>handleUrlParameters();</script>
<script>
var getUrl = window.location;
var baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
var example = baseUrl + "?name=foo&value=bar&expires=7";
document.getElementById("api-example-text").textContent = example;
document.getElementById("api-example-a").setAttribute("href", example);
</script>
<style>
#forkongithub a {
background: #000;
color: #fff;
text-decoration: none;
font-family: arial, sans-serif;
text-align: center;
font-weight: bold;
padding: 5px 40px;
font-size: 1rem;
line-height: 2rem;
position: relative;
transition: 0.5s;
}
#forkongithub a:hover {
background: #c11;
color: #fff;
}
#forkongithub a::before,
#forkongithub a::after {
content: "";
width: 100%;
display: block;
position: absolute;
top: 1px;
left: 0;
height: 1px;
background: #fff;
}
#forkongithub a::after {
bottom: 1px;
top: auto;
}
@media screen and (min-width:800px) {
#forkongithub {
position: fixed;
display: block;
top: 0;
right: 0;
width: 200px;
overflow: hidden;
height: 200px;
z-index: 9999;
}
#forkongithub a {
width: 200px;
position: absolute;
top: 60px;
right: -60px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.8);
}
}
</style><span id="forkongithub"><a href="https://github.com/TomyCesaille/cookie-tester">Fork me on GitHub</a></span>
</body>
</html>