Skip to content

Instantly share code, notes, and snippets.

@Fraasi
Created February 18, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fraasi/34c83ecd4632771b66e416541b42017b to your computer and use it in GitHub Desktop.
Save Fraasi/34c83ecd4632771b66e416541b42017b to your computer and use it in GitHub Desktop.
Bookmarklet to get github repository creation time.
(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