auto copy url

parent dd0b182c
Pipeline #19 canceled with stages
......@@ -3,8 +3,8 @@
"name" : "Shorten URL",
"description" : "Create shortened URL from long URL",
"homepage_url": "http://url.itunix.eu/",
"version": "1.1.1",
"homepage_url": "https://url.itunix.eu/",
"version": "1.2",
"icons": {
"48": "icons/icon-48.png",
......@@ -20,7 +20,8 @@
},
"permissions": [
"https://url.itunix.eu/",
"tabs"
"tabs",
"clipboardWrite"
]
}
......@@ -12,15 +12,16 @@
<body>
<section class="flexbox" id="short_menu" style="display: none;">
<input type="text" placeholder="URL to Shorten" id="urltext" />
<input type="text" placeholder="URL to shortening" id="urltext" />
<button id="urlclick" class="button">Submit</button>
<p id="demo">Past URL in text box and click submit</p>
<input type="text" id="shorturl" style="display:none;" />
<p id="info">Past URL in text box and click submit</p>
</section>
<section class="flexbox" id="setapi">
<input type="text" placeholder="API Key" id="apikey" />
<button id="apiclick" class="button">Save</button>
<p id="demo">Enter your api key to get started</p>
<p id="info">Enter your api key to get started</p>
</section>
<button id="clearapi" style="display: none;">Remove Api-Key</button>
......
......@@ -7,14 +7,9 @@ document.getElementById("clearapi").addEventListener("click", clearApi);
var apikey = localStorage.getItem('apikey');
if (apikey != null) {
var menu = document.getElementById("short_menu");
menu.setAttribute("style","display:block;");
var setapi = document.getElementById("setapi");
setapi.setAttribute("style","display:none;");
var clearapi = document.getElementById("clearapi");
clearapi.setAttribute("style","display:block;");
document.getElementById("short_menu").setAttribute("style","display:block;");
document.getElementById("setapi").setAttribute("style","display:none;");
document.getElementById("clearapi").setAttribute("style","display:block;");
}
browser.tabs.query({currentWindow: true, active: true})
......@@ -31,35 +26,32 @@ function short() {
function saveapi() {
var apikey = document.getElementById("apikey").value;
localStorage.setItem('apikey', apikey);
document.location.reload(true);
}
function clearApi() {
localStorage.removeItem('apikey');
document.location.reload(true);
}
function shortUrl(apikey, long_url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
// if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
if (this.status == 200 || this.status == 201) {
document.getElementById("shorturl").value = this.responseText;
document.getElementById("shorturl").setAttribute("style","display:block;");
copyToClipboard();
} else {
document.getElementById("info").innerHTML = this.responseText;
}
};
}
xhttp.open("POST", "https://url.itunix.eu/short", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("long_url="+long_url+"&apikey="+apikey);
}
/*
function short() {
var long_url = document.getElementById("urltext").value;
var apikey = localStorage.getItem('apikey');
regexp = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
if (regexp.test(long_url)) {
shortUrl(apikey, long_url);
} else {
document.getElementById("demo").innerHTML = long_url + " is not a valid URL";
}
}
*/
\ No newline at end of file
function copyToClipboard() {
var copyText = document.getElementById("shorturl");
copyText.select();
document.execCommand("copy");
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment