Github format time

在 Github 的原始时间后添加一个格式化后的时间(24小时制)

当前为 2023-05-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Github format time
  3. // @name:en Github format time (24-hour system)
  4. // @name:zh-CN Github 格式化时间(24小时制)
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.1.2
  7. // @description 在 Github 的原始时间后添加一个格式化后的时间(24小时制)
  8. // @description:en Add a formatted time (24-hour system) after the original time of Github
  9. // @author Waset
  10. // @homepage https://gf.qytechs.cn/zh-CN/scripts/466416-github-format-time
  11. // @icon https://github.com/fluidicon.png
  12. // @match https://www.tampermonkey.net/scripts.php
  13. // @license MIT
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19. function convertDateFormat(dateString) {
  20. // 创建一个新的 Date 对象
  21. const date = new Date(dateString);
  22.  
  23. // 获取年份、月份和日期
  24. const year = date.getFullYear();
  25. const month = ('0' + (date.getMonth() + 1)).slice(-2);
  26. const day = ('0' + date.getDate()).slice(-2);
  27.  
  28. // 获取小时和分钟
  29. const hours = ('0' + date.getHours()).slice(-2);
  30. const minutes = ('0' + date.getMinutes()).slice(-2);
  31. const seconds = ('0' + date.getSeconds()).slice(-2);
  32.  
  33. // 拼接成新的格式
  34. const newDateFormat = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  35. return newDateFormat;
  36. }
  37. document.querySelectorAll('relative-time').forEach((item) => {
  38. var time = item.datetime;
  39.  
  40. var node = document.createElement('span');
  41. node.className = 'commit-ref';
  42. var str = convertDateFormat(time);
  43. var textnode = document.createTextNode(`${str}`);
  44. node.appendChild(textnode);
  45.  
  46. // 在 relative-time 元素之后插入新元素
  47. item.insertAdjacentElement('afterend', node);
  48. });
  49. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址