百度收录检测

handsome模板

1.在模板post.php加入

/*百度收录代码开始*/
<li class="meta-baidu"><span class="post-icons"><i class="glyphicon glyphicon-refresh" id="baidu_icon"></i></span><span class="meta-value" id="baidu_result">加载中</span></li>
/*百度收录代码结束*/

2.在post.php内加入(必须引入jquery)

/*百度收录代码开始*/
<script>
 function baidu_check(){
    $.getJSON("https://xiaochamao.com/api/baidu.php?domain="+window.location.href,function(result){ 
        if (result.code == 200) {
           $('#baidu_icon').removeClass('glyphicon-refresh');
           $('#baidu_icon').addClass('glyphicon-ok-circle');
           $('#baidu_result').text('百度已收录');
        }else if(result.code == 403){
           $('#baidu_icon').removeClass('glyphicon-refresh');
           $('#baidu_icon').addClass('glyphicon-info-sign');
           $('#baidu_result').text('百度未收录');
           baidu_push();
        }else{
            $('#baidu_icon').removeClass('glyphicon-refresh');
           $('#baidu_icon').addClass('glyphicon-remove-circle');
           $('#baidu_result').text('查询收录失败');
        }
    });
 }
 function baidu_push(){
    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);
 }
 baidu_check();
</script>
/*百度收录代码结束*/

3.pjax回调函数

/*百度收录代码开始*/
if((typeof baidu_check) !== "undefined"){
baidu_check();
}
/*百度收录代码结束*/

其他模板

1.在模板functions.php末尾合适处加入以下代码

/*百度收录代码开始*/
function baidu_check() {
 $url = baidu_url();
 $api = 'https://xiaochamao.com/api/baidu.php?domain='; //更改为你自己的API
 $result = json_decode(file_get_contents($api.$url));
 if($result['code'] == 200){
    echo '百度已收录';
 }elseif($result['code'] == 403){
    echo '<a style="color:red;" rel="external nofollow" title="点击提交收录" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.$url.'">百度未收录</a>';
 }else{
    echo '查询收录失败';
 }
}
function baidu_url(){
 if((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')){
    return 'https'.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 }else{
    return 'http'.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 }
}
/*百度收录代码结束*/

2.然后在你需要输出检测结果的地方加入<?php baidu_check(); ?>即可

API源码

<?php
/**
Baidu
@editer: Weifeng
@link: https://wfblog.net
@version: 1.0
*/
error_reporting(0);
header("Access-Control-Allow-Origin:*");
header('Content-type: application/json');
$domain = @$_GET['domain'];
if(!isset($domain) || empty($domain) || $domain==''){
 $data = array(
    "code" => false,
    "msg" => "未传入请求参数!"
 );
 echo json_encode($data,JSON_UNESCAPED_UNICODE);
 exit;
}
if(substr($domain, -1) == '/'){
 $domain = substr($domain,0,strlen($domain)-1);
}
$data = checkBaidu($domain);
echo json_encode($data,JSON_UNESCAPED_UNICODE);
function checkBaidu($url){
 $header = array(
    "Host:www.baidu.com",
    "Content-Type:application/x-www-form-urlencoded",//post请求
    "Connection: keep-alive",
    "Referer:https://www.baidu.com",
    "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36"
 );
 $url = 'https://www.baidu.com/s?ie=UTF-8&wd='.urlencode($url).'&usm=3&rsv_idx=2&rsv_page=1';
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $output = curl_exec($ch);
 curl_close($ch);
 if(strpos($output, '没有找到') || strpos($output, '很抱歉')){
    $data = array(
        "code" => 403,
        "msg" => "该域名暂时未被百度收录!"
    );
 }else{
    $number = GetBetween($output,'<span class="nums_text">百度为您找到相关结果约','个</span>');
    if(empty($number) || $number == 0){
        $number = GetBetween($output,'<b>找到相关结果数约','个</b></p>');
        if(empty($number) || $number == 0){
           $data = array(
              "code" => false,
              "msg" => "获取百度收录失败!"
           );
           return $data;
        }
    }
    $data = array(
        "code" => 200,
        "msg" => "该域名已被百度收录!",
        "number" => str_replace(',','',$number)
    );
 }
 return $data;
}
function GetBetween($content,$start,$end){
 $r = explode($start, $content);
 if (isset($r[1])){
    $r = explode($end, $r[1]);
    return $r[0];
 }
}
?>

响应耗时和访客总数

首先将以下代码加到/usr/themes/handsome/libs/Content.php中,放在class Content{}之前

/*访问总量代码开始*/
function theAllViews(){
    $db = Typecho_Db::get();
    $row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`');
        echo number_format($row[0]['SUM(VIEWS)']);
}
/*访问总量代码结束*/
/*响应时间代码开始*/
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime()  );
$timestart = $mtime[1] + $mtime[0];
return true; 
}
timer_start();
function timer_stop( $display = 0, $precision = 3  ) {
global $timestart, $timeend;
$mtime = explode( ' ', microtime()  );
$timeend = $mtime[1] + $mtime[0];
$timetotal = number_format( $timeend - $timestart, $precision  );
$r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
if ( $display  ) {
    echo $r;
}
return $r;
}
/*响应时间代码结束*/

然后在/usr/themes/handsome/component/sidebar.php文件内,找到博客信息下面添加以下代码

/*访客总数代码开始*/
<li class="list-group-item text-second"> <span class="blog-info-icons"> <i data-feather="users"></i></span>
<span class="badge
pull-right"><?php echo theAllViews();?></span><?php _me("访客总数") ?></li>
/*访客总数代码结束*/
/*响应耗时代码开始*/
<li class="list-group-item text-second"> <span class="blog-info-icons"> <i data-feather="refresh-ccw"></i></span>
<span class="badge
pull-right"><?php echo timer_stop();?></span><?php _me("响应耗时") ?></li>
/*响应耗时代码结束*/

handsome彩色标签云

打开后台-更改外观-设置外观-开发者设置-复制代码粘贴至自定义JavaScript即可
如果主题中启用了pjax,还需要将上面代码添加到pjax-pjax回调函数中。

/*彩色标签云代码开始*/
let tags = document.querySelectorAll("#tag_cloud-2 a");
let colorArr = ["#428BCA", "#AEDCAE", "#ECA9A7", "#DA99FF", "#FFB380", "#D9B999"];
tags.forEach(tag => {
tagsColor = colorArr[Math.floor(Math.random() * colorArr.length)];
tag.style.backgroundColor = tagsColor;
});
/*彩色标签云代码结束*/

handsome底部美化

原底部代码

</div><!-- /content -->
<footer id="footer" class="app-footer" role="footer">
 <div class="wrapper bg-light">
   <span class="pull-right hidden-xs text-ellipsis">
   <?php $this->options->BottomInfo(); ?>
   Powered by <a target="_blank" href="http://www.typecho.org">Typecho</a>&nbsp;|&nbsp;Theme by <a target="_blank"
                                                                               href="https://www.ihewro.com/archives/489/">handsome</a>
   </span>
    <span class="text-ellipsis">&copy;&nbsp;<?php echo date("Y");?> Copyright&nbsp;<?php
        $this->options->BottomleftInfo(); ?></span>
 </div>

修改后

/*handsome底部美化*/
</div><!-- /content -->
<footer id="footer" class="app-footer" role="footer">
 <!-- 底部信息 -->
 <div class="wrapper bg-light">
 <!-- 左侧底部 -->
<div class="github-badge">
<a href="./" title="©2020-2022&nbsp;小茶猫">
<span class="badge-subject">Copyright</span><span class="badge-value bg-blue">©2020-2022&nbsp;小茶猫</span>
</a>
</div>
&nbsp;|&nbsp;
<div class="github-badge">
<a href="http://www.miitbeian.gov.cn/" target="_blank" title="浙ICP备2020035411号-1" style="cursor: url(&quot;/usr/plugins/HoerMouse/static/image/dew/link.cur&quot;), pointer;">
<span class="badge-subject">浙ICP备</span><span class="badge-value bg-green">2020035411号-1</span>
</a>
</div>
      </span>
 </div>
<!-- /底部信息 --> 
/*handsome底部美化*/

css

/*底部页脚*/
.github-badge {
display: inline-block;
border-radius: 4px;
text-shadow: none;
font-size: 12px;
color: #fff;
line-height: 15px;
background-color: #abbac3;
margin-bottom: 5px
}
.github-badge .badge-subject {
display: inline-block;
background-color: #4d4d4d;
padding: 4px 4px 4px 6px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px
}
.github-badge .badge-value {
display: inline-block;
padding: 4px 6px 4px 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px
}
.github-badge .bg-blue {
background-color: #007ec6
}
.github-badge .bg-orange {
background-color: #ffa500
}
.github-badge .bg-red {
background-color: #f00
}
.github-badge .bg-green {
background-color: #3bca6e
}
.github-badge .bg-purple {
background-color: #ab34e9
}

顶部 RSS 图标

主图设置 – 高级设置 – 顶部导航按钮配置

{"name":"RSS","class":"fontello fontello-rss icon-fw","link":"https://xiaochamao.com/feed/","target":"_blank"}

404 自动返回首页

/usr/themes/handsome/404.php 文件 130 行左右添加以下代码
添加在<h1>404</h1>这行下面即可

<br> <small> <b>10</b>秒后自动返回···<br> <a href="#" onclick="javascript:history.go(-1);">立刻返回</a>

再在最后面</body>标签前添加以下代码

<script type="text/javascript"> onload = function(){setInterval(go, 1000);};var x=10; function go() {x--;if(x>0) {document.getElementById("sp").innerHTML = x;}else{history.go(-1);}} </script>

实际效果

评论添加一键打卡

第一步:打开 Handsome 主题目录下的 component/comments.php 文件,找到并删除如下内容:

                        <label class="padder-v-sm" for="comment"><?php _me("评论") ?>
                            <span class="required text-danger">*</span></label>
                        <textarea id="comment" class="textarea form-control OwO-textarea" name="text" rows="5" placeholder="<?php _me("说点什么吧……") ?>" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('submit').click();return false};"><?php $this->remember('text'); ?></textarea>
                        <div class="OwO padder-v-sm"></div>
                        <?php $options = mget(); if (in_array('ajaxComment', Utils::checkArray( $options->featuresetup))): ?>
                        <div class="secret_comment" id="secret_comment" data-toggle="tooltip"
                        data-original-title="<?php _me("开启该功能,您的评论仅作者和评论双方可见") ?>">

改后

            <label class="padder-v-sm" for="comment"><?php _me("评论") ?>
                            <span class="required text-danger">*</span></label>
                        <textarea id="comment" class="textarea form-control OwO-textarea" name="text" rows="5" placeholder="<?php _me("说点什么吧……") ?>" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('submit').click();return false};"><?php $this->remember('text'); ?></textarea>
                        <div class="OwO" style="display: inline;"></div>
                        <div class="OwO" title="打卡" style="display: inline;" onclick="javascript:SIMPALED.Editor.daka();this.style.display='none'"><div class="OwO-logo"><i class="fontello-pencil"></i><span class="OwOlogotext">打卡</span></div></div>
                        <div class="OwO" title="赞" style="display: inline;" onclick="javascript:SIMPALED.Editor.zan();this.style.display='none'"><div class="OwO-logo"><i class="glyphicon glyphicon-thumbs-up"></i><span class="OwOlogotext"></span></div></div>
                        <div class="OwO" title="踩" style="display: inline;" onclick="javascript:SIMPALED.Editor.cai();this.style.display='none'"><div class="OwO-logo"><i class="glyphicon glyphicon-thumbs-down"></i><span class="OwOlogotext"></span></div></div>
                        <?php $options = mget(); if (in_array('ajaxComment', Utils::checkArray( $options->featuresetup))): ?>
                        <div class="secret_comment" id="secret_comment" data-toggle="tooltip"
                        data-original-title="<?php _me("开启该功能,您的评论仅作者和评论双方可见") ?>">

第二步:在后台 --> 设置外观 --> 开发者设置 --> 自定义JavaScript PJAX回调函数 加入以下代码:

<!--评论一键打卡-->
function a(a, b, c) {
        if (document.selection) a.focus(), sel = document.selection.createRange(), c ? sel.text = b + sel.text + c : sel.text = b, a.focus();
        else if (a.selectionStart || "0" == a.selectionStart) {
            var l = a.selectionStart,
                m = a.selectionEnd,
                n = m;
            c ? a.value = a.value.substring(0, l) + b + a.value.substring(l, m) + c + a.value.substring(m, a.value.length) : a.value = a.value.substring(0, l) + b + a.value.substring(m, a.value.length);
            c ? n += b.length + c.length : n += b.length - m + l;
            l == m && c && (n -= c.length);
            a.focus();
            a.selectionStart = n;
            a.selectionEnd = n
        } else a.value += b + c, a.focus()
}
var b = (new Date).toLocaleTimeString(),
        c = document.getElementById("comment") || 0;
window.SIMPALED = {};
window.SIMPALED.Editor = {
    daka: function() {
        a(c, "滴!学生卡!打卡时间:" + b, ",请上车的乘客系好安全带~")
    },
    zan: function() {
        a(c, " 写得好好哟,我要给你生猴子!::funny:04:: ")
    },
    cai: function() {
        a(c, "骚年,我怀疑你写了一篇假的文章!::funny:03:: ")
    }
};

第三步:在后台 --> 设置外观 --> 开发者设置 --> 自定义CSS 加入以下代码:

/*评论一键打卡*/
.secret_comment {
    top: 5px;
}
.OwO.OwO-open .OwO-body {
    display:table
}
/*评论一键打卡*/
最后修改:2021 年 12 月 18 日
如果觉得我的文章对你有用,请随意赞赏