2024-03-31 15:57:56 +05:30
|
|
|
import { Storage } from "@plasmohq/storage"
|
|
|
|
|
|
|
|
|
|
const storage = new Storage()
|
2024-12-13 20:03:52 +05:30
|
|
|
const storage2 = new Storage({
|
|
|
|
|
area: "local"
|
|
|
|
|
})
|
2024-03-31 15:57:56 +05:30
|
|
|
|
|
|
|
|
const TOTAL_SEARCH_RESULTS = 2
|
|
|
|
|
const DEFAULT_PROVIDER = "google"
|
|
|
|
|
|
|
|
|
|
const AVAILABLE_PROVIDERS = ["google", "duckduckgo"] as const
|
|
|
|
|
|
|
|
|
|
export const getIsSimpleInternetSearch = async () => {
|
|
|
|
|
const isSimpleInternetSearch = await storage.get("isSimpleInternetSearch")
|
|
|
|
|
if (!isSimpleInternetSearch || isSimpleInternetSearch.length === 0) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return isSimpleInternetSearch === "true"
|
|
|
|
|
}
|
|
|
|
|
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
export const getIsVisitSpecificWebsite = async () => {
|
|
|
|
|
const isVisitSpecificWebsite = await storage.get("isVisitSpecificWebsite")
|
|
|
|
|
if (!isVisitSpecificWebsite || isVisitSpecificWebsite.length === 0) {
|
2024-06-23 20:34:43 +05:30
|
|
|
return true
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
}
|
|
|
|
|
return isVisitSpecificWebsite === "true"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const setIsVisitSpecificWebsite = async (
|
|
|
|
|
isVisitSpecificWebsite: boolean
|
|
|
|
|
) => {
|
|
|
|
|
await storage.set("isVisitSpecificWebsite", isVisitSpecificWebsite.toString())
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 15:57:56 +05:30
|
|
|
export const setIsSimpleInternetSearch = async (
|
|
|
|
|
isSimpleInternetSearch: boolean
|
|
|
|
|
) => {
|
|
|
|
|
await storage.set("isSimpleInternetSearch", isSimpleInternetSearch.toString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getSearchProvider = async (): Promise<
|
|
|
|
|
(typeof AVAILABLE_PROVIDERS)[number]
|
|
|
|
|
> => {
|
|
|
|
|
const searchProvider = await storage.get("searchProvider")
|
|
|
|
|
if (!searchProvider || searchProvider.length === 0) {
|
|
|
|
|
return DEFAULT_PROVIDER
|
|
|
|
|
}
|
|
|
|
|
return searchProvider as (typeof AVAILABLE_PROVIDERS)[number]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setSearchProvider = async (searchProvider: string) => {
|
|
|
|
|
await storage.set("searchProvider", searchProvider)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const totalSearchResults = async () => {
|
|
|
|
|
const totalSearchResults = await storage.get("totalSearchResults")
|
|
|
|
|
if (!totalSearchResults || totalSearchResults.length === 0) {
|
|
|
|
|
return TOTAL_SEARCH_RESULTS
|
|
|
|
|
}
|
|
|
|
|
return parseInt(totalSearchResults)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setTotalSearchResults = async (totalSearchResults: number) => {
|
|
|
|
|
await storage.set("totalSearchResults", totalSearchResults.toString())
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 00:23:17 +05:30
|
|
|
export const getSearxngURL = async () => {
|
|
|
|
|
const searxngURL = await storage.get("searxngURL")
|
|
|
|
|
return searxngURL || ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const isSearxngJSONMode = async () => {
|
|
|
|
|
const searxngJSONMode = await storage.get<boolean>("searxngJSONMode")
|
|
|
|
|
return searxngJSONMode ?? false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setSearxngJSONMode = async (searxngJSONMode: boolean) => {
|
|
|
|
|
await storage.set("searxngJSONMode", searxngJSONMode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setSearxngURL = async (searxngURL: string) => {
|
|
|
|
|
await storage.set("searxngURL", searxngURL)
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 20:03:52 +05:30
|
|
|
export const getBraveApiKey = async () => {
|
|
|
|
|
const braveApiKey = await storage2.get("braveApiKey")
|
|
|
|
|
return braveApiKey || ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setBraveApiKey = async (braveApiKey: string) => {
|
|
|
|
|
await storage2.set("braveApiKey", braveApiKey)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 15:57:56 +05:30
|
|
|
export const getSearchSettings = async () => {
|
2024-12-01 00:23:17 +05:30
|
|
|
const [isSimpleInternetSearch, searchProvider, totalSearchResult, visitSpecificWebsite,
|
|
|
|
|
searxngURL,
|
2024-12-13 20:03:52 +05:30
|
|
|
searxngJSONMode,
|
|
|
|
|
braveApiKey
|
2024-12-01 00:23:17 +05:30
|
|
|
] =
|
2024-03-31 15:57:56 +05:30
|
|
|
await Promise.all([
|
|
|
|
|
getIsSimpleInternetSearch(),
|
|
|
|
|
getSearchProvider(),
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
totalSearchResults(),
|
2024-12-01 00:23:17 +05:30
|
|
|
getIsVisitSpecificWebsite(),
|
|
|
|
|
getSearxngURL(),
|
2024-12-13 20:03:52 +05:30
|
|
|
isSearxngJSONMode(),
|
|
|
|
|
getBraveApiKey()
|
2024-03-31 15:57:56 +05:30
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
isSimpleInternetSearch,
|
|
|
|
|
searchProvider,
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
totalSearchResults: totalSearchResult,
|
2024-12-01 00:23:17 +05:30
|
|
|
visitSpecificWebsite,
|
|
|
|
|
searxngURL,
|
2024-12-13 20:03:52 +05:30
|
|
|
searxngJSONMode,
|
|
|
|
|
braveApiKey
|
2024-03-31 15:57:56 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setSearchSettings = async ({
|
|
|
|
|
isSimpleInternetSearch,
|
|
|
|
|
searchProvider,
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
totalSearchResults,
|
2024-12-01 00:23:17 +05:30
|
|
|
visitSpecificWebsite,
|
|
|
|
|
searxngJSONMode,
|
2024-12-13 20:03:52 +05:30
|
|
|
searxngURL,
|
|
|
|
|
braveApiKey
|
2024-03-31 15:57:56 +05:30
|
|
|
}: {
|
|
|
|
|
isSimpleInternetSearch: boolean
|
|
|
|
|
searchProvider: string
|
|
|
|
|
totalSearchResults: number
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
visitSpecificWebsite: boolean
|
2024-12-01 00:23:17 +05:30
|
|
|
searxngURL: string
|
2024-12-13 20:03:52 +05:30
|
|
|
searxngJSONMode: boolean,
|
|
|
|
|
braveApiKey: string
|
2024-03-31 15:57:56 +05:30
|
|
|
}) => {
|
|
|
|
|
await Promise.all([
|
|
|
|
|
setIsSimpleInternetSearch(isSimpleInternetSearch),
|
|
|
|
|
setSearchProvider(searchProvider),
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
setTotalSearchResults(totalSearchResults),
|
2024-12-01 00:23:17 +05:30
|
|
|
setIsVisitSpecificWebsite(visitSpecificWebsite),
|
|
|
|
|
setSearxngJSONMode(searxngJSONMode),
|
2024-12-13 20:03:52 +05:30
|
|
|
setSearxngURL(searxngURL),
|
|
|
|
|
setBraveApiKey(braveApiKey)
|
2024-03-31 15:57:56 +05:30
|
|
|
])
|
|
|
|
|
}
|