Skip to content

Instantly share code, notes, and snippets.

@anartzdev
Created November 8, 2022 08:02
Show Gist options
  • Save anartzdev/ea4974be8dfbd1dec97df9bad16373c1 to your computer and use it in GitHub Desktop.
Save anartzdev/ea4974be8dfbd1dec97df9bad16373c1 to your computer and use it in GitHub Desktop.
Chrome Extension Short URL
<!DOCTYPE html>
<html>
<head>
<title>Fast URL Shortener</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="box">
<h2>Fast URL Shortener</h2>
<input type="text" name="url" placeholder="Add original URL" id="url" />
<p id="result"></p>
<table>
<th>
<div class="button btn1" id="genShortUrl">Generate</div>
</th>
<th><a class="button btn2" id="copyShortUrl">Copy URL</a></th>
</table>
</div>
</body>
<script src="script.js"></script>
</html>
document.addEventListener('DOMContentLoaded', function () {
document
.getElementById('genShortUrl')
.addEventListener('click', async function () {
const dataInput = document.getElementById('url').value;
console.log(dataInput)
fetch(
'https://api.allorigins.win/raw?url=' +
'https://short-link-api.vercel.app/?query=' +
dataInput
)
.then((response) => response.json())
.then((json) => {
console.log(json['is.gd'])
document.getElementById('result').innerHTML = json['is.gd'];
});
});
document
.getElementById('copyShortUrl')
.addEventListener('click', function () {
const copyText = document.getElementById("password");
copyText.select();
copyText.setSelectionRange(0, 999);
document.execCommand("copy");
});
});
* {
margin: 0;
padding: 0;
user-select: none;
box-sizing: border-box;
}
body {
background-color: #0581ca;
justify-content: center;
align-items: center;
display: flex;
min-height: 100vh;
}
#result {
display: none
}
.box {
background-color: white;
padding-top: 30px;
padding: 30px;
max-width: 450px;
}
.box h2 {
margin-bottom: 40px;
text-align: center;
font-size: 26px;
color: #015a96;
font-family: sans-serif;
}
input {
padding: 20px;
user-select: none;
height: 50px;
width: 400px;
border-radius: 6px;
border: none;
border: 2px solid rgb(13, 152, 245);
outline: none;
font-size: 22px;
}
input::placeholder {
font-size: 23px;
}
.button {
font-family: sans-serif;
font-size: 15px;
margin-top: 40px;
border: 2px solid rgb(20, 139, 250);
width: 155px;
height: 50px;
text-align: center;
background-color: #0c81ee;
display: flex;
color: rgb(255, 255, 255);
justify-content: center;
align-items: center;
cursor: pointer;
border-radius: 7px;
}
.btn2 {
margin-left: 85px;
}
.button:hover {
color: white;
background-color: black;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment