Github format time

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

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

QingJ © 2025

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