Skip to content

Instantly share code, notes, and snippets.

View eduardoacskimlinks's full-sized avatar

Eduardo Aparicio Cardenes eduardoacskimlinks

View GitHub Profile
@eduardoacskimlinks
eduardoacskimlinks / index.html
Created February 3, 2022 10:20 — forked from JobLeonard/index.html
Benchmark extracting hostname from URL (http://jsbench.github.io/#ccc21879bfeca48a8807f4b662e7acce) #jsbench #jsperf
<!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>
@eduardoacskimlinks
eduardoacskimlinks / useInternationalization.hook.js
Created June 9, 2022 10:37
useInternationalization - hook
// 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"
@eduardoacskimlinks
eduardoacskimlinks / runtime-onMessage.listener.js
Created June 9, 2022 10:41
Runtime onMessage listener - servicer worker
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()
@eduardoacskimlinks
eduardoacskimlinks / i18next-setup-service-worker.js
Created June 9, 2022 10:43
i18next setup for service worker to fetch translations
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),
@eduardoacskimlinks
eduardoacskimlinks / chrome-local-storage.wrapper.js
Created June 22, 2022 08:14
Wrapper for Chrome Local Storage API persistence for Chrome extensions
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) => {