Skip to content

Commit 8f345ed

Browse files
author
cpv123
committed
Bring back background script
1 parent 5e5eb83 commit 8f345ed

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

mint/js/background.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
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";
44

5-
// let storedGithubProfile;
6-
// let storedRepos = [];
5+
let storedGithubProfile;
6+
let storedRepos = [];
77

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+
};
1214

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;
1919

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+
});
3326

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

Comments
 (0)