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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Benchmark extracting hostname from URL</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
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
// Custom Hook -> useInternationalization() | |
import i18n from "i18next" | |
import { useState, useEffect } from "react" | |
import { initReactI18next } from "react-i18next" | |
const NOTFETCHED = "notFetched" | |
const FETCHING = "fetching" | |
const FETCHED = "fetched" | |
const ERROR = "error" |
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
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | |
if (sender.tab && request.type === DISABLE_ICON) { | |
setIconOff() | |
} | |
... | |
// Provide internationalization translations at content script request | |
if (sender.tab && request.type === "internationalization") { | |
// Extract language from user settings | |
const store = getStore() | |
const state = store.getState() |
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
import i18next from "i18next" | |
import Fetch from "i18next-fetch-backend" | |
i18next.use(Fetch).init({ | |
debug: true, | |
fallbackLng: "en", | |
preload: ["en"], | |
keySeparator: false, // Allow usage of dots in keys | |
backend: { | |
loadPath: "https://{API_PATH}/translations/{{lng}}.json", | |
parse: (data) => JSON.parse(data), |
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
import _get from "lodash/get" | |
import _isArray from "lodash/isArray" | |
// Placeholder to fetch your cache version | |
// CACHE_VERSION allows to reset user data after a version upgrade if it's required | |
import { CACHE_VERSION } from "config" | |
export const loadState = (keys) => { | |
const promise = new Promise((resolve, reject) => { | |
chrome.storage.local.get(CACHE_VERSION, (items) => { |