Skip to content

Instantly share code, notes, and snippets.

@jessuni
jessuni / jsconfig.json
Created Aug 24, 2020
extension-section-0-vscode
View jsconfig.json
{
"typeAcquisition": {
"include": [
"chrome"
]
}
}
@jessuni
jessuni / manifest.json
Last active Aug 24, 2020
extension-section-2-manifest-1
View manifest.json
{
"name": "My extension",
"content_scripts": [
{
"matches": ["http://*.nytimes.com/*"],
"run_at": "document_start",
"js": ["contentScript.js"]
}
]
}
@jessuni
jessuni / background.js
Created Aug 24, 2020
extension-section-1-background-2
View background.js
chrome.runtime.onConnect.addListener(port => {
const tabId = port && port.sender && port.sender.tab.id
if (port.name === 'hello') {
enableIcon(tabId)
}
// disable icon when connection is closed
port.onDisconnect.addListener(() => {
disableIcon(tabId)
})
})
@jessuni
jessuni / contentscript.js
Last active Aug 24, 2020
extension-section-1-content-1
View contentscript.js
// when content script runs, notify background
const port = chrome.runtime.connect({ name: 'hello' })
@jessuni
jessuni / background.js
Last active Aug 24, 2020
extension-section-1-background-1
View background.js
function disableIcon(tabId) {
chrome.browserAction.setIcon({
tabId: tabId,
path: {
'16': '/images/icon16-gray.png',
'32': '/images/icon32-gray.png',
},
})
chrome.browserAction.setPopup({
tabId,
@jessuni
jessuni / GenerateAudioWaveform
Last active Nov 21, 2020
Audio Oscilloscope (Frequency Byte) - by Web Audio API and Canvas