Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"select-dom": "^5.1.0",
"shorten-repo-url": "^1.5.3",
"tiny-version-compare": "^1.0.0",
"twas": "^2.1.1",
"webext-additional-permissions": "^0.1.0",
"webext-detect-page": "^1.0.3",
"webext-domain-permission-toggle": "^1.0.0",
Expand Down
24 changes: 18 additions & 6 deletions source/features/repo-age.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import twas from 'twas';
import React from 'dom-chef';
import select from 'select-dom';
import cache from 'webext-storage-cache';
import timeAgo from '../libs/time-ago';
import select from 'select-dom';
import elementReady from 'element-ready';
import features from '../libs/features';
import * as api from '../libs/api';
import * as icons from '../libs/icons';
import {getRepoGQL, getRepoURL} from '../libs/utils';

const dateFormatter = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});

const getRepoCreationDate = cache.function(async (): Promise<string> => {
const {repository} = await api.v4(`
repository(${getRepoGQL()}) {
Expand All @@ -16,23 +23,28 @@ const getRepoCreationDate = cache.function(async (): Promise<string> => {

return repository.createdAt;
}, {
expiration: 3,
cacheKey: () => __featureName__ + ':' + getRepoURL()
});

async function init(): Promise<void> {
const date = new Date(await getRepoCreationDate());
const {value, unit} = timeAgo(date);

// `twas` could also return `an hour ago` or `just now`
const [value, unit] = twas(date.getTime())
.replace('just now', '1 second')
.replace(/^an?/, '1')
.split(' ');

const element = (
<li title={`Repository created on ${date.toDateString()}`}>
<li title={`Repository created on ${dateFormatter.format(date)}`}>
<a className="text-gray"> {/* Required just to match GitHub’s style */}
{icons.repo()}
<span className="num text-emphasized">{value}</span> {unit} old
</a>
</li>
);

await elementReady('.overall-summary + *');
const license = select('.numbers-summary .octicon-law');
if (license) {
license.closest('li')!.before(element);
Expand All @@ -48,6 +60,6 @@ features.add({
include: [
features.isRepoRoot
],
load: features.onAjaxedPages,
load: features.nowAndOnAjaxedPages,
init
});
17 changes: 0 additions & 17 deletions source/libs/time-ago.tsx

This file was deleted.