Skip to content

Instantly share code, notes, and snippets.

@kamiazya
Last active February 22, 2024 15:53
Show Gist options
  • Save kamiazya/da0aeff05063af4bda26da1bf81f5fb6 to your computer and use it in GitHub Desktop.
Save kamiazya/da0aeff05063af4bda26da1bf81f5fb6 to your computer and use it in GitHub Desktop.
画面をスクショするブックマークレット
javascript: (function () {
const src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js';
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
script.onload = () => {
html2canvas(document.body, {
onrendered: (canvas) => {
const imgageData = canvas.toDataURL('image/png');
const el = document.createElement('a');
el.setAttribute('href', imgageData.replace(/^data:image\/png/, 'data:application/octet-stream'));
el.setAttribute('download', 'screen.png');
el.style.display = 'none';
document.body.appendChild(el);
el.click();
document.body.removeChild(el);
}
});
};
document.body.appendChild(script);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment