Skip to content

Commit c49a10e

Browse files
committed
feat: add option to open links in new window and update button behavior
1 parent 3b820b7 commit c49a10e

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

entrypoints/content/git-ingest-button.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,20 @@ export async function createGitIngestButton(): Promise<HTMLLIElement> {
3131
const link = document.createElement('a');
3232
link.className = 'btn-sm btn';
3333

34-
// Get custom base URL from storage, default to gitingest.com if not set
35-
const baseUrl = await storage.getItem<string>('sync:baseUrl') || 'gitingest.com';
36-
link.href = window.location.href.replace('github.com', baseUrl);
34+
// Get custom base URL and window preference from storage
35+
const [baseUrl, openInNewWindow] = await Promise.all([
36+
storage.getItem<string>('sync:baseUrl'),
37+
storage.getItem<boolean>('sync:openInNewWindow')
38+
]);
39+
40+
// Set default base URL if not set
41+
link.href = window.location.href.replace('github.com', baseUrl || 'gitingest.com');
42+
43+
// Set target based on preference
44+
if (openInNewWindow) {
45+
link.target = '_blank';
46+
link.rel = 'noopener noreferrer';
47+
}
3748

3849
// Create spans for different screen sizes
3950
const linkContent = `
@@ -45,7 +56,6 @@ export async function createGitIngestButton(): Promise<HTMLLIElement> {
4556

4657
// Add button to container
4758
li.appendChild(link);
48-
4959
li.id = 'git-ingest-button';
5060

5161
return li;
@@ -69,7 +79,12 @@ storage.watch('sync:baseUrl', () => {
6979
const link = button.querySelector('a');
7080
if (link) {
7181
createGitIngestButton().then(newButton => {
72-
link.href = newButton.querySelector('a')?.href || link.href;
82+
const newLink = newButton.querySelector('a');
83+
if (newLink) {
84+
link.href = newLink.href;
85+
link.target = newLink.target;
86+
link.rel = newLink.rel;
87+
}
7388
});
7489
}
7590
}

entrypoints/popup/App.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { storage } from 'wxt/storage';
33

44
function App() {
55
const [baseUrl, setBaseUrl] = useState<string>('');
6+
const [openInNewWindow, setOpenInNewWindow] = useState(false);
67
const [isSaved, setIsSaved] = useState(false);
78

89
useEffect(() => {
@@ -11,6 +12,9 @@ function App() {
1112
setBaseUrl(savedUrl);
1213
}
1314
});
15+
storage.getItem<boolean>('sync:openInNewWindow').then((value) => {
16+
setOpenInNewWindow(value ?? false);
17+
});
1418
}, []);
1519

1620
const handleSave = async (e: React.FormEvent) => {
@@ -20,6 +24,11 @@ function App() {
2024
setTimeout(() => setIsSaved(false), 2500);
2125
};
2226

27+
const handleToggleChange = async (checked: boolean) => {
28+
setOpenInNewWindow(checked);
29+
await storage.setItem('sync:openInNewWindow', checked);
30+
};
31+
2332
return (
2433
<div className="min-w-32 p-4 bg-[#fff4da]">
2534
<div className="mb-4 flex justify-between items-center">
@@ -63,6 +72,19 @@ function App() {
6372
/>
6473
</div>
6574
</div>
75+
76+
<div className="space-y-2">
77+
<label className="relative inline-flex items-center cursor-pointer">
78+
<input
79+
type="checkbox"
80+
checked={openInNewWindow}
81+
onChange={(e) => handleToggleChange(e.target.checked)}
82+
className="sr-only peer"
83+
/>
84+
<div className="relative w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer border-[3px] border-gray-900 peer-checked:after:translate-x-[19px] rtl:peer-checked:after:-translate-x-[19px] peer-checked:after:border-gray-900 after:content-[''] after:absolute after:top-[1px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#fca847]"></div>
85+
<span className="ms-3 text-sm font-bold text-gray-900">Open in New Window</span>
86+
</label>
87+
</div>
6688

6789
<div className="relative w-full group">
6890
<div className="w-full h-full rounded bg-gray-800 translate-y-1 translate-x-1 absolute inset-0 z-10"></div>

0 commit comments

Comments
 (0)