-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
// wait for submit button to be clicked | ||
document.getElementById("myinput").onclick = function () { | ||
// get the link from the input | ||
var link = document.getElementById("linkinput").value; | ||
|
||
let api_url="https://api.short.io/links/lnk_2MDV_9dCPkoujKaJ"; | ||
|
||
|
||
// data to be sent to the API | ||
var data = { | ||
domain: "link.laavesh.ml", | ||
originalURL: link, | ||
allowDuplicates: false, | ||
}; | ||
|
||
|
||
// send the data to the API | ||
fetch(api_url, { | ||
method: "post", | ||
headers: { | ||
accept: "application/json", | ||
"Content-Type": "application/json", | ||
authorization: "sk_oNHGE7VRdKp0DWJc", | ||
}, | ||
body: JSON.stringify(data), | ||
}) | ||
// get the response from the API | ||
.then(function (response) { | ||
return response.json(); | ||
}) | ||
// display the shortened link | ||
.then(function (data) { | ||
if (data.error) { | ||
throw data.error; | ||
} | ||
// get shortened link | ||
let url = String(data.shortURL); | ||
// remove https:// | ||
url =url.replace("https://", ""); | ||
// display shortened link | ||
console.log(url); | ||
document.getElementById("message").innerHTML = url; | ||
}) | ||
// display error if any | ||
.catch(function (error) { | ||
console.log(error); | ||
document.getElementById("message").innerHTML = error; | ||
}); | ||
|
||
// clear the input fields | ||
document.getElementById("linkinput").value = ""; | ||
}; | ||
|
||
|
||
// Copy the link to the clipboard | ||
document.getElementById("copy").onclick = function () { | ||
// Get the text field | ||
var message = document.getElementById("message"); | ||
|
||
// get the link | ||
url = message.innerHTML; | ||
|
||
|
||
// Copy link to clipboard | ||
navigator.clipboard.writeText(url); | ||
|
||
// Alert copied to clipboard | ||
message.innerHTML = "Copied!"; | ||
console.log("Copied!"); | ||
|
||
// Change back to link after 800ms | ||
setTimeout(function () { | ||
message.innerHTML = url; | ||
}, 800); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!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"> | ||
<title>Shorten! from aviiciii</title> | ||
<link rel="stylesheet" href="styles.css" /> | ||
<link rel="icon" href="favicon.png" /> | ||
</head> | ||
|
||
<body> | ||
|
||
<!-- form --> | ||
<div class="login-box"> | ||
<form> | ||
|
||
<!-- long url --> | ||
<div class="user-box"> | ||
<input type="text" name="text" value id="linkinput" required="" /> | ||
<label>Url</label> | ||
</div> | ||
|
||
|
||
<!-- button --> | ||
<a href="#" id="myinput" value="Shorten"> | ||
<span></span> | ||
<span></span> | ||
<span></span> | ||
<span></span> | ||
Shorten | ||
</a> | ||
</form> | ||
|
||
<br> | ||
|
||
<!-- shortened url box --> | ||
<div class="msg row"> | ||
<div class="column left"> | ||
<p id="message">link.laavesh.ml/we </p> | ||
</div> | ||
<div class="column right"> | ||
<button name="copy" id="copy"><img src="copy.png" width="30px" alt="copy" /></button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- link script --> | ||
<script src="script-we.js"></script> | ||
|
||
</body> | ||
</html> |