-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as constant from "./const.js"; | ||
|
||
export async function storeSuggestCandidates(candidate) { | ||
const oldCandidates = await fetchSuggestCandidates(); | ||
const newCandidates = appendSuggestion(oldCandidates, candidate); | ||
chrome.storage.local.set({ suggestCandidates: newCandidates }); | ||
} | ||
|
||
export async function findSuggestCandidate(word) { | ||
const candidates = await fetchSuggestCandidates(); | ||
const suggest = candidates.find((c) => { | ||
if (c.startsWith(word)) { | ||
return c; | ||
} | ||
}); | ||
return suggest; | ||
} | ||
|
||
////////////////// | ||
// Private Methods | ||
////////////////// | ||
|
||
async function fetchSuggestCandidates() { | ||
const { suggestCandidates } = await chrome.storage.local.get({ | ||
suggestCandidates: [], | ||
}); | ||
return suggestCandidates; | ||
} | ||
|
||
function appendSuggestion(candidates, candidate) { | ||
let _candidates = structuredClone(candidates); | ||
_candidates.unshift(candidate); | ||
_candidates.reverse().slice(constant.MAX_SUGGEST_CANDIDATES).reverse(); | ||
return _candidates; | ||
} |