├── README.md └── oldest.js /README.md: -------------------------------------------------------------------------------- 1 | OLDEST 2 | ==== 3 | A bookmarklet to quickly get you to the oldest commit page of a repo. 4 | 5 | ### Overview 6 | 7 | Being able to quickly navigate to the oldest commit page in a repo is quite helpful. Go ahead and drag the [bookmarklet (link)](http://bpceee.github.io/oldest/) onto your bookmark bar and click it whenever you'd like to go to the first commit page of a repo. 8 | 9 | ### Credits 10 | * Inspired by [INIT](https://github.com/FarhadG/init). However there is a limitation on api.github.com calls, so this bookmarklet parses the main page to get the commitID and count. 11 | 12 | * Use https://mrcoles.com/bookmarklet/ as a bookmarklet creator -------------------------------------------------------------------------------- /oldest.js: -------------------------------------------------------------------------------- 1 | (([_, repo]) => { 2 | const branchElement = document.querySelector("#branch-select-menu > summary > span.css-truncate-target"); 3 | const branch = branchElement ? branchElement.textContent : 'master'; 4 | fetch(`https://github.com/${repo}/tree/${branch}`) 5 | .then(res => res.text()) 6 | .then(res => { 7 | const mainDocument = new DOMParser().parseFromString(res, 'text/html'); 8 | let commitCount = mainDocument.evaluate('//span[@class="d-none d-sm-inline"]//strong', mainDocument.body).iterateNext().innerText; 9 | commitCount = Number(commitCount.trim().replaceAll(',', '')); 10 | const commitId = mainDocument 11 | .evaluate('//*[@class="f6 Link--secondary text-mono ml-2 d-none d-lg-inline"]', mainDocument.body) 12 | .iterateNext() 13 | .getAttribute("href") 14 | .split('/') 15 | .pop(); 16 | const url = `https://github.com/${repo}/commits/${branch}?after=${commitId}+${commitCount-10}`; 17 | window.location = url; 18 | }) 19 | })(window.location.pathname.match(/\/([^\/]+\/[^\/]+)(?:\/(?:tree|commits|blob)\/([^\/]+))?/)); 20 | --------------------------------------------------------------------------------