-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
132 lines (114 loc) · 4.93 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/index-style.css">
<link rel="icon" type="image/png" href="favicon.ico"/>
<title>Doughnut | Online URL Shortner</title>
</head>
<body style = "font-family: sans-serif;">
<nav>
<div class="navbar">
<a href="doughnut.html" target="_blank" rel="noopener noreferrer" class="text-decoration-none text-dark">
<img src="assets/doughnut.png" alt="logo">
<h3 class="text-dark navbar-text">Doughnut</h3>
</a>
</div>
<div class="form">
<a href="pages/sign-in.html" target="_blank" rel="noopener noreferrer"><button id="log-in">Log In</button></a>
<a href="pages/sign-up.html" target="_blank" rel="noopener noreferrer"><button id="sign-up">#</button></a>
</div>
</nav>
<div class="container">
<h2 class="text" >Enter URL: </h2>
<input type="text" name="URL" style = "font-size: medium;" id="url" required="">
<button id="enter" onclick = loadocs()>Enter</button>
<h2 class="text-2">Short URL: </h2>
<input type="text" style = "font-size: medium;" name="URL-2" id="surl" readonly="">
<button id="copy" onclick = copy() >Copy</button>
<p id="line"># to see all your previous links and their statistics</p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p id="line-2"></p>
</div>
<script src="../js/encrypt.js"></script>
<script>
var headr = document.getElementById("line");
var tbl = document.getElementById("line-2");
var urlString = window.location.href;
let paramString = urlString.split('?')[1];
var UNAME_AVAIL = false ;
var tok ;
if(paramString !== undefined){
UNAME_AVAIL = true ;
let queryString = new URLSearchParams(paramString);
for (let pair of queryString.entries()) {
// alert((pair[1]));
//var cs = decode(pair[1]) ;
//alert(cs);
tok = JSON.parse(atob(pair[1])) ;
//tok = ;
}
headr.innerHTML = "Welcome "+tok.name ;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function(){
tbl.innerHTML = this.responseText ;
}
xmlhttp.open("GET","script/contentGenarator.php?tok="+JSON.stringify(tok));
xmlhttp.send();
}
var elm1 = document.getElementById("url");
var url = elm1.value ;
var urlObj = {
uid : "",
url : "" ,
desc : "" ,
surl : "" ,
INVALID_URL : false,
EMPTY_URL : false,
SUCCES : false,
DB_INSER_FAIL : false
};
if(UNAME_AVAIL)
urlObj.uid = tok.uname ;
else
urlObj.uid = "anonymous" ;
function loadocs(){
urlObj.url = elm1.value ;
var jsn = JSON.stringify(urlObj);
//console.log(jsn) ;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function(){
//console.log(this.responseText);
var obj = JSON.parse(this.responseText);
if(obj.EMPTY_URL)
alert("Empty URL");
if(obj.INVALID_URL)
alert("Invalid URL: Please provide a valid URL") ;
if(obj.DB_INSER_FAIL)
alert("Database is not responding: Please try after some time");
if(obj.SUCCES){
//echo(obj.surl);
document.getElementById("surl").value = "https://dghnut.000webhostapp.com/i.php/"+obj.surl ;
//document.getElementById("surl").innerHTML = "https://dnut.000webhostapp.com/i.php/"+obj.surl ;
}
}
xmlhttp.open("POST","script/generatelink.php");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//console.log(jsn);
xmlhttp.send("url="+jsn);
}
function copy() {
/* Get the text field */
var copyText = document.getElementById("surl");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("Copied the text: " + copyText.value);
}
</script>
</body>
</html>