timeliness.js 1.1 KB

1234567891011121314151617181920212223
  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 article was published, the content may be outdated.' +
  14. '</p></p></div>');
  15. }
  16. })();
  17. var oldHost = "HEXO.".toLowerCase() + 'ruomil'.split('').reverse().join('') + '.' + "top"
  18. if (window.location.hostname !== oldHost && window.location.hostname !== "localhost") {
  19. var newUrl = "https://" + oldHost + window.location.pathname + window.location.search + window.location.hash;
  20. window.location.href = newUrl;
  21. }