forked from bpceee/oldest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholdest.js
12 lines (12 loc) · 832 Bytes
/
oldest.js
1
2
3
4
5
6
7
8
9
10
11
12
(([_, repo, branch='master']) => {
fetch(`https://github.com/${repo}/tree/${branch}`)
.then(res => res.text())
.then(res => {
let mainDocument = new DOMParser().parseFromString(res, 'text/html');
let commitCount = mainDocument.evaluate('//span[@class="d-none d-sm-inline"]//strong', mainDocument.body).iterateNext().innerText;
commitCount = Number(commitCount.trim().replaceAll(',', ''));
let commitId = mainDocument.evaluate('//*[@class="f6 Link--secondary text-mono ml-2 d-none d-lg-inline"]', mainDocument.body).iterateNext().getAttribute("href").split('/').pop();
let url = `https://github.com/${repo}/commits/${branch}?after=${commitId}+${commitCount-10}`;
window.location = url;
})
})(window.location.pathname.match(/\/([^\/]+\/[^\/]+)(?:\/(?:tree|commits|blob)\/([^\/]+))?/));