前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Native JS Timer

Native JS Timer

作者头像
Akilar
发布2021-06-11 11:13:48
7390
发布2021-06-11 11:13:48
举报
文章被收录于专栏:Akilarの糖果屋Akilarの糖果屋

魔改步骤

  1. 新建 [Blogroot]\themes\butterfly\source\js\runtime.js, 此处用到了 shield.io 生成徽标,更多内容请参看站内教程:博客添加 github 徽标方案
代码语言:javascript
复制
setInterval(() => {
  let create_time = Math.round(new Date('2019-04-17 00:00:00').getTime() / 1000); //在此行修改建站时间
  let timestamp = Math.round((new Date().getTime()) / 1000);
  let second = timestamp - create_time;
  let time = new Array(0, 0, 0, 0, 0);
  //格式规范化,个位数前面加0
  var nol = function(h){
    return h>9?h:'0'+h;
  }
  if (second >= 365 * 24 * 3600) {
    time[0] = parseInt(second / (365 * 24 * 3600));
    second %= 365 * 24 * 3600;
  }//年
  if (second >= 24 * 3600) {
    time[1] = parseInt(second / (24 * 3600));
    second %= 24 * 3600;
  }//天
  if (second >= 3600) {
    time[2] = nol(parseInt(second / 3600));
    second %= 3600;
  }//时
  if (second >= 60) {
    time[3] = nol(parseInt(second / 60));
    second %= 60;
  }//分
  if (second > 0) {
    time[4] = nol(second);
  }//秒
  //早上7点到晚上10点营业
  if ((Number(time[2])<22) && (Number(time[2])>7)){
    currentTimeHtml ="<img class='boardsign' src='https://img.shields.io/badge/糖果屋-营业中-6adea8?style=social&logo=cakephp' title='距离百年老店也就差不到一百年~'><div id='runtime'>" + time[0] + ' YEAR ' + time[1] + ' DAYS ' + time[2] + ' : ' + time[3] + ' : ' + time[4] + '</div>';
  } //徽标内容参考站内教程
  //其余时间打烊
  else{
    currentTimeHtml ="<img class='boardsign' src='https://img.shields.io/badge/糖果屋-打烊了-6adea8?style=social&logo=coffeescript' title='这个点了应该去睡觉啦,熬夜对身体不好哦'><div id='runtime'>" + time[0] + ' YEAR ' + time[1] + ' DAYS ' + time[2] + ' : ' + time[3] + ' : ' + time[4] + '</div>'; //徽标内容参考站内教程
  }
  //覆写挂载标签的内容
  document.getElementById("workboard").innerHTML = currentTimeHtml;
}, 1000);
  1. 修改 [Blogroot]\themes\butterfly\layout\includes\footer.pug, 添加计时器的挂载标签:
代码语言:javascript
复制
  if theme.footer.copyright
    .framework-info
      span= _p('footer.framework') + ' '
      a(href='https://hexo.io')= 'Hexo'
      span.footer-separator |
      span= _p('footer.theme') + ' '
      a(href='https://github.com/jerryc127/hexo-theme-butterfly')= 'Butterfly'
  if theme.footer.custom_text
    .footer_custom_text!=`${theme.footer.custom_text}`
+ #workboard
+ script(async src=url_for(theme.CDN.runtime))
  1. 新建 [Blogroot]\themes\butterfly\source\css\_layout\runtime.styl,
代码语言:javascript
复制
/*电子钟字体*/
@font-face
  font-family 'UnidreamLED'
  src url('https://cdn.jsdelivr.net/gh/Akilarlxh/Akilarlxh.github.io@v3.3.3_3/clock/fonts/UnidreamLED.ttf')
  font-display swap
//页脚计时器
div#runtime
  width 180px
  margin auto
  color white
  padding-inline 5px
  border-radius 10px
  background-color rgba(0,0,0,0.7)
  font-family 'UnidreamLED'

// 夜间全局透明度
[data-theme="dark"]
  div#runtime
      color rgb(40, 180, 200)
      box-shadow 0 0 5px rgba(28, 69, 218, 0.71)
      animation flashlight 1s linear infinite alternate
@keyframes flashlight
  from
    box-shadow 0 0 5px rgb(20, 120, 210)
  to
    box-shadow 0 0 2px rgb(20, 120, 210)
  1. 修改_config.butterfly.yml, 添加 CDN 链接:
代码语言:javascript
复制
  CDN:
    # main
    main_css: /css/index.css
    jquery: https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js
    main: /js/main.js
    utils: /js/utils.js
    # 页脚计时器
+   runtime: /js/runtime.js

TO DO

夜间模式适配

原生 js 实现

添加营业中,打烊了牌子

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-02-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 魔改步骤
  • TO DO
相关产品与服务
内容分发网络 CDN
内容分发网络(Content Delivery Network,CDN)通过将站点内容发布至遍布全球的海量加速节点,使其用户可就近获取所需内容,避免因网络拥堵、跨运营商、跨地域、跨境等因素带来的网络不稳定、访问延迟高等问题,有效提升下载速度、降低响应时间,提供流畅的用户体验。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档