GitHub 按日期排序

将文件排序方式改为日期降序,方便查看最新更新的文件。

当前为 2024-08-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Sort by Date
  3. // @name:zh-CN GitHub 按日期排序
  4. // @name:vi GitHub Sắp xếp theo Ngày
  5. // @name:ja GitHub 日付順ソート
  6. // @name:ko GitHub 날짜별 정렬
  7. // @description Change the file sorting order to descending by date for easier viewing of the most recently updated files.
  8. // @description:zh-CN 将文件排序方式改为日期降序,方便查看最新更新的文件。
  9. // @description:vi Thay đổi thứ tự sắp xếp tệp thành giảm dần theo ngày để dễ dàng xem các tệp được cập nhật gần đây nhất.
  10. // @description:ja ファイルの並び順を日付の降順に変更し、最新の更新ファイルを簡単に確認できるようにします。
  11. // @description:ko 파일 정렬 순서를 날짜 내림차순으로 변경하여 가장 최근에 업데이트된 파일을 쉽게 확인할 수 있습니다。
  12. // @namespace https://github.com/ChinaGodMan/UserScripts
  13. // @version 1.1.0.5
  14. // @author @Androidcn ,人民的勤务员 <toniaiwanowskiskr47@gmail.com>
  15. // @match https://github.com/*
  16. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  17. // @grant none
  18. // @supportURL https://github.com/ChinaGodMan/UserScripts/issues
  19. // @homepageURL https://github.com/ChinaGodMan/UserScripts
  20. // @license MIT
  21. // ==/UserScript==
  22. (function () {
  23. 'use strict'
  24.  
  25. function createButton() {
  26. // Create a button element
  27. const button = document.createElement('button')
  28. button.textContent = '排序'
  29. button.style.position = 'fixed'
  30. button.style.top = '60px'
  31. button.style.right = '20px'
  32. button.style.zIndex = '9999'
  33.  
  34. // Append the button to the body
  35. document.body.appendChild(button)
  36.  
  37. // Add click event listener to the button
  38. button.addEventListener('click', performSortedAction)
  39. }
  40. function waitForElement(selector) {
  41. return new Promise((resolve) => {
  42. const observer = new MutationObserver(() => {
  43. if (document.querySelector(selector)) {
  44. resolve()
  45. observer.disconnect()
  46. }
  47. })
  48. observer.observe(document.body, { childList: true, subtree: true })
  49. })
  50. }
  51. function performSortedAction() {
  52.  
  53. var files = document.querySelector('[aria-labelledby="folders-and-files"] tbody')
  54. var children = [...files.children]
  55. files.replaceChildren(
  56. children[0], ...[...files.querySelectorAll('.react-directory-row')].sort((a, b) => new Date(a.querySelector('relative-time').datetime) < new Date(b.querySelector('relative-time').datetime) ? 1 : -1), children.at(-1),
  57. )
  58. console.log('已按文件更新日期排序')
  59. }
  60. function WaitForRelativeTime() {
  61. waitForElement('relative-time').then(() => {
  62. performSortedAction()
  63. })
  64. }
  65. // Wait for the page to load
  66. window.addEventListener('load', WaitForRelativeTime)
  67.  
  68.  
  69. })()