Created
February 18, 2019 11:21
-
-
Save Fraasi/34c83ecd4632771b66e416541b42017b to your computer and use it in GitHub Desktop.
Bookmarklet to get github repository creation time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
if (window.location.host !== 'github.com') { | |
alert('Not a GitHub page.'); | |
return; | |
} | |
if (window.location.pathname.split('/').length < 3) { | |
alert('Not in a repository page.'); | |
return; | |
} | |
function formatBytes(a, b) { if (0 == a) return "0 Bytes"; var c = 1024, d = b || 2, e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], f = Math.floor(Math.log(a) / Math.log(c)); return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f] } | |
const cleanRepoName = window.location.pathname.split('/').splice(0, 3).join('/'); | |
fetch(`https://api.github.com/repos${cleanRepoName}`) | |
.then(data => data.json()) | |
.then(json => { | |
console.log('Github repo alert json',json); | |
alert(`${cleanRepoName}\n\nCreated: ${new Date(json.created_at).toLocaleString('EN-GB')}\n\nSize: ${formatBytes(json.size*1024)}`) | |
}).catch(e => alert(`${e.message}.\nSee console for more info.`)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment