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.6
  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. function createButton() {
  25. // Create a button element
  26. const button = document.createElement('button')
  27. button.textContent = '排序'
  28. button.style.position = 'fixed'
  29. button.style.top = '60px'
  30. button.style.right = '20px'
  31. button.style.zIndex = '9999'
  32.  
  33. // Append the button to the body
  34. document.body.appendChild(button)
  35.  
  36. // Add click event listener to the button
  37. button.addEventListener('click', performSortedAction)
  38. }
  39. function waitForElement(selector) {
  40. return new Promise((resolve) => {
  41. const observer = new MutationObserver(() => {
  42. if (document.querySelector(selector)) {
  43. resolve()
  44. observer.disconnect()
  45. }
  46. })
  47. observer.observe(document.body, { childList: true, subtree: true })
  48. })
  49. }
  50. function performSortedAction() {
  51.  
  52. var files = document.querySelector('[aria-labelledby="folders-and-files"] tbody')
  53. var children = [...files.children]
  54. files.replaceChildren(
  55. 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),
  56. )
  57. console.log('已按文件更新日期排序')
  58. }
  59. function WaitForRelativeTime() {
  60. waitForElement('relative-time').then(() => {
  61. performSortedAction()
  62. })
  63. }
  64. // Wait for the page to load
  65. window.addEventListener('load', WaitForRelativeTime)
  66.  
  67.  
  68. })()