Skip to content

Instantly share code, notes, and snippets.

@hindmost
hindmost / reduxed-chrome-storage-article-async-action-example.js
Created December 18, 2020 09:08
reduxed-chrome-storage article: async action creator example
const addTodo = text => ({
type: 'ADD_TODO',
text
});
const delayAddTodo = (text) => dispatch => {
setTimeout(() => {
dispatch(addTodo(text));
}, 1000);
}
@hindmost
hindmost / reduxed-chrome-storage-article-buffered-dispatch.js
Created December 18, 2020 09:05
reduxed-chrome-storage article: buffered dispatch version
class ReduxedStorage {
...
dispatch(action) {
if (!this.buffStore) {
this.buffStore = this.createStore(this.reducer, this.state, this.enhancer);
this.lastState = this.buffStore.getState();
setTimeout(() => {
this.buffStore = null;
}, 100);
}
@hindmost
hindmost / cra-rich-chrome-ext-article-content-mod.js
Created August 11, 2020 18:17
cra-rich-chrome-ext article: src/content.js - modifications
...
(async () => {
chrome.runtime.onMessage.addListener( data => {
// if current tab received focus, apply mark/unmark operations (if any),
// then, if there was no mark operation, update marker stats
data && data.id === 'tabFocusPass' &&
!render(store) && updateStats(store);
});
@hindmost
hindmost / cra-rich-chrome-ext-article-background-mod.js
Created August 11, 2020 18:16
cra-rich-chrome-ext article: src/background.js - modifications
...
chrome.tabs.onActivated.addListener(async data => {
const {tabId} = data;
if (!tabId)
return;
const store = await getStore();
const state = store.getState();
const {account, marker} = state;
const toMark = account.keywords && marker.enabled;
@hindmost
hindmost / cra-rich-chrome-ext-article-background.js
Created August 11, 2020 18:13
cra-rich-chrome-ext article: src/background.js
import { createStore } from 'redux';
import storeCreatorFactory from 'reduxed-chrome-storage';
import reducers from './reducers';
import { accountLogout, setStats, setIconHash } from './actions';
const storeCreator = storeCreatorFactory({createStore});
let store;
const getStore = async () => {
if (store)
return store;
@hindmost
hindmost / cra-rich-chrome-ext-article-reducers-marker-final.js
Created August 11, 2020 18:11
cra-rich-chrome-ext article: src/reducers/marker.js - final edition
import {
SET_ENABLED, SET_STATS, SET_ICONHASH
} from '../actions/marker';
const initialState = {
enabled: false,
stats: false,
iconHash: ''
};
@hindmost
hindmost / cra-rich-chrome-ext-article-actions-marker-final.js
Created August 11, 2020 18:10
cra-rich-chrome-ext article: src/actions/marker.js - final edition
export const SET_ENABLED = 'SET_ENABLED';
export const SET_STATS = 'SET_STATS';
export const SET_ICONHASH = 'SET_ICONHASH';
export const setEnabled = data => ({
type: SET_ENABLED, data
});
export const setStats = data => ({
type: SET_STATS, data
@hindmost
hindmost / cra-rich-chrome-ext-article-content.js
Created August 11, 2020 18:09
cra-rich-chrome-ext article: src/content.js
import { createStore } from 'redux';
import storeCreatorFactory from 'reduxed-chrome-storage';
import reducers from './reducers';
import { setStats } from './actions/marker';
import { mark, unmark } from './mark';
let stateJson0;
let toUnmark = false;
let stats = false;
@hindmost
hindmost / cra-rich-chrome-ext-article-mark-index.js
Created August 11, 2020 18:08
cra-rich-chrome-ext article: src/mark/index.js
let styleElem;
const setStyle = (style, cssClass) => {
if (!styleElem) {
styleElem = document.createElement('style');
styleElem.type = 'text/css';
document.body.appendChild(styleElem);
}
styleElem.innerHTML = style? `.${cssClass} {${style}}` : '';
};
@hindmost
hindmost / cra-rich-chrome-ext-article-index.js
Created August 11, 2020 18:07
cra-rich-chrome-ext article: src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import storeCreatorFactory from 'reduxed-chrome-storage';
import reducers from './reducers';
import 'semantic-ui-css/semantic.min.css';
import App from './views/Popup/App';
(async () => {