Skip to content

Commit f1f3b74

Browse files
committed
Add project files.
1 parent e57ab29 commit f1f3b74

File tree

13 files changed

+246
-0
lines changed

13 files changed

+246
-0
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
dist
11+
12+
# misc
13+
.DS_Store
14+
15+
# local env files
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
# lock files
22+
yarn.lock
23+
package-lock.json
24+
25+
# debug files
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# extension.js
31+
extension-env.d.ts
32+
33+
# IDE files
34+
.idea/
35+
.vs/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ghcss-extension
2+
3+
A simple extension that allows users to view custom css on GitHub profiles.

images/extension_128.png

11 KB
Loading

images/extension_48.png

3.55 KB
Loading

manifest.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"manifest_version": 3,
3+
"version": "1.0",
4+
"name": "ghcss-extension",
5+
"description": "A simple extension that allows users to view custom css on GitHub profiles.",
6+
"author": "Bims-sh",
7+
"permissions": [
8+
"activeTab",
9+
"tabs",
10+
"storage"
11+
],
12+
"icons": {
13+
"48": "images/extension_48.png",
14+
"128": "images/extension_128.png"
15+
},
16+
"background": {
17+
"chromium:service_worker": "src/background.ts",
18+
"firefox:scripts": ["src/background.ts"]
19+
},
20+
"content_scripts": [
21+
{
22+
"matches": ["*://*.github.com/*"],
23+
"js": ["src/content/ghcss.ts"]
24+
}
25+
]
26+
}

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "ghcss-extension",
3+
"description": "A simple extension that allows users to view custom css on GitHub profiles.",
4+
"version": "0.0.1",
5+
"license": "MIT",
6+
"author": {
7+
"name": "Bims-sh",
8+
"email": "contact@bims.sh",
9+
"url": "https://bims.sh"
10+
},
11+
"devDependencies": {
12+
"typescript": "5.3.3",
13+
"extension": "latest"
14+
},
15+
"scripts": {
16+
"dev": "extension dev",
17+
"start": "extension start",
18+
"build": "extension build"
19+
},
20+
"dependencies": {}
21+
}

src/background.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello world!")

src/content/ghcss.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {fetchGitHubCss} from "../lib/utils/GitHubUtils";
2+
import {injectCss} from "../lib/utils/InjectCss";
3+
4+
async function main() {
5+
try {
6+
const css = await fetchGitHubCss();
7+
8+
if (css !== null) {
9+
injectCss(css);
10+
}
11+
} catch (error) {
12+
console.error(error);
13+
}
14+
}
15+
16+
main().then();

src/lib/types/GitHubPageType.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum GitHubPageType {
2+
User = "User",
3+
Repo = "Repo",
4+
Organization = "Organization"
5+
}

src/lib/utils/FetchData.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export async function fetchMainBranch(owner: string, repo: string): Promise<string | null> {
2+
const url = `https://api.github.com/repos/${owner}/${repo}`;
3+
4+
try {
5+
const response = await fetch(url);
6+
7+
if (response.status === 404) {
8+
return null;
9+
}
10+
11+
const data = await response.json();
12+
13+
return data.default_branch || null;
14+
} catch (error) {
15+
console.log(`Failed to fetch JSON: ${error}`);
16+
return null;
17+
}
18+
}
19+
20+
export async function fetchPlainCss(url: string): Promise<string | null> {
21+
try {
22+
const response = await fetch(url, { headers: { "Accept": "text/plain" } });
23+
24+
if (response.status === 404) {
25+
return null;
26+
}
27+
28+
console.log(`Successfully fetched custom CSS from ${url}`);
29+
30+
return await response.text();
31+
} catch (error) {
32+
console.log(`Failed to fetch text: ${error}`);
33+
return null;
34+
}
35+
}

0 commit comments

Comments
 (0)