请求失败后或者解析失败解析按钮允许重新解析!DOCTYPE htmlhtmlhead title视频解析title meta charset=utf-8 meta name=viewport content=width=device-width initial-scale=10 link rel=stylesheet href=stylecss script src=httpscodejquery
修改后的JavaScript代码:
$(document).ready(function() {
$('#submit').click(function() {
var url = $('#url').val().trim();
if (url == '') {
alert('请输入视频链接');
return false;
} else if (!isValidUrl(url)) {
alert('请输入有效的视频链接');
return false;
}
var api_url = 'https://ovoa.cc/api/Tencent_live.php?url=' + url;
$('.result').html('<p><strong>解析中,请稍等<span class="dots">...</span></strong></p>').show();
$('#copy').hide();
$.get(api_url, function(data) {
if (data.code == 200) {
$('.result').html('<p><strong>解析结果:</strong></p><p><a href="' + data.url + '">' + data.url + '</a></p>');
$('#copy').show();
} else {
$('.result').html('<p><strong>解析失败:</strong>' + data.msg + '</p>');
$('#submit').prop('disabled', false);
}
}).fail(function() {
$('.result').html('<p><strong>请求失败:</strong>请稍后再试</p>');
$('#submit').prop('disabled', false);
});
$(this).prop('disabled', true);
});
$('#clear').click(function() {
$('#url').val('');
$('.result').hide();
$('#copy').hide();
$('#submit').prop('disabled', false);
});
$('#copy').click(function() {
var url = $('.result a').attr('href');
if (url) {
navigator.clipboard.writeText(url);
}
});
function isValidUrl(url) {
var pattern = /^(http|https):\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(\/\S*)?$/;
return pattern.test(url);
}
if (!navigator.clipboard) {
$('#copy').prop('disabled', true);
}
});
主要改动如下:
- 在解析失败和请求失败的情况下,解析按钮需要重新启用,以允许重新解析。
- 在解析失败和请求失败的情况下,解析结果需要清空,并且复制按钮需要隐藏。
- 在解析失败和请求失败的情况下,解析按钮需要重新启用,以允许重新解析。
原文地址: https://www.cveoy.top/t/topic/bc2W 著作权归作者所有。请勿转载和采集!