Skip to content

Commit 42b4759

Browse files
saulcostafregante
authored andcommitted
Add support for personal access tokens (refined-github#1375)
1 parent 2e41923 commit 42b4759

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

source/background.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ new OptionsSync().define({
77
defaults: {
88
disabledFeatures: '',
99
customCSS: '',
10+
personalToken: '',
1011
logging: false
1112
},
1213
migrations: [

source/libs/api.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import OptionsSync from 'webext-options-sync';
2+
13
const cache = new Map();
24

35
export default async endpoint => {
46
if (cache.has(endpoint)) {
57
return cache.get(endpoint);
68
}
9+
const headers = {};
10+
const {personalToken} = await new OptionsSync().getAll();
11+
if (personalToken) {
12+
headers.Authorization = `token ${personalToken}`;
13+
}
714
const api = location.hostname === 'github.com' ? 'https://api.github.com/' : `${location.origin}/api/`;
8-
const response = await fetch(api + endpoint);
15+
const response = await fetch(api + endpoint, {headers});
916
const json = await response.json();
1017
cache.set(endpoint, json);
1118
return json;

source/options.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
body {
22
min-width: 430px; /* Required to size the Browser Action popup */
33
}
4+
:root {
5+
--github-green: #28a745;
6+
--github-red: #cb2431;
7+
}
8+
input:not([type='checkbox']):not(:placeholder-shown):valid {
9+
color: var(--github-green);
10+
border: 1px solid;
11+
}
12+
input:not([type='checkbox']):invalid {
13+
color: var(--github-red);
14+
border: 1px solid;
15+
}
16+
input:not([type='checkbox']),
417
textarea {
518
display: block;
619
width: 100%;

source/options.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ <h2 class="only-firefox">Options</h2>
2323
</label>
2424
</p>
2525

26+
<hr>
27+
28+
<p>
29+
<label>
30+
<strong>Personal token</strong>, <a href="https://github.com/settings/tokens/new?description=Refined%20GitHub" target="_blank">found here</a> (for high rate API calls and private repos)<br>
31+
<!-- placeholder is set to enable use of :placeholder-shown CSS selector -->
32+
<input name="personalToken" spellcheck="false" autocomplete="off" size="40" maxlength="40" pattern="[\da-f]{40}" placeholder=" "></input>
33+
</label>
34+
</p>
35+
36+
<hr>
37+
2638
<p>
2739
<label>
2840
<input type="checkbox" name="logging">

0 commit comments

Comments
 (0)