-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini.html
More file actions
55 lines (43 loc) · 1.22 KB
/
Copy pathmini.html
File metadata and controls
55 lines (43 loc) · 1.22 KB
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
<!doctype html>
<html>
<head>
<!--
https://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/
-->
<script>
let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const createToken = function(){
let tok = '';
for (let i = 0; i < 7; i++){
tok += chars[Math.floor(Math.random()*62)]
}
if(localStorage.getItem(tok)){
tok = createToken();
}
return tok;
}
debugger
let search = window.location.search
let param = search.split('?')[1]
console.log(param)
let tok = '';
if(localStorage.getItem(param)){
tok = localStorage.getItem(param);
}
else{
tok = createToken();
localStorage.setItem(tok, param);
localStorage.setItem(param, tok);
}
let miniTxt = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname + '?' + tok;
</script>
</head>
<body>
<h1 style="text-align: center">Mini shortens your URLs.</h1>
<p> Provide the long URL as a parameter, like ?longURL
<div id='mini'></div>
<script>
mini.innerText = miniTxt;
</script>
</body>
</html>