timeliness.js 815 B

1234567891011121314151617
  1. (function() {
  2. var times = document.getElementsByTagName('time');
  3. if (times.length === 0) { return; }
  4. var posts = document.getElementsByClassName('post-content');
  5. if (posts.length === 0) { return; }
  6. var pubTime = new Date(times[0].dateTime); /* 文章发布时间戳 */
  7. var now = Date.now() /* 当前时间戳 */
  8. var interval = parseInt(now - pubTime)
  9. /* 发布时间超过指定时间(毫秒) */
  10. if (interval > 3600*24*30*1000){
  11. var days = parseInt(interval / 86400000)
  12. posts[0].insertAdjacentHTML('afterbegin', '<div class="note note-warning" style="font-size:0.9rem"><p>' +
  13. '<div class="h6">Article Timeliness Reminder</div><p>It has been ' + days + ' days since the last update, the content may be outdated.' +
  14. '</p></p></div>');
  15. }
  16. })();