-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
349 lines (301 loc) · 11.4 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cookie Handler Documentation</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0px;
background-color: #f4f4f4;
}
h1, h2, h3 {
color: #333;
}
.container {
background: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-height: 96vh; /* Limit height for overflow */
overflow: auto; /* Enable scrollbars */
}
button {
padding: 10px 20px;
margin: 10px 0;
border: none;
background-color: #007BFF;
color: white;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
pre {
position: relative;
background: #0e101e;
color: white;
padding: 10px;
border-radius: 5px;
border: 1px solid #ddd;
overflow: auto;
}
.copy-btn {
position: relative;
left: -35px;
top: -17px;
padding: 5px 10px;
border: none;
background-color: #007BFF;
color: white;
border-radius: 3px;
cursor: pointer;
}
.copy-btn:hover {
background-color: #0056b3;
}
span{
font-size: 14px;
}
.whiteP{
color: white;
}
.green{
color: greenyellow;
}
.comment{
color: #979191;
}
.import, .from{
color:rgb(245 71 255);
}
.yellow{
color: yellow;
}
.blue{
color: rgb(132, 216, 252);
}
/* Custom Scrollbar for Webkit Browsers (Chrome, Safari) */
.custom-scrollbar::-webkit-scrollbar {
width: 12px; /* Width of the vertical scrollbar */
height: 12px; /* Height of the horizontal scrollbar */
}
.custom-scrollbar::-webkit-scrollbar-track {
background: #f1f1f1; /* Background of the scrollbar track */
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background-color: #888; /* Color of the scrollbar thumb */
border-radius: 10px; /* Rounded corners */
border: 3px solid #f1f1f1; /* Space around the thumb */
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: #555; /* Color of the scrollbar thumb when hovered */
}
/* Custom Scrollbar for Firefox */
.custom-scrollbar {
scrollbar-width: thin; /* Thin scrollbar */
scrollbar-color: #888 #f1f1f1; /* Thumb color and track color */
}
/* Custom Scrollbar for Edge, IE, and others */
.custom-scrollbar {
-ms-overflow-style: none; /* Hide default scrollbar in IE */
}
.custom-scrollbar::-ms-scrollbar {
width: 12px; /* Width of the scrollbar */
height: 12px; /* Height of the scrollbar */
}
.custom-scrollbar::-ms-scrollbar-track {
background: #f1f1f1; /* Background of the scrollbar track */
}
.custom-scrollbar::-ms-scrollbar-thumb {
background-color: #888; /* Color of the scrollbar thumb */
border-radius: 10px; /* Rounded corners */
border: 3px solid #f1f1f1; /* Space around the thumb */
}
.custom-scrollbar::-ms-scrollbar-thumb:hover {
background: #555; /* Color of the scrollbar thumb when hovered */
}
/* Custom Scrollbar for <pre> tag */
pre::-webkit-scrollbar {
height: 8px; /* Height of the horizontal scrollbar */
}
pre::-webkit-scrollbar-track {
background: #f1f1f1; /* Background of the scrollbar track */
}
pre::-webkit-scrollbar-thumb {
background-color: #888; /* Color of the scrollbar thumb */
border-radius: 10px; /* Rounded corners */
}
pre::-webkit-scrollbar-thumb:hover {
background: #555; /* Color of the scrollbar thumb when hovered */
}
pre {
scrollbar-width: thin; /* Thin scrollbar for Firefox */
scrollbar-color: #888 #f1f1f1; /* Thumb color and track color */
}
pre {
-ms-overflow-style: none; /* Hide default scrollbar in IE */
}
pre::-ms-scrollbar {
height: 8px; /* Height of the scrollbar */
}
pre::-ms-scrollbar-track {
background: #f1f1f1; /* Background of the scrollbar track */
}
pre::-ms-scrollbar-thumb {
background-color: #888; /* Color of the scrollbar thumb */
border-radius: 10px; /* Rounded corners */
}
pre::-ms-scrollbar-thumb:hover {
background: #555; /* Color of the scrollbar thumb when hovered */
}
</style>
</head>
<body>
<div class="container custom-scrollbar">
<h1>Cookie Handler</h1>
<p>A simple and flexible cookie handler for JavaScript and TypeScript projects.</p>
<h2>Installation</h2>
<pre>
<button class="copy-btn" onclick="copyToClipboard('install-code')">Copy</button>
<code id="install-code"><span class="white">npm install</span><span class="green"> cookie-handler-pro</span></code>
</pre>
<p>OR</p>
<pre>
<button class="copy-btn" onclick="copyToClipboard('install-code')">Copy</button>
<span class="white">npm i</span><span class="green"> cookie-handler-pro</span>
</pre>
<h2>Usage</h2>
<h3>Setting a Cookie</h3>
<pre>
<button class="copy-btn" onclick="copyToClipboard('set-cookie-code')">Copy</button>
<code id="set-cookie-code">
<span class="import">import</span><span class="white"> <span class="yellow">{ setCookie }</span> <span class="from">from</span> <span class="yellow">'cookie-handler-pro';</span>
<span class="comment">//Set a cookie with various options</span>
<span>
setCookie('username', 'john_doe', {
expires: '7d', // Expires in 7 days
path: '/',
domain: 'example.com',
secure: true,
sameSite: 'Lax'});
</span>
<span class="comment">// Set a cookie to expire in 2 hours</span>
<span>setCookie('session', 'abcd1234', { expires: '2h', path: '/'});</span>
</code>
</pre>
<h3>Getting a Cookie</h3>
<pre>
<button class="copy-btn" onclick="copyToClipboard('get-cookie-code')">Copy</button>
<code id="get-cookie-code"><span class="import">import</span> <span class="yellow">{ getCookie }</span> <span class="from">from</span> <span class="yellow">'cookie-handler-pro';</span>
<span>const username = getCookie('username');console.log(username); </span> <span class="comment">// Output: 'john_doe'</span>
</code>
</pre>
<h3>Deleting a Cookie</h3>
<pre>
<button class="copy-btn" onclick="copyToClipboard('delete-cookie-code')">Copy</button>
<code id="get-cookie-code"><span class="import">import</span> <span class="yellow">{ deleteCookie }</span> <span class="from">from</span> <span class="yellow">'cookie-handler-pro';</span>
<span>deleteCookie('username', { path: '/', domain: 'example.com' }); </span>
</pre>
<h2>Usage in Next.js</h2>
<h3>Setting a Cookie in Next.js</h3>
<pre>
<button class="copy-btn" onclick="copyToClipboard('nextjs-set-cookie-code')">Copy</button>
<code id="nextjs-set-cookie-code">
<span class="comment">// pages/api/set-username.ts</span>
<span class="import">import</span> <span class="yellow">{ NextApiRequest, NextApiResponse }</span> <span class="from">from</span> <span class="yellow">'next';</span>
<span class="import">import</span> <span class="yellow">{ setCookie }</span> <span class="from">from</span> <span class="yellow">'cookie-handler-pro';</span>
<span>
export default function handler(req: NextApiRequest, res: NextApiResponse) {
setCookie('username', 'john_doe', {
expires: '7d',
path: '/',
domain: req.headers.host,
secure: process.env.NODE_ENV === 'production',
sameSite: 'Lax'
});
res.status(200).json({ message: 'Cookie set successfully' });
}
</span></code></pre>
<h3>Getting a Cookie in Next.js</h3>
<pre>
<button class="copy-btn" onclick="copyToClipboard('nextjs-get-cookie-code')">Copy</button>
<code id="nextjs-get-cookie-code">
<span class="comment">// pages/index.tsx</span>
<span class="import">import</span> <span class="yellow">{ useEffect, useState }</span> <span class="from">from</span> <span class="yellow">'react';</span>
<span class="import">import</span> <span class="yellow">{ getCookie }</span> <span class="from">from</span> <span class="yellow">'cookie-handler-pro';</span>
<span>
const HomePage = () => {
const [username, setUsername] = useState<string | null>(null);
useEffect(() => {
const cookieValue = getCookie('username');
setUsername(cookieValue);
}, []);
return <div>Username: {username}</div>;
};
export default HomePage;
</span></code></pre>
<h3>Deleting a Cookie in Next.js</h3>
<pre>
<button class="copy-btn" onclick="copyToClipboard('nextjs-delete-cookie-code')">Copy</button>
<code id="nextjs-delete-cookie-code">
<span class="comment">// pages/api/delete-username.ts</span>
<span class="import">import</span> <span class="yellow">{ NextApiRequest, NextApiResponse }</span> <span class="from">from</span> <span class="yellow">'next';</span>
<span class="import">import</span> <span class="yellow">{ deleteCookie }</span> <span class="from">from</span> <span class="yellow">'cookie-handler-pro';</span>
<span>
export default function handler(req: NextApiRequest, res: NextApiResponse) {
deleteCookie('username', { path: '/', domain: req.headers.host });
res.status(200).json({ message: 'Cookie deleted successfully' });
}
</span></code></pre>
<h3>Next.js App Route</h3>
<pre>
<button class="copy-btn" onclick="copyToClipboard('nextjs-app-route-code')">Copy</button>
<code id="nextjs-app-route-code">
<span class="blue">"use client";</span>
<span class="import">import</span> <span class="yellow">{ getCookie, setCookie, deleteCookie }</span> <span class="from">from</span> <span class="yellow">'cookie-handler-pro';</span>
<span>
export default function Home() {
const handleSetCookie = () => {
setCookie("username", "john_doe", {
expires: "7d",
path: "/",
domain: window.location.hostname, // Use window.location.hostname instead of req.headers.host
secure: process.env.NODE_ENV === "production",
sameSite: "Lax",
});
};
const handleDeleteCookie = () => {
deleteCookie("username");
};
const value = getCookie("username");
return (
<>
<button onClick={handleSetCookie}>Set Cookie</button> <br>
<button onClick={handleDeleteCookie}>Delete Cookie</button>
<h1>Cookies: {value}</h1>
</>
);
}
</span></code></pre>
<span>Author</span> <span><a href="http://nrshagor.com" target="_blank">N R SHAGOR</a></span>
<br>
<span>License</span> <span>MIT</span>
</div>
<script>
function copyToClipboard(id) {
const codeElement = document.getElementById(id);
const range = document.createRange();
range.selectNode(codeElement);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
alert('Code copied to clipboard');
}
</script>
</body>
</html>