Files
amysteamdev 90249bc956 [New sample] Open Chrome API reference page (omnibox, alarms, messaging sample) (#848)
* First draft

* Rename folder

* Tweak comments

* Update index.html

* remove extra closing div

* Rename sw file

* Apply first round of @sebastianbenz suggestions

* Fix import

* Update popover

* Second tech review round
2024-08-21 13:53:13 +02:00

24 lines
706 B
JavaScript

import apiList from './api-list.js';
/**
* Returns a list of suggestions and a description for the default suggestion
*/
export async function getApiSuggestions(input) {
const suggestions = apiList.filter((api) => api.content.startsWith(input));
// return suggestions if any exist
if (suggestions.length) {
return {
description: 'Matching Chrome APIs',
suggestions: suggestions
};
}
// return past searches if no match was found
const { apiSuggestions } = await chrome.storage.local.get('apiSuggestions');
return {
description: 'No matches found. Choose from past searches',
suggestions: apiList.filter((item) => apiSuggestions.includes(item.content))
};
}