`**之前添加以下代码 ``` ``` [/collapse] ### 时间流逝 [collapse status="false" title="时间流逝"] 将以下代码加到**/usr/themes/handsome/component/sidebar.php**,找到广告代码这里上面两行,放在``之后 **加入位置示例**  ```
``` 在主题目录**usr/themes/handsome/assets/js**新建一个js文件命名为**timeinfo.js**并把下面代码复制进去保存 ``` function init_life_time() { function getAsideLifeTime() { /* 当前时间戳 */ let nowDate = +new Date(); /* 今天开始时间戳 */ let todayStartDate = new Date(new Date().toLocaleDateString()).getTime(); /* 今天已经过去的时间 */ let todayPassHours = (nowDate - todayStartDate) / 1000 / 60 / 60; /* 今天已经过去的时间比 */ let todayPassHoursPercent = (todayPassHours / 24) * 100; $('#dayProgress .title span').html(parseInt(todayPassHours)); $('#dayProgress .progress .progress-inner').css('width', parseInt(todayPassHoursPercent) + '%'); $('#dayProgress .progress .progress-percentage').html(parseInt(todayPassHoursPercent) + '%'); /* 当前周几 */ let weeks = { 0: 7, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6 }; let weekDay = weeks[new Date().getDay()]; let weekDayPassPercent = (weekDay / 7) * 100; $('#weekProgress .title span').html(weekDay); $('#weekProgress .progress .progress-inner').css('width', parseInt(weekDayPassPercent) + '%'); $('#weekProgress .progress .progress-percentage').html(parseInt(weekDayPassPercent) + '%'); let year = new Date().getFullYear(); let date = new Date().getDate(); let month = new Date().getMonth() + 1; let monthAll = new Date(year, month, 0).getDate(); let monthPassPercent = (date / monthAll) * 100; $('#monthProgress .title span').html(date); $('#monthProgress .progress .progress-inner').css('width', parseInt(monthPassPercent) + '%'); $('#monthProgress .progress .progress-percentage').html(parseInt(monthPassPercent) + '%'); let yearPass = (month / 12) * 100; $('#yearProgress .title span').html(month); $('#yearProgress .progress .progress-inner').css('width', parseInt(yearPass) + '%'); $('#yearProgress .progress .progress-percentage').html(parseInt(yearPass) + '%'); } getAsideLifeTime(); setInterval(() => { getAsideLifeTime(); }, 1000); } init_life_time() ``` 以下代码放在 **后台-外观设置-开发者设置-自定义CSS** ``` /* 时间流逝 */ .sidebar-count .content { padding: 15px } .sidebar-count .content .item { margin-bottom: 15px } .sidebar-count .content .item:last-child { margin-bottom: 0 } .sidebar-count .content .item .title { font-size: 12px; color: var(--minor); margin-bottom: 5px; display: flex; align-items: center } .sidebar-count .content .item .title span { color: var(--theme); font-weight: 500; font-size: 14px; margin: 0 5px } .sidebar-count .content .item .progress { display: flex; align-items: center } .sidebar-count .content .item .progress .progress-bar { height: 10px; border-radius: 5px; overflow: hidden; background: var(--classC); width: 0; min-width: 0; flex: 1; margin-right: 5px } @keyframes progress { 0% { background-position: 0 0 } 100% { background-position: 30px 0 } } .sidebar-count .content .item .progress .progress-bar .progress-inner { width: 0; height: 100%; border-radius: 5px; transition: width 0.35s; -webkit-animation: progress 750ms linear infinite; animation: progress 750ms linear infinite } .sidebar-count .content .item .progress .progress-bar .progress-inner-1 { background: #bde6ff; background-image: linear-gradient(135deg, #50bfff 25%, transparent 25%, transparent 50%, #50bfff 50%, #50bfff 75%, transparent 75%, transparent 100%); background-size: 30px 30px } .sidebar-count .content .item .progress .progress-bar .progress-inner-2 { background: #ffd980; background-image: linear-gradient(135deg, #f7ba2a 25%, transparent 25%, transparent 50%, #f7ba2a 50%, #f7ba2a 75%, transparent 75%, transparent 100%); background-size: 30px 30px } .sidebar-count .content .item .progress .progress-bar .progress-inner-3 { background: #ffa9a9; background-image: linear-gradient(135deg, #ff4949 25%, transparent 25%, transparent 50%, #ff4949 50%, #ff4949 75%, transparent 75%, transparent 100%); background-size: 30px 30px } .sidebar-count .content .item .progress .progress-bar .progress-inner-4 { background: #67c23a; background-image: linear-gradient(135deg, #4f9e28 25%, transparent 25%, transparent 50%, #4f9e28 50%, #4f9e28 75%, transparent 75%, transparent 100%); background-size: 30px 30px } .sidebar-count .content .item .progress .progress-percentage { color: var(--info) } ``` 最后一步,将以下代码放在**后台-外观设置-开发者设置-自定义输出body尾部** ``` ``` [/collapse] ### 太空人表盘 [collapse status="false" title="太空人表盘"] 如添加了本帖中“时间流逝”则将以下代码加到“时间流逝”后面,否则将以下代码加到**/usr/themes/handsome/component/sidebar.php**,找到广告代码这里上面两行,放在``之后 **加入位置示例**  ``` ``` 在主题目录**usr/themes/handsome/assets/js**新建一个js文件命名为**timeGeneration.js**并把下面代码复制进去保存 ``` // 生成时间 农历 公历 时间 function TimeGeneration() { } TimeGeneration.prototype = { constructor: TimeGeneration, WEEKDAY_NAME: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"], NUMBER_STRING: "一二三四五六七八九十", MONTH_STRING: "正二三四五六七八九十冬腊", MONTH_ADD: [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], CALENDAR_DATA: [0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x415B5, 0x2B6, 0x957, 0x2092F, 0x497, 0x60C96, 0xD4A, 0xEA5, 0x50DA9, 0x5AD, 0x2B6, 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x4155B, 0x25D, 0x92D, 0x2192B, 0xA95, 0x71695, 0x6CA, 0xB55, 0x50AB5, 0x4DA, 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6, 0x414AE, 0xA57, 0x526, 0x31D26, 0xD95, 0x70B55, 0x56A, 0x96D, 0x5095D, 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54, 0xB6A, 0x612DA, 0x95B, 0x49B, 0x41497, 0xA4B, 0xA164B, 0x6A5, 0x6D4, 0x615B4, 0xAB6, 0x957, 0x5092F, 0x497, 0x64B, 0x30D4A, 0xEA5, 0x80D65, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95], _getBit: function (m, n) { return (m >> n) & 1; }, // 获取时间 array getTime: function () { var time = new Date(); return [parseInt(time.getHours() / 10), parseInt(time.getHours() % 10), parseInt(time.getMinutes() / 10), parseInt(time.getMinutes() % 10), parseInt(time.getSeconds() / 10), parseInt(time.getSeconds() % 10)] }, // 获取公历日期 array getDate: function () { var date = new Date(); return [ date.getMonth() + 1, date.getDate(), this.WEEKDAY_NAME[date.getDay()] ] }, // 获取农历日期 string getCalendarDate: function () { var calendar = new Date(); var tmp = calendar.getFullYear(); if (tmp < 1900) { tmp += 1900; } var total = (tmp - 1921) * 365 + Math.floor((tmp - 1921) / 4) + this.MONTH_ADD[calendar.getMonth()] + calendar.getDate() - 38; if (calendar.getFullYear() % 4 == 0 && calendar.getMonth() > 1) { total++; } var isEnd = false; var n, m, k for (m = 0; ; m++) { k = (this.CALENDAR_DATA[m] < 0xfff) ? 11 : 12; for (n = k; n >= 0; n--) { if (total <= 29 + this._getBit(this.CALENDAR_DATA[m], n)) { isEnd = true; break; } total = total - 29 - this._getBit(this.CALENDAR_DATA[m], n); } if (isEnd) break; } var month = k - n + 1; var day = total; if (k == 12) { if (month == Math.floor(this.CALENDAR_DATA[m] / 0x10000) + 1) { month = 1 - month; } if (month > Math.floor(this.CALENDAR_DATA[m] / 0x10000) + 1) { month--; } } var tmp = ""; if (month < 1) { tmp += "(闰)"; tmp += this.MONTH_STRING.charAt(-month - 1); } else { tmp += this.MONTH_STRING.charAt(month - 1); } tmp += "月"; tmp += (day < 11) ? "初" : ((day < 20) ? "十" : ((day < 30) ? "廿" : "三十")); if (day % 10 != 0 || day == 10) { tmp += this.NUMBER_STRING.charAt((day - 1) % 10); } return tmp; } } ``` 以下代码放在 **后台-外观设置-开发者设置-自定义CSS** ``` /* 太空人表盘 */ .jun-meter { position: relative; width: 195px; height: 195px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/ring.svg"); background-repeat: no-repeat; background-size: 100%; margin: auto; margin-top: 7%; } .jun-time-rect { position: absolute; width: 9px; height: 24px; left: 82.5px; top: 54px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/rect.svg"); background-size: 12px 12px; } .jun-time-h-h { position: absolute; width: 30px; height: 30px; left: 42px; top: 51px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-h-l { position: absolute; width: 30px; height: 30px; left: 60px; top: 51px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-m-h { position: absolute; width: 30px; height: 30px; left: 87px; top: 51px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-m-l { position: absolute; width: 30px; height: 30px; left: 105px; top: 51px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-s-h { position: absolute; width: 18px; height: 18px; left: 129px; top: 62.5px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-s-l { position: absolute; width: 18px; height: 18px; left: 141px; top: 62.4px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-calendar-date { position: absolute; width: 36px; height: 9px; left: 128px; top: 93px; line-height: 9px; font-size: 10px; transform: scale(0.83333); transform-origin: 0 0; white-space: nowrap; text-align: center; } .jun-date { position: absolute; width: 36px; height: 9px; left: 128px; top: 103.5px; line-height: 9px; font-size: 10px; transform: scale(0.83333); transform-origin: 0 0; white-space: nowrap; text-align: center; } .jun-human{ position: absolute; width: 45px; height: 45px; left: 70px; top: 84px; background-image: url("https://s3-us-east-1.ossfiles.com/itggcc/img/human.gif"); background-repeat: no-repeat; background-size: 100%; } ``` 在**/usr/themes/handsome/component**的**footer.php**文件最后的**``**之前添加以下代码 ``` ``` 最后一步,将以下代码放在**后台-外观设置-开发者设置-自定义输出body尾部** ``` ``` [/collapse] ### 添加左侧导航 [collapse status="false" title="添加左侧导航"] 以下代码放在**后台-外观设置-高级设置-左侧边栏导航**内容请自行更改 ``` {"name":"每日一读","class":"book-open","link":"/everyday.html","target":"_self"}, {"name":"IT哥哥Tools","class":"trello","link":"http://tool.itgg.cc","target":"_blank"}, ``` [/collapse] ### 信息统计增加全站字数、在线人数、响应耗时和访客总数 [collapse status="false" title="信息统计增加全站字数、在线人数、响应耗时和访客总数"] 首先将以下代码加到**/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; } /** * 全站字数 */ function allOfCharacters() { $chars = 0; $db = Typecho_Db::get(); $select = $db ->select('text')->from('table.contents'); $rows = $db->fetchAll($select); foreach ($rows as $row) { $chars += mb_strlen(trim($row['text']), 'UTF-8'); } $unit = ''; if($chars >= 10000) { $chars /= 10000; $unit = '万'; } else if($chars >= 1000) { $chars /= 1000; $unit = '千'; } $out = sprintf('%.2lf %s',$chars, $unit); return $out; } /** * 在线人数 */ function online_users() { $filename='online.txt'; //数据文件 $cookiename='Nanlon_OnLineCount'; //Cookie名称 $onlinetime=30; //在线有效时间 $online=file($filename); $nowtime=$_SERVER['REQUEST_TIME']; $nowonline=array(); foreach($online as $line){ $row=explode('|',$line); $sesstime=trim($row[1]); if(($nowtime - $sesstime)<=$onlinetime){ $nowonline[$row[0]]=$sesstime; } } if(isset($_COOKIE[$cookiename])){ $uid=$_COOKIE[$cookiename]; }else{ $vid=0; do{ $vid++; $uid='U'.$vid; }while(array_key_exists($uid,$nowonline)); setcookie($cookiename,$uid); } $nowonline[$uid]=$nowtime; $total_online=count($nowonline); if($fp=@fopen($filename,'w')){ if(flock($fp,LOCK_EX)){ rewind($fp); foreach($nowonline as $fuid=>$ftime){ $fline=$fuid.'|'.$ftime."\n"; @fputs($fp,$fline); } flock($fp,LOCK_UN); fclose($fp); } } echo "$total_online"; } ``` 然后在**/usr/themes/handsome/component/sidebar.php**文件内,找到合适和位置添加以下代码: 注:**``**处就是添加代码的地方,找到你想加的位置添加代码即可 `````` [/collapse] ### 彩色标签云 [collapse status="false" title="彩色标签云"] 以下代码放在 **后台-外观设置-开发者设置-自定义 JavaScript** ``` // 彩色标签云 let tags = document.querySelectorAll("#tag_cloud-2 a"); let infos = document.querySelectorAll(".badge"); let colorArr = ["#428BCA", "#AEDCAE", "#ECA9A7", "#DA99FF", "#FFB380", "#D9B999"]; tags.forEach(tag => { tagsColor = colorArr[Math.floor(Math.random() * colorArr.length)]; tag.style.backgroundColor = tagsColor; }); infos.forEach(info => { infosColor = colorArr[Math.floor(Math.random() * colorArr.length)]; info.style.backgroundColor = infosColor; }); function addNumber(a) { var length = document.getElementById("comment").value.length; if(length> 0){ document.getElementById("comment").focus() document.getElementById("comment").value += '\n' + a + new Date }else{ document.getElementById("comment").focus() document.getElementById("comment").value += a + new Date } } ``` 如果你博客开启了PJAX,需要在**PJAX回调函数**里面添加以下代码: ``` // 彩色标签云 let tags = document.querySelectorAll("#tag_cloud-2 a"); let infos = document.querySelectorAll(".badge"); let colorArr = ["#428BCA", "#AEDCAE", "#ECA9A7", "#DA99FF", "#FFB380", "#D9B999"]; tags.forEach(tag => { tagsColor = colorArr[Math.floor(Math.random() * colorArr.length)]; tag.style.backgroundColor = tagsColor; }); infos.forEach(info => { infosColor = colorArr[Math.floor(Math.random() * colorArr.length)]; info.style.backgroundColor = infosColor; }); function addNumber(a) { var length = document.getElementById("comment").value.length; if(length> 0){ document.getElementById("comment").focus() document.getElementById("comment").value += '\n' + a + new Date }else{ document.getElementById("comment").focus() document.getElementById("comment").value += a + new Date } } ``` [/collapse]
Loading...
Loading...
4 comments
我是新手,请问怎么能查找到--------模板文件/component/headnav.php文件中动态日历中------
模板目录里面找一下/component/headnav.php这个文件呢,找到你应该就懂了
⌇●﹏●⌇过来学习学习