通过ajax查询文章页百度收录判断,优化加载白屏时间!

我用的是杨小杰API的接口,如果不喜欢可以自己做!

同样还是有js自动推送功能,可省去已被收录的文章进行反复推送的加载时间。

JS

$(function () {
    $.getJSON(‘https://api.yum6.cn/baidu/query.php?url='+window.location.href, function(json, textStatus) {
        if (json.state == 1) {
            $(‘#ae_bdcx’).html(‘本文已被百度收录!’);
            $(“#ae_bdcx”).attr(‘href’,’https://www.baidu.com/s?wd='+window.location.href);
        }else{
            $(‘#ae_bdcx’).html(‘坐等收录’);
            $(‘#ae_bdcx’).css(‘color’,’#ff0000’);
            $(‘#ae_bdcx’).attr(‘href’,’http://zhanzhang.baidu.com/sitesubmit/index?sitename='+window.location.href);
            var bp = document.createElement(‘script’);
            var curProtocol = window.location.protocol.split(‘:’)[0];
            if (curProtocol === ‘https’) {bp.src = ‘https://zz.bdstatic.com/linksubmit/push.js';} else {bp.src = ‘http://push.zhanzhang.baidu.com/push.js';} var s = document.getElementsByTagName(‘script’)[0];
            s.parentNode.insertBefore(bp, s);
        }
    }); 
 

HTML

<a id=”ae_bdcx” rel=”external nofollow” target=”_blank”></a>