修复由切换qq头像和gravatar头像导致的报错问题

This commit is contained in:
Parasomnia 2020-03-06 17:59:17 +08:00
parent ccb0b6f5da
commit aa221716b1
1 changed files with 45 additions and 42 deletions

View File

@ -864,53 +864,56 @@ function getqqinfo() {
} }
var emailAddressFlag = cached.filter('#email').val(); var emailAddressFlag = cached.filter('#email').val();
cached.filter('#author').on('blur', function () { cached.filter('#author').on('blur', function () {
var qq = cached.filter('#author').val(); var qq = cached.filter('#author').val(),
$.ajax({ $reg = /^[1-9]\d{4,9}$/;
type: 'get', if ($reg.test(qq)) {
url: mashiro_option.qq_api_url + '?qq=' + qq + '&_wpnonce=' + Poi.nonce, $.ajax({
dataType: 'json', type: 'get',
success: function (data) { url: mashiro_option.qq_api_url + '?qq=' + qq + '&_wpnonce=' + Poi.nonce,
cached.filter('#author').val(data.name); dataType: 'json',
cached.filter('#email').val($.trim(qq) + '@qq.com'); success: function (data) {
if (mashiro_option.qzone_autocomplete) { cached.filter('#author').val(data.name);
cached.filter('#url').val('https://user.qzone.qq.com/' + $.trim(qq)); cached.filter('#email').val($.trim(qq) + '@qq.com');
} if (mashiro_option.qzone_autocomplete) {
$('div.comment-user-avatar img').attr('src', 'https://q2.qlogo.cn/headimg_dl?dst_uin=' + qq + '&spec=100'); cached.filter('#url').val('https://user.qzone.qq.com/' + $.trim(qq));
is_get_by_qq = true; }
cached.filter('#qq').val($.trim(qq)); $('div.comment-user-avatar img').attr('src', 'https://q2.qlogo.cn/headimg_dl?dst_uin=' + qq + '&spec=100');
if (cached.filter('#qq').val()) { is_get_by_qq = true;
$('.qq-check').css('display', 'block'); cached.filter('#qq').val($.trim(qq));
$('.gravatar-check').css('display', 'none'); if (cached.filter('#qq').val()) {
} $('.qq-check').css('display', 'block');
setCookie('user_author', data.name, 30); $('.gravatar-check').css('display', 'none');
setCookie('user_qq', qq, 30); }
setCookie('is_user_qq', 'yes', 30); setCookie('user_author', data.name, 30);
setCookie('user_qq_email', qq + '@qq.com', 30); setCookie('user_qq', qq, 30);
setCookie('user_email', qq + '@qq.com', 30); setCookie('is_user_qq', 'yes', 30);
emailAddressFlag = cached.filter('#email').val(); setCookie('user_qq_email', qq + '@qq.com', 30);
/***/ setCookie('user_email', qq + '@qq.com', 30);
$('div.comment-user-avatar img').attr('src', data.avatar); emailAddressFlag = cached.filter('#email').val();
setCookie('user_avatar', data.avatar, 30); /***/
}, $('div.comment-user-avatar img').attr('src', data.avatar);
error: function () { setCookie('user_avatar', data.avatar, 30);
cached.filter('#qq').val(''); },
$('.qq-check').css('display', 'none'); error: function () {
$('.gravatar-check').css('display', 'block'); cached.filter('#qq').val('');
$('div.comment-user-avatar img').attr('src', get_gravatar(cached.filter('#email').val(), 80));
setCookie('user_qq', '', 30);
setCookie('user_email', cached.filter('#email').val(), 30);
setCookie('user_avatar', get_gravatar(cached.filter('#email').val(), 80), 30);
/***/
cached.filter('#qq,#email,#url').val('');
if (!cached.filter('#qq').val()) {
$('.qq-check').css('display', 'none'); $('.qq-check').css('display', 'none');
$('.gravatar-check').css('display', 'block'); $('.gravatar-check').css('display', 'block');
setCookie('user_qq', '', 30);
$('div.comment-user-avatar img').attr('src', get_gravatar(cached.filter('#email').val(), 80)); $('div.comment-user-avatar img').attr('src', get_gravatar(cached.filter('#email').val(), 80));
setCookie('user_qq', '', 30);
setCookie('user_email', cached.filter('#email').val(), 30);
setCookie('user_avatar', get_gravatar(cached.filter('#email').val(), 80), 30); setCookie('user_avatar', get_gravatar(cached.filter('#email').val(), 80), 30);
/***/
cached.filter('#qq,#email,#url').val('');
if (!cached.filter('#qq').val()) {
$('.qq-check').css('display', 'none');
$('.gravatar-check').css('display', 'block');
setCookie('user_qq', '', 30);
$('div.comment-user-avatar img').attr('src', get_gravatar(cached.filter('#email').val(), 80));
setCookie('user_avatar', get_gravatar(cached.filter('#email').val(), 80), 30);
}
} }
} });
}); }
// $.ajax({ // $.ajax({
// type: 'get', // type: 'get',
// url: mashiro_option.qq_avatar_api_url + '?type=getqqavatar&qq=' + qq, // url: mashiro_option.qq_avatar_api_url + '?type=getqqavatar&qq=' + qq,