Skip to content

Commit 61442af

Browse files
committed
feat: migrate JavaScript files to TypeScript and add tsconfig.json
1 parent 7a50840 commit 61442af

File tree

9 files changed

+2016
-1800
lines changed

9 files changed

+2016
-1800
lines changed

app/scripts/background.js

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

app/scripts/background.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const injectContentToTab = async (tab: chrome.tabs.Tab): Promise<void> => {
2+
// Skip if URL is undefined
3+
if (!tab.url) {
4+
return;
5+
}
6+
7+
// Skip if tab is discarded
8+
if (tab.discarded) {
9+
return;
10+
}
11+
12+
// Skip if tab ID is undefined
13+
if (tab.id === undefined) {
14+
return;
15+
}
16+
17+
// Skip if not a GitHub URL
18+
if (!tab.url.startsWith('https://github.com/')) {
19+
return;
20+
}
21+
22+
try {
23+
const manifest = chrome.runtime.getManifest();
24+
25+
// Inject CSS
26+
if (manifest.content_scripts?.[0]?.css) {
27+
await chrome.scripting.insertCSS({
28+
target: { tabId: tab.id },
29+
files: manifest.content_scripts[0].css,
30+
});
31+
}
32+
33+
// Inject JavaScript
34+
if (manifest.content_scripts?.[0]?.js) {
35+
await chrome.scripting.executeScript({
36+
target: { tabId: tab.id },
37+
files: manifest.content_scripts[0].js,
38+
});
39+
}
40+
} catch (error) {
41+
console.error('Error injecting content script:', error);
42+
}
43+
};
44+
45+
// Update extension content for tabs
46+
chrome.tabs.query({}, async (tabs: chrome.tabs.Tab[]) => {
47+
for (const tabKey in tabs) {
48+
const tab = tabs[tabKey];
49+
50+
try {
51+
await injectContentToTab(tab);
52+
} catch (e) {
53+
console.error(e);
54+
}
55+
}
56+
});

app/scripts/content.js renamed to app/scripts/content.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Function to add DeepWiki button
2-
function addDeepWikiButton() {
2+
function addDeepWikiButton(): void {
33
// If button already exists, do nothing
44
if (document.querySelector('.deepwiki-button')) {
55
return;
66
}
77

88
// Get repository main navigation element
9-
const navActions = document.querySelector('ul.pagehead-actions');
9+
const navActions = document.querySelector<HTMLUListElement>('ul.pagehead-actions');
1010
if (!navActions) {
1111
return;
1212
}
@@ -41,7 +41,7 @@ function addDeepWikiButton() {
4141
<img src="${chrome.runtime.getURL('images/icon-64.png')}" width="16" height="16" alt="DeepWiki">
4242
`;
4343

44-
// Add text with i18n support
44+
// Add text
4545
const text = document.createTextNode('DeepWiki');
4646
button.appendChild(icon);
4747
button.appendChild(text);
@@ -61,7 +61,7 @@ document.addEventListener('DOMContentLoaded', () => {
6161
let lastUrl = location.href;
6262
let isProcessing = false;
6363

64-
const observer = new MutationObserver((mutations) => {
64+
const observer = new MutationObserver((mutations: MutationRecord[]) => {
6565
if (isProcessing) return;
6666
isProcessing = true;
6767

@@ -76,7 +76,7 @@ document.addEventListener('DOMContentLoaded', () => {
7676
}
7777

7878
// Monitor navigation element addition (only if button doesn't exist)
79-
const navActions = document.querySelector('ul.pagehead-actions');
79+
const navActions = document.querySelector<HTMLUListElement>('ul.pagehead-actions');
8080
const deepWikiButton = document.querySelector('.deepwiki-button');
8181
if (navActions && !deepWikiButton) {
8282
addDeepWikiButton();

biome.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
33
"files": {
44
"include": [
5-
"app/scripts/**/*.js"
6-
],
7-
"ignore": [
8-
"website/client/.vitepress/.temp",
9-
"website/client/.vitepress/dist",
10-
"website/client/.vitepress/cache",
11-
"website/server/dist"
5+
"app/scripts/**/*.ts"
126
]
137
},
148
"organizeImports": {

0 commit comments

Comments
 (0)