├── index.html ├── README.md └── main.js /index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
23 |
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | var endpoint = "https://www.jsonstore.io/8ba4fd855086288421f770482e372ccb5a05d906269a34da5884f39eed0418a1";
2 |
3 | function geturl(){
4 | var url = document.getElementById("urlinput").value;
5 | var protocol_ok = url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp://");
6 | if(!protocol_ok){
7 | newurl = "http://"+url;
8 | return newurl;
9 | }else{
10 | return url;
11 | }
12 | }
13 |
14 | function getrandom() {
15 | var text = "";
16 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
17 |
18 | for (var i = 0; i < 5; i++)
19 | text += possible.charAt(Math.floor(Math.random() * possible.length));
20 | return text;
21 | }
22 |
23 | function genhash(){
24 | if (window.location.hash == ""){
25 | window.location.hash = getrandom();
26 | }
27 | }
28 |
29 | function send_request(url) {
30 | this.url = url;
31 | $.ajax({
32 | 'url': endpoint + "/" + window.location.hash.substr(1),
33 | 'type': 'POST',
34 | 'data': JSON.stringify(this.url),
35 | 'dataType': 'json',
36 | 'contentType': 'application/json; charset=utf-8'
37 | })
38 | }
39 |
40 | function shorturl(){
41 | var longurl = geturl();
42 | genhash();
43 | send_request(longurl);
44 | }
45 |
46 | var hashh = window.location.hash.substr(1)
47 |
48 | if (window.location.hash != "") {
49 | $.getJSON(endpoint + "/" + hashh, function (data) {
50 | data = data["result"];
51 |
52 | if (data != null) {
53 | window.location.href = data;
54 | }
55 |
56 | });
57 | }
58 |
59 |
--------------------------------------------------------------------------------