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
var SetIntervalMixin = { | |
componentWillMount: function() { | |
this.intervals = []; | |
}, | |
setInterval: function() { | |
this.intervals.push(setInterval.apply(null, arguments)); | |
}, | |
componentWillUnmount: function() { | |
this.intervals.forEach(clearInterval); | |
} |
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.addEventListener('paste', async (e) => { | |
e.preventDefault(); | |
const text = await navigator.clipboard.readText(); | |
console.log('Pasted text: ', text); | |
}); |
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 clipboardItems = []; | |
document.addEventListener("copy", async (e) => { | |
e.preventDefault(); | |
try { | |
let clipboardItems = []; | |
for (const item of e.clipboardData.items) { | |
if (!item.type.startsWith("image/")) { | |
continue; | |
} |
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 source = document.querySelector('.source'); | |
source.addEventListener('copy', (event) => { | |
const selection = document.getSelection(); | |
event.clipboardData.setData('text/plain', selection.toString().toUpperCase()); | |
event.preventDefault(); | |
}); |
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 copy() { | |
const image = await fetch('kitten.png'); | |
const text = new Blob(['Cute sleeping kitten'], {type: 'text/plain'}); | |
const item = new ClipboardItem({ | |
'text/plain': text, | |
'image/png': image | |
}); | |
await navigator.clipboard.write([item]); |
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
try { | |
const imgURL = 'https://dummyimage.com/300.png'; | |
const data = await fetch(imgURL); | |
const blob = await data.blob(); | |
await navigator.clipboard.write([ | |
new ClipboardItem({ | |
[blob.type]: blob | |
}) | |
]); | |
console.log('Image copied.'); |
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
async function copyPageUrl() { | |
try { | |
await navigator.clipboard.writeText(location.href); | |
console.log('Page URL copied to clipboard'); | |
} catch (err) { | |
console.error('Failed to copy: ', err); | |
} | |
} |
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.body.addEventListener( | |
'click', | |
async (e) => { | |
await navigator.clipboard.writeText('Sabesan') | |
} | |
) |
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
async function getClipboardContents() { | |
try { | |
const clipboardItems = await navigator.clipboard.read(); | |
for (const clipboardItem of clipboardItems) { | |
for (const type of clipboardItem.types) { | |
const blob = await clipboardItem.getType(type); | |
console.log(URL.createObjectURL(blob)); | |
} | |
} | |
} catch (err) { |
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
async function getClipboardContents() { | |
try { | |
const text = await navigator.clipboard.readText(); | |
console.log('Pasted content: ', text); | |
} catch (err) { | |
console.error('Failed to read clipboard contents: ', err); | |
} | |
} |