Skip to content

Instantly share code, notes, and snippets.

@jessuni
jessuni / background.js
Created August 24, 2020 03:34
extension-section-1-background-2
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 / manifest.json
Last active August 24, 2020 04:51
extension-section-2-manifest-1
{
"name": "My extension",
"content_scripts": [
{
"matches": ["http://*.nytimes.com/*"],
"run_at": "document_start",
"js": ["contentScript.js"]
}
]
}
@jessuni
jessuni / jsconfig.json
Created August 24, 2020 07:56
extension-section-0-vscode
{
"typeAcquisition": {
"include": [
"chrome"
]
}
}
@jessuni
jessuni / contentscript.js
Last active August 24, 2020 08:41
extension-section-1-content-1
// when content script runs, notify background
const port = chrome.runtime.connect({ name: 'hello' })
@jessuni
jessuni / background.js
Last active August 24, 2020 11:23
extension-section-1-background-1
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 / Card.vue
Last active January 30, 2022 08:54
contenteditable-vue-2-onblur-method
<template>
<div contenteditable="true" @blur="update" v-text="modelValue"></div>
</template>
<script>
export default {
props: {
modelValue: {
type: String,
default: '',
},
@jessuni
jessuni / Card.vue
Last active January 30, 2022 09:38
contenteditable-vue-3-decoupling
<template>
<div v-once contenteditable="true" @input="update" v-text="modelValue"></div>
</template>
<script>
export default {
props: {
modelValue: {
type: String,
default: '',
},
@jessuni
jessuni / App.vue
Last active January 30, 2022 10:21
contenteditable-vue-1
<template>
<card v-model="content" />
</template>
<script>
import Card from '...'
export default {
components: { Card },
data() {
@jessuni
jessuni / GenerateAudioWaveform
Last active July 3, 2023 05:58
Audio Oscilloscope (Frequency Byte) - w/ web audio API and canvas
// rename gist