custom-1.js 1.0 KB

123456789101112131415161718192021222324
  1. if (!window.runningTime) {
  2. window.runningTime = () => {
  3. const infoBox = document.querySelector('.footer .website-info-box')
  4. const tempDiv = document.createElement('div');
  5. tempDiv.setAttribute('class', 'info-item default')
  6. infoBox.appendChild(tempDiv)
  7. const since = '2020-01-01 00:00:00'
  8. const formatTimestamp = (timestamp) => {
  9. const now = Date.now()
  10. const timeDiff = Math.abs(now - timestamp)
  11. const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24))
  12. const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
  13. const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60))
  14. const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000)
  15. return `${days} 天 ${hours} 小时 ${minutes} 分 ${seconds} 秒`
  16. }
  17. setInterval(() => {
  18. tempDiv.innerHTML = '本站已安全运行 ' + formatTimestamp(new Date(since).getTime())
  19. }, 1000)
  20. }
  21. }
  22. window.runningTime()