Skip to content

Commit

Permalink
docs: context
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Feb 14, 2023
1 parent c779357 commit 9c3ff9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,23 @@ Quick screenshots per second by reusing context
```ts
import { createContext, destroyContext, domToPng } from 'modern-screenshot'

createContext(document.querySelector('#app')).then(context => {
setInterval(() => {
async function screenshotsPerSecond() {
const context = awiat createContext(document.querySelector('#app'))
for (let i = 0; i < 10; i++) {
domToPng(context).then(dataUrl => {
const link = document.createElement('a')
link.download = 'screenshot.png'
link.download = `screenshot-${ i + 1 }.png`
link.href = dataUrl
link.click()
if (i + 1 === 10) {
destroyContext(context)
}
})
}, 1000)
})
await new Promise(resolve => setTimeout(resolve, 1000))
}
}

screenshotsPerSecond()
```

See the [context.ts](src/context.ts)
Expand Down
17 changes: 12 additions & 5 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,23 @@ DOM 转 HTMLElement
```ts
import { createContext, destroyContext, domToPng } from 'modern-screenshot'

createContext(document.querySelector('#app')).then(context => {
setInterval(() => {
async function screenshotsPerSecond() {
const context = awiat createContext(document.querySelector('#app'))
for (let i = 0; i < 10; i++) {
domToPng(context).then(dataUrl => {
const link = document.createElement('a')
link.download = 'screenshot.png'
link.download = `screenshot-${ i + 1 }.png`
link.href = dataUrl
link.click()
if (i + 1 === 10) {
destroyContext(context)
}
})
}, 1000)
})
await new Promise(resolve => setTimeout(resolve, 1000))
}
}

screenshotsPerSecond()
```

请查看 [context.ts](src/context.ts)
Expand Down

1 comment on commit 9c3ff9f

@vercel
Copy link

@vercel vercel bot commented on 9c3ff9f Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

modern-screenshot – ./

modern-screenshot-git-master-qq15725.vercel.app
modern-screenshot-qq15725.vercel.app
modern-screenshot.vercel.app

Please sign in to comment.