Skip to content

Commit 49128b8

Browse files
committed
Merge branch 'master' into show-folder-sizes
# Conflicts: # src/inject.js
2 parents 0ea80e3 + b84b14b commit 49128b8

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

manifest.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "GitHub Repository Size",
3-
"version": "0.3.2",
3+
"version": "0.4.1",
44
"manifest_version": 2,
55
"description": "Automatically adds repository size to GitHub's repository summary",
66
"homepage_url": "https://github.com/harshjv/github-repo-size",
@@ -11,18 +11,18 @@
1111
"128": "icons/ghrs128.png"
1212
},
1313
"permissions": [
14-
"http://github.com/*",
15-
"https://github.com/*",
16-
"storage"
14+
"storage",
15+
"activeTab"
1716
],
1817
"background" : {
19-
"scripts" : [ "src/background.js" ]
18+
"scripts" : [
19+
"src/background.js"
20+
]
2021
},
2122
"content_scripts": [
2223
{
2324
"matches": [
24-
"http://github.com/*",
25-
"https://github.com/*"
25+
"*://github.com/*"
2626
],
2727
"js": [
2828
"src/inject.js"

src/background.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@
33
const GITHUB_TOKEN_KEY = 'x-github-token'
44
const TOKEN_FEATURE_INFORMATION_KEY = 'user-knows-token-feature'
55

6-
const setGithubToken = (key, cb) => {
6+
const storage = chrome.storage.sync || chrome.storage.local
7+
8+
function setGithubToken (key, cb) {
79
const obj = {}
810

911
obj[GITHUB_TOKEN_KEY] = key
1012

11-
chrome.storage.sync.set(obj, () => {
13+
storage.set(obj, function () {
1214
alert('Your Github token has been set successfully. Reload the Github page to see changes.')
1315

1416
cb()
1517
})
1618
}
1719

18-
const handleOldGithubToken = (cb) => {
19-
chrome.storage.sync.get(GITHUB_TOKEN_KEY, (storedData) => {
20+
function handleOldGithubToken (cb) {
21+
storage.get(GITHUB_TOKEN_KEY, function (storedData) {
2022
const oldGithubToken = storedData[GITHUB_TOKEN_KEY]
2123

2224
if (oldGithubToken) {
2325
if (confirm('You have already set your Github token. Do you want to remove it?')) {
24-
chrome.storage.sync.remove(GITHUB_TOKEN_KEY, () => {
26+
storage.remove(GITHUB_TOKEN_KEY, function () {
2527
alert('You have successfully removed Github token. Click extension icon again to set a new token.')
2628

2729
cb(false)
@@ -39,11 +41,11 @@ const userNowKnowsAboutGithubTokenFeature = (cb) => {
3941
const obj = {}
4042
obj[TOKEN_FEATURE_INFORMATION_KEY] = true
4143

42-
chrome.storage.sync.set(obj, cb)
44+
storage.set(obj, cb)
4345
}
4446

45-
const informUserAboutGithubTokenFeature = () => {
46-
chrome.storage.sync.get(TOKEN_FEATURE_INFORMATION_KEY, (storedData) => {
47+
function informUserAboutGithubTokenFeature () {
48+
storage.get(TOKEN_FEATURE_INFORMATION_KEY, function (storedData) {
4749
const userKnows = storedData[TOKEN_FEATURE_INFORMATION_KEY]
4850

4951
if (!userKnows) {
@@ -63,6 +65,8 @@ const informUserAboutGithubTokenFeature = () => {
6365
const askGithubToken = (cb) => {
6466
const githubToken = prompt('Please enter your Github token')
6567

68+
if (githubToken === null) return
69+
6670
if (githubToken) {
6771
setGithubToken(githubToken, cb)
6872
} else {

src/inject.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const API = 'https://api.github.com/repos/'
44
const LI_TAG_ID = 'github-repo-size'
55
const GITHUB_TOKEN_KEY = 'x-github-token'
66

7+
const storage = chrome.storage.sync || chrome.storage.local
8+
79
let githubToken
810

911
const isTree = (uri) => {
@@ -52,7 +54,7 @@ const getHumanReadableSizeObject = (bytes) => {
5254
}
5355

5456
const K = 1024
55-
const MEASURE = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
57+
const MEASURE = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
5658
const i = Math.floor(Math.log(bytes) / Math.log(K))
5759

5860
return {
@@ -73,15 +75,13 @@ const getSizeHTML = (size) => {
7375
const humanReadableSize = getHumanReadableSizeObject(size)
7476

7577
return '<li id="' + LI_TAG_ID + '">' +
76-
'<a>' +
7778
'<svg class="octicon octicon-database" aria-hidden="true" height="16" version="1.1" viewBox="0 0 12 16" width="12">' +
7879
'<path d="M6 15c-3.31 0-6-.9-6-2v-2c0-.17.09-.34.21-.5.67.86 3 1.5 5.79 1.5s5.12-.64 5.79-1.5c.13.16.21.33.21.5v2c0 1.1-2.69 2-6 2zm0-4c-3.31 0-6-.9-6-2V7c0-.11.04-.21.09-.31.03-.06.07-.13.12-.19C.88 7.36 3.21 8 6 8s5.12-.64 5.79-1.5c.05.06.09.13.12.19.05.1.09.21.09.31v2c0 1.1-2.69 2-6 2zm0-4c-3.31 0-6-.9-6-2V3c0-1.1 2.69-2 6-2s6 .9 6 2v2c0 1.1-2.69 2-6 2zm0-5c-2.21 0-4 .45-4 1s1.79 1 4 1 4-.45 4-1-1.79-1-4-1z"></path>' +
7980
'</svg>' +
8081
'<span class="num text-emphasized"> ' +
8182
humanReadableSize.size +
8283
'</span> ' +
8384
humanReadableSize.measure +
84-
'</a>' +
8585
'</li>'
8686
}
8787

@@ -126,8 +126,9 @@ const getAPIData = (uri, callback) => {
126126
const getFileName = (text) => text.trim().split('/')[0]
127127

128128
const checkForRepoPage = () => {
129-
const repoURI = window.location.pathname.substring(1)
130-
const repoPath = repoURI.split('/').splice(4).join('/').trim()
129+
let repoURI = window.location.pathname.substring(1)
130+
repoURI = repoURI.endsWith('/') ? repoURI.slice(0, -1) : repoURI
131+
let repoPath = repoURI.split('/').splice(4).join('/').trim()
131132

132133
if (isTree(repoURI)) {
133134
const ns = document.querySelector('ul.numbers-summary')
@@ -173,7 +174,7 @@ const checkForRepoPage = () => {
173174
}
174175
}
175176

176-
chrome.storage.sync.get(GITHUB_TOKEN_KEY, (data) => {
177+
storage.get(GITHUB_TOKEN_KEY, function (data) {
177178
githubToken = data[GITHUB_TOKEN_KEY]
178179

179180
chrome.storage.onChanged.addListener((changes, namespace) => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy