2020-11-24 22:38:16 +08:00

61 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
=========================================================
* PT短网址- v1.0.0
=========================================================
* Product Page: https://github.com/xuhuai66/pt-dwz
* Copyright 2020 Xuhuai (https://www.zhai78.com)
* Coded by Xuhuai
*/
function initial() {
document.getElementById('copyLink').innerText = '复制链接';  
$('#resultBox').css('display', 'none');
$('#desBox').css('display', 'block');
$('#loadingBox').css('display', 'block');
}
function checkUrl(url, type) {
var url_test = /^(http|https):\/\/.*$/i.test(url);
if (!url_test) {
document.getElementById('errTip').innerText = '链接有误请检查后再提交';
$('#errPop').modal('show');
} else {
fetch(window.location.origin + '/insert', {
body: JSON.stringify({url}), // must match 'Content-Type' header
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, same-origin, *omit
headers: {
'user-agent': 'Mozilla/4.0 MDN Example',
'content-type': 'application/json'
},
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, cors, *same-origin
redirect: 'follow', // manual, *follow, error
referrer: 'no-referrer', // *client, no-referrer
}).then(response => response.json()).then(res => {
initial()
$('#loadingBox').css('display', 'none');
document.getElementById('resultLink').innerText = window.location.origin + '/' + res.tail
$('#resultBox').css('display', 'block');
$('#desBox').css('display', 'none');
}).catch(err => {
console.log(err)
document.getElementById('errTip').innerText = '转换失败';
$('#errPop').modal('show');
})
}
}
function setBoard() {
var clipboard = new ClipboardJS("#copyLink");
clipboard.on("success", function(element) { //复制成功的回调
document.getElementById('copyLink').innerText = '复制成功';  
console.info("复制成功,复制内容: " + element.text);
});
clipboard.on("error", function(element) { //复制失败的回调
console.info(element);
});
}
$(function() {
setBoard();
});