Skip to content

Instantly share code, notes, and snippets.

View a90100's full-sized avatar
:octocat:
Keep learning

Harry Xie a90100

:octocat:
Keep learning
View GitHub Profile
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['content.js']
});
});
chrome.runtime.onMessage.addListener(async ({ name, options }) => {
if (name === 'inject-programmatic') {
await chrome.storage.local.set({ options });
await chrome.tabs.create({
url: 'https://example.com/#inject-programmatic'
});
}
});
document
.querySelector('#inject-programmatic')
.addEventListener('click', async () => {
const world = document.querySelector("[name='world']").value;
chrome.runtime.sendMessage({
name: 'inject-programmatic',
options: { world }
});
});
"content_scripts": [
{
"matches": ["https://*.udemy.com/*"],
"js": ["dist/js/injector.js"],
"run_at": "document_end"
}
]
let color = '#3aa757';
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.set({ color });
});
const path = require('path');
function resolve (dir) {
return path.join(__dirname, '.', dir);
}
module.exports = function override(config) {
config.resolve.alias = {
...config.resolve.alias,
'@': resolve('src'),
function Example() {
// 宣告一個新的 state 變數,我們稱作為「count」。
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
import React from 'react';
import { mount } from 'enzyme';
import App from 'components/App';
import Root from 'root';
import moxios from 'moxios';
let wrapped;
beforeEach(() => {
moxios.install();
import commentsReducer from 'reducers/comments';
const SAVE_COMMENT = 'save_comment';
it('handles actions of type SAVE_COMMENT', () => {
const action = {
type: SAVE_COMMENT,
payload: 'new comment'
}
const newState = commentsReducer([], action);
@a90100
a90100 / index.js
Last active October 11, 2020 16:18
const SAVE_COMMENT = 'save_comment';
export default(state = [], action) => {
switch(action.type) {
case SAVE_COMMENT:
return [...state, action.payload]
default:
return state;
}
}