|
1 | | -// const BASE_URL = "https://github.com"; |
2 | | -// const STORAGE_PROFILE = "githubProfile"; |
3 | | -// const STORAGE_REPOS = "githubRepos"; |
| 1 | +const BASE_URL = "https://github.com"; |
| 2 | +const STORAGE_PROFILE = "githubProfile"; |
| 3 | +const STORAGE_REPOS = "githubRepos"; |
4 | 4 |
|
5 | | -// let storedGithubProfile; |
6 | | -// let storedRepos = []; |
| 5 | +let storedGithubProfile; |
| 6 | +let storedRepos = []; |
7 | 7 |
|
8 | | -// chrome.omnibox.onInputStarted.addListener(() => { |
9 | | -// chrome.storage.sync.get([STORAGE_PROFILE, STORAGE_REPOS], (storage) => { |
10 | | -// if (storage.githubProfile) { |
11 | | -// storedGithubProfile = storage.githubProfile; |
| 8 | +const reposToSuggestions = (repos) => { |
| 9 | + return repos.map((repoName) => ({ |
| 10 | + content: repoName, |
| 11 | + description: repoName, |
| 12 | + })); |
| 13 | +}; |
12 | 14 |
|
13 | | -// if (storage.githubRepos) { |
14 | | -// storedRepos = storage.githubRepos; |
15 | | -// } |
16 | | -// } |
17 | | -// }); |
18 | | -// }); |
| 15 | +chrome.omnibox.onInputStarted.addListener(() => { |
| 16 | + chrome.storage.sync.get([STORAGE_PROFILE, STORAGE_REPOS], (storage) => { |
| 17 | + if (storage.githubProfile) { |
| 18 | + storedGithubProfile = storage.githubProfile; |
19 | 19 |
|
20 | | -// chrome.omnibox.onInputChanged.addListener((text, suggest) => { |
21 | | -// if (!text || !text.length) return storedRepos; |
22 | | -// const filteredRepos = storedRepos.filter((repoName) => { |
23 | | -// const searchTerm = text.toLowerCase(); |
24 | | -// const doesMatch = repoName.toLowerCase().includes(searchTerm); |
25 | | -// return doesMatch; |
26 | | -// }); |
27 | | -// const suggestions = filteredRepos.map((repoName) => ({ |
28 | | -// content: repoName, |
29 | | -// description: repoName, |
30 | | -// })); |
31 | | -// suggest(suggestions); |
32 | | -// }); |
| 20 | + if (storage.githubRepos) { |
| 21 | + storedRepos = storage.githubRepos; |
| 22 | + } |
| 23 | + } |
| 24 | + }); |
| 25 | +}); |
33 | 26 |
|
34 | | -// chrome.omnibox.onInputEntered.addListener((text) => |
35 | | -// chrome.tabs.update({ url: `${BASE_URL}/${storedGithubProfile}/${text}` }) |
36 | | -// ); |
| 27 | +chrome.omnibox.onInputChanged.addListener((text, suggest) => { |
| 28 | + if (!text || text.length === 0) { |
| 29 | + const allSuggestions = reposToSuggestions(storedRepos); |
| 30 | + return suggest(allSuggestions); |
| 31 | + } |
| 32 | + const filteredRepos = storedRepos.filter((repoName) => { |
| 33 | + const searchTerm = text.toLowerCase(); |
| 34 | + const doesMatch = repoName.toLowerCase().includes(searchTerm); |
| 35 | + return doesMatch; |
| 36 | + }); |
| 37 | + const suggestions = reposToSuggestions(filteredRepos); |
| 38 | + return suggest(suggestions); |
| 39 | +}); |
| 40 | + |
| 41 | +chrome.omnibox.onInputEntered.addListener((text) => |
| 42 | + chrome.tabs.update({ url: `${BASE_URL}/${storedGithubProfile}/${text}` }) |
| 43 | +); |
0 commit comments