Skip to content
Snippets Groups Projects
Verified Commit d4503150 authored by Jonas Leder's avatar Jonas Leder
Browse files

init

parents
No related branches found
No related tags found
No related merge requests found
node_modules/
\ No newline at end of file
icon/16.png

422 B

{
"manifest_version": 2,
"name": "URL Shorter",
"version": "1.0",
"description": "Short a URL with one click.",
"icons": {
"48": "icon/16.png"
},
"permissions": [
"activeTab",
"webRequest",
"*://jle.xyz/*"
],
"browser_action": {
"default_icon": "icon/16.png",
"default_popup": "popup.html",
"default_title": "URL Shorter"
}
}
\ No newline at end of file
{
"dependencies": {
"web-ext": "^7.2.0"
},
"scripts": {
"start": "web-ext run --verbose",
"build": "web-ext build"
}
}
<!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="popup.css">
</head>
<body>
<h1>URL Shorter</h1>
<input type="text" id="shortUrl">
<script src="./popup.js"></script>
</body>
</html>
\ No newline at end of file
popup.js 0 → 100644
$apiURL = "https://jle.xyz/user/api";
async function shortURL() {
const urlField = document.getElementById("shortUrl");
const [tab] = await browser.tabs.query({ currentWindow: true, active: true });
const url = tab.url;
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if(xhr.readyState == 4){
if(xhr.status == 200){
const response = JSON.parse(xhr.responseText);
urlField.value = response.url;
urlField.focus();
urlField.select();
} else {
alert("Error: " + xhr.status + "\n" + xhr.responseText);
}
}
};
xhr.open("POST", $apiURL, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ "long": url }));
}
shortURL();
\ No newline at end of file
input {
width: 100%;
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment