This file contains hidden or 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.action.onClicked.addListener((tab) => { | |
| chrome.scripting.executeScript({ | |
| target: {tabId: tab.id}, | |
| files: ['content.js'] | |
| }); | |
| }); |
This file contains hidden or 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(async ({ name, options }) => { | |
| if (name === 'inject-programmatic') { | |
| await chrome.storage.local.set({ options }); | |
| await chrome.tabs.create({ | |
| url: 'https://example.com/#inject-programmatic' | |
| }); | |
| } | |
| }); |
This file contains hidden or 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
| document | |
| .querySelector('#inject-programmatic') | |
| .addEventListener('click', async () => { | |
| const world = document.querySelector("[name='world']").value; | |
| chrome.runtime.sendMessage({ | |
| name: 'inject-programmatic', | |
| options: { world } | |
| }); | |
| }); |
This file contains hidden or 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
| "content_scripts": [ | |
| { | |
| "matches": ["https://*.udemy.com/*"], | |
| "js": ["dist/js/injector.js"], | |
| "run_at": "document_end" | |
| } | |
| ] |
This file contains hidden or 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
| let color = '#3aa757'; | |
| chrome.runtime.onInstalled.addListener(() => { | |
| chrome.storage.sync.set({ color }); | |
| }); |
This file contains hidden or 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
| 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'), |
This file contains hidden or 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
| 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> |
This file contains hidden or 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 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(); |
This file contains hidden or 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 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); |
This file contains hidden or 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
| const SAVE_COMMENT = 'save_comment'; | |
| export default(state = [], action) => { | |
| switch(action.type) { | |
| case SAVE_COMMENT: | |
| return [...state, action.payload] | |
| default: | |
| return state; | |
| } | |
| } |