-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbs.js
71 lines (67 loc) · 2.51 KB
/
bs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let res
function shorturl() {
if(document.querySelector("#text").value==""){
alert("Url不能为空!")
return
}
document.getElementById("searchbtn").disabled=true;
document.getElementById("searchbtn").innerHTML='<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>请稍等...';
fetch(window.location.pathname, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: document.querySelector("#text").value,mima: document.querySelector("#mm").value })
}).then(function(response) {
return response.json();
})
.then(function(myJson) {
res = myJson;
document.getElementById("searchbtn").disabled=false;
document.getElementById("searchbtn").innerHTML=' Shorten it';
if(res.key!=="")
document.getElementById("result").innerHTML="http://"+window.location.host+res.key;
$('#exampleModal').modal('show')
}).catch(function(err){alert("未知错误,请重试!");
console.log(err);
document.getElementById("searchbtn").disabled=false;
document.getElementById("searchbtn").innerHTML=' Shorten it';})
}
function copyurl (id, attr) {
let target = null;
if (attr) {
target = document.createElement('div');
target.id = 'tempTarget';
target.style.opacity = '0';
if (id) {
let curNode = document.querySelector('#' + id);
target.innerText = curNode[attr];
} else {
target.innerText = attr;
}
document.body.appendChild(target);
} else {
target = document.querySelector('#' + id);
}
try {
let range = document.createRange();
range.selectNode(target);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
console.log('Copy success')
} catch (e) {
console.log('Copy error')
}
if (attr) {
// remove temp target
target.parentElement.removeChild(target);
}
}
$(function () {
$('[data-toggle="popover"]').popover()
})
console.log("https://github.com/xyTom/Url-Shorten-Worker/")
let notice="Notice: This service is for demonstration purposes only and the generated short links will automatically expire after 24 hours."
if(window.location.host=="lnks.eu.org"){
document.getElementById("notice").innerHTML=notice
}