- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgithubSorted.user.js
More file actions
Latest commit
45 lines (38 loc) · 1.65 KB
/
Copy pathgithubSorted.user.js
File metadata and controls
45 lines (38 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// ==UserScript==
// @name Github按文件更新日期排序
// @namespace https://github.com/androidcn/
// @version 1.1
// @description Github按文件更新日期排序...
// @author@Androidcn
// @match https://github.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant none
// @updateURL https://github.com/androidcn/userscripts/raw/main/githubSorted.user.js
// @downloadURL https://github.com/androidcn/userscripts/raw/main/githubSorted.user.js
// ==/UserScript==
(function(){
'use strict';
functioncreateButton(){
// Create a button element
constbutton=document.createElement('button');
button.textContent='排序';
button.style.position='fixed';
button.style.top='60px';
button.style.right='20px';
button.style.zIndex='9999';
// Append the button to the body
document.body.appendChild(button);
// Add click event listener to the button
button.addEventListener('click',performSortedAction);
}
functionperformSortedAction(){
varfiles=document.querySelector('[aria-labelledby="folders-and-files"] tbody');
varchildren=[...files.children];
files.replaceChildren(
children[0],...[...files.querySelectorAll('.react-directory-row')].sort((a,b)=>newDate(a.querySelector('relative-time').datetime)<newDate(b.querySelector('relative-time').datetime) ? 1 : -1),children.at(-1),
);
console.log('已按文件更新日期排序');
}
// Wait for the page to load
window.addEventListener('load',createButton);
})();