【Templater】时光进度

使用此模板可以插入如下格式的内容:

2024-05-08  08:26:19  
▓▓▓▓▓▓▓░░░░░░░░░░░░░  
YearProgress: 34.98%

使用等宽字体显示效果最好。

在插入内容同时,会将内容复制到剪切板,方便在各处分享(制造焦虑

模板如下:

<%*
  /**
   * 时光进度
   * @author: 稻米鼠
   * @description: 为笔记中插入纯文本时光进度条
   * @created: 2024-05-08
   * @updated: 2024-05-08
   * @version: 0.0.1
   */
  const now = new Date()
  const year = now.getFullYear()
  const dbNum = num => String(num).padStart(2, '0')
  const date = `${dbNum(now.getFullYear())}-${dbNum(now.getMonth() + 1)}-${dbNum(now.getDate())}`
  const time = `${dbNum(now.getHours())}:${dbNum(now.getMinutes())}:${dbNum(now.getSeconds())}`
  const progress = (now - new Date(`${year}-01-01`)) / (new Date(`${year + 1}-01-01`) - new Date(`${year}-01-01`))
  const progressBarLength = Math.round(progress / 0.05)
  const selection = tp.file.selection()
  const progressBar = ''.padEnd(progressBarLength, '▓') + ''.padEnd(20-progressBarLength, '░')
  const progressNum = (progress*100).toFixed(2)
  tR += `${date}  ${time}  \n`
        + `${progressBar}  \n`
        + `YearProgress: ${progressNum}%\n`
  const copiedStr = `${date}  ${time}\n`
    + `${progressBar}\n`
    + `YearProgress: ${progressNum}%`
  navigator.clipboard.writeText(copiedStr)
  new Notice(copiedStr)
%>
©2022~2024 稻米鼠. Last build at 2024-10-12 00:00:34