Skip to content

Commit eacb64c

Browse files
authored
Merge pull request #3 from riskers/0.0.3
0.0.3
2 parents 3b5a465 + 664e666 commit eacb64c

60 files changed

Lines changed: 1948 additions & 1042 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
# github-plus-extension
1+
# GithubX
22

3-
> Chrome Extension enhance github
3+
> Chrome Extension enhance Github
44
55
## Download
66

7-
https://chrome.google.com/webstore/detail/github-plus/nmcddfeclkbhehidjoadbmkaajoppapo
7+
[Chrome WebStore](https://chrome.google.com/webstore/detail/githubx/nmcddfeclkbhehidjoadbmkaajoppapo)
88

99
## Organize Your Github Stars
1010

1111
Tag and group your github stars:
1212

1313
![](https://i.imgur.com/dZlYXCi.png)
1414

15+
Popup window when you star a repo:
16+
17+
![](https://i.imgur.com/KOCn2xl.gif)
18+
1519
## Data is stored locally
1620

1721
Can't sync data with multi drive.
1822
Only Storaged on Local drive.
1923

2024
## TODO
2125

22-
* [0.0.2](https://github.com/riskers/github-plus-extension/projects/1)
2326
* [0.0.3](https://github.com/riskers/github-plus-extension/projects/3)
2427

25-
## Thanks
28+
## Thanks OpenSource and Free Services
2629

27-
* [hatchful](https://hatchful.shopify.com/): Create a Logo in Seconds
30+
* [hatchful](https://hatchful.shopify.com/): create a logo in a few seconds
2831
* [Dexie](https://dexie.org/): wondful IndexedDB lib
2932
* [MUI](https://mui.com/): my favorite React UI lib
33+
* [react-window](https://github.com/bvaughn/react-window): rendering large lists data
34+
* [octokit.js](https://github.com/octokit/octokit.js): GitHub API SDK
3035
* [react-chrome-boilerplate](https://github.com/riskers/react-chrome-boilerplate) I made for developing Chrome Extension in React

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"src/**/*.{ts,tsx}": "eslint"
1313
},
1414
"devDependencies": {
15+
"@octokit/types": "^6.34.0",
1516
"@types/chrome": "^0.0.179",
1617
"@types/react": "^17.0.39",
1718
"@types/react-dom": "^17.0.13",
@@ -58,15 +59,17 @@
5859
"@mui/material": "^5.6.0",
5960
"@mui/styles": "^5.6.0",
6061
"@reduxjs/toolkit": "^1.8.0",
62+
"ahooks": "^3.3.8",
6163
"classnames": "^2.3.1",
6264
"dexie": "^3.2.1",
6365
"dexie-relationships": "^1.2.11",
6466
"leancloud-storage": "^4.6.1",
67+
"octokit": "^1.7.1",
6568
"react": "^17.0.2",
6669
"react-dom": "^17.0.2",
6770
"react-markdown": "^8.0.0",
6871
"react-redux": "^7.2.6",
69-
"react-router-dom": "^4.3.1",
72+
"react-router-dom": "^6.3.0",
7073
"react-treebeard": "^3.2.4",
7174
"react-use": "^17.2.1",
7275
"react-window": "^1.8.6",

src/background/network.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { getRepoInfo } from '@/common/api';
1+
import { getRepoInfo, IStar } from '@/common/api';
22
import { getFullName } from '@/common/tools';
33
import {
44
INTERCEPT_GETSTARINFO_B2C,
55
INTERCEPT_STARADD_C2B,
66
ACTION_SHOW_OPTION_PAGE,
77
IAction,
88
INTERCEPT_STARADD_C2B_DONE,
9+
INTERCEPT_INTO_PAGE,
910
} from '@/content_script/hooks/oneway-message/message';
1011
import { getGroupList, IGroup } from '@/services/idb/group';
11-
import { addStar, delStar } from '@/services/idb/stars';
12+
import { addStar, delStar, getStarInfoByFullName } from '@/services/idb/stars';
1213
import { addSJT, deleteSJTBySid } from '@/services/idb/starsJTags';
1314
import { getTagsList, ITag } from '@/services/idb/tag';
1415

@@ -69,6 +70,51 @@ chrome.webRequest.onCompleted.addListener(
6970
},
7071
);
7172

73+
export interface IInterceptIntoPage {
74+
star: IStar;
75+
}
76+
77+
/**
78+
* into repo page intercept for add buttons
79+
*/
80+
chrome.webRequest.onCompleted.addListener(
81+
async (details) => {
82+
if (details.url.match(/\?/gi)) {
83+
return;
84+
}
85+
86+
const [tab] = await chrome.tabs.query({
87+
active: true,
88+
currentWindow: true,
89+
});
90+
91+
// console.log(tab);
92+
// console.log(details);
93+
94+
if (!tab) return;
95+
96+
const url = tab.url.replace('https://github.com/', '');
97+
const star = await getStarInfoByFullName(url);
98+
// console.log(star);
99+
100+
if (!star) return;
101+
102+
chrome.tabs.sendMessage<IAction<IInterceptIntoPage>>(tab.id, {
103+
type: INTERCEPT_INTO_PAGE,
104+
payload: {
105+
star,
106+
},
107+
});
108+
},
109+
{
110+
types: ['xmlhttprequest'],
111+
urls: ['*://api.github.com/repos/*/*'],
112+
},
113+
);
114+
115+
/**
116+
* message listener
117+
*/
72118
chrome.runtime.onMessage.addListener(async (request: IAction<any>) => {
73119
const { type } = request;
74120

src/common/api.ts

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
1-
import { DEFAULT_GROUP, IGroup } from '@/services/idb/group';
2-
import { ITag } from '@/services/idb/tag';
1+
import { IItem } from '@/options/components/mid';
2+
import { IGist } from '@/services/idb/gist';
3+
import { DEFAULT_GROUP } from '@/services/idb/group';
4+
import { getToken } from '@/services/idb/settings';
35

4-
export interface IGithubStarResponse {
5-
starred_at: string;
6-
repo: IRepo;
7-
}
6+
import { Octokit } from 'octokit';
87

98
export interface IRepo {
109
id: number;
1110
full_name: string;
1211
html_url: string;
1312
}
1413

15-
export interface IStar {
16-
readonly id: number;
14+
export interface IStar extends IItem {
1715
fullName: string;
18-
htmlUrl: string;
19-
groupId: number;
20-
createTime?: number;
21-
updateTime?: number;
22-
group?: IGroup;
23-
tags?: ITag[];
2416
}
2517

26-
export const getAllStarListFromGithub = async (username: string): Promise<IStar[]> => {
18+
export const getUserInfo = async () => {
19+
const token = await getToken();
20+
const octokit = new Octokit({ auth: token });
21+
return await octokit.rest.users.getAuthenticated();
22+
};
23+
24+
const getGistsList = async (page: number) => {
25+
const token = await getToken();
26+
const octokit = new Octokit({ auth: token });
27+
// https://docs.github.com/cn/rest/reference/gists#list-gists-for-the-authenticated-user
28+
const res = await octokit.request('GET /gists', {
29+
page,
30+
per_page: 20,
31+
});
32+
return res.data;
33+
};
34+
35+
export const getAllGistFromGithub = async () => {
2736
let page = 1;
2837
let ending = false;
29-
let res: IStar[] = [];
38+
let res: IGist[] = [];
3039

3140
while (!ending) {
32-
const pres: IGithubStarResponse[] = await getStarListFromGithub(username, page);
41+
const pres = await getGistsList(page);
3342

34-
const stars: IStar[] = pres.map((data) => {
43+
const gists: IGist[] = pres.map((data) => {
3544
return {
36-
id: data.repo.id,
37-
fullName: data.repo.full_name,
38-
htmlUrl: data.repo.html_url,
45+
_id: data.id,
3946
groupId: DEFAULT_GROUP.id,
47+
description: data.description,
48+
htmlUrl: data.html_url,
4049
createTime: Date.now(),
4150
updateTime: Date.now(),
4251
};
@@ -47,23 +56,50 @@ export const getAllStarListFromGithub = async (username: string): Promise<IStar[
4756
ending = true;
4857
}
4958

50-
res = res.concat(...stars);
59+
res = res.concat(...gists);
5160
}
5261

5362
return res;
5463
};
5564

56-
export const getStarListFromGithub = async (username: string, page: number): Promise<IGithubStarResponse[]> => {
57-
const url = `https://api.github.com/users/${username}/starred`;
58-
const response = await fetch(`${url}?page=${page}`, {
59-
headers: {
60-
Accept: 'application/vnd.github.v3.star+json',
61-
},
65+
export const getStarListFromGithub = async (page: number): Promise<IRepo[]> => {
66+
const token = await getToken();
67+
const octokit = new Octokit({ auth: token });
68+
69+
const res = await octokit.request(`GET /user/starred`, {
70+
page,
6271
});
72+
return res.data;
73+
};
6374

64-
if (response.ok) {
65-
return response.json();
75+
export const getAllStarListFromGithub = async (): Promise<IStar[]> => {
76+
let page = 1;
77+
let ending = false;
78+
let res: IStar[] = [];
79+
80+
while (!ending) {
81+
const pres = await getStarListFromGithub(page);
82+
83+
const stars: IStar[] = pres.map((data) => {
84+
return {
85+
id: data.id,
86+
fullName: data.full_name,
87+
htmlUrl: data.html_url,
88+
groupId: DEFAULT_GROUP.id,
89+
createTime: Date.now(),
90+
updateTime: Date.now(),
91+
};
92+
});
93+
94+
page++;
95+
if (pres.length === 0) {
96+
ending = true;
97+
}
98+
99+
res = res.concat(...stars);
66100
}
101+
102+
return res;
67103
};
68104

69105
export const getRepoInfo = async (fullName: string): Promise<Omit<IStar, 'groupId'>> => {
@@ -92,15 +128,19 @@ export interface IReadmeResponse {
92128
}
93129

94130
export const getRepoContent = async (fullname: string): Promise<IReadmeResponse> => {
95-
const url = `https://api.github.com/repos/${fullname}/readme`;
96-
97-
const response = await fetch(`${url}`, {
98-
headers: {
99-
Accept: 'application/vnd.github.v3+json',
100-
},
101-
});
102-
103-
if (response.ok) {
104-
return response.json();
105-
}
131+
const token = await getToken();
132+
const octokit = new Octokit({ auth: token });
133+
const res = await octokit.request(`GET /repos/${fullname}/readme`);
134+
return res.data;
135+
// const url = `https://api.github.com/repos/${fullname}/readme`;
136+
137+
// const response = await fetch(`${url}`, {
138+
// headers: {
139+
// Accept: 'application/vnd.github.v3+json',
140+
// },
141+
// });
142+
143+
// if (response.ok) {
144+
// return response.json();
145+
// }
106146
};

src/content_script/components/btn/index.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/content_script/components/btn/style.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/content_script/components/loading/index.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/content_script/components/loading/style.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/content_script/components/node/index.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/content_script/components/sizeObserver/index.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)