Skip to content

Instantly share code, notes, and snippets.

View sabesansathananthan's full-sized avatar
:octocat:
Work

Sathananthan Sabesan sabesansathananthan

:octocat:
Work
View GitHub Profile
@sabesansathananthan
sabesansathananthan / ClipboardReadText.js
Created March 5, 2021 05:56
Clipboard Operation in JavaScript
document.body.addEventListener(
'click',
async (e) => {
const text = await navigator.clipboard.readText();
console.log(text);
}
)
@sabesansathananthan
sabesansathananthan / ReadTextTimeout.js
Created March 5, 2021 05:51
Clipboard Operation in JavaScript
setTimeout(async () => {
const text = await navigator.clipboard.readText();
console.log(text);
}, 2000);
@sabesansathananthan
sabesansathananthan / ReadText.js
Created March 5, 2021 05:48
Clipboard Operation in JavaScript
(async () => {
const text = await navigator.clipboard.readText();
console.log(text);
})();
@sabesansathananthan
sabesansathananthan / PasteText.js
Created March 5, 2021 04:09
Clipboard Operation in JavaScript
const pasteText = document.querySelector('#output');
pasteText.focus();
document.execCommand('paste');
@sabesansathananthan
sabesansathananthan / CutText.js
Created March 5, 2021 04:00
Clipboard Operation in JavaScript
const inputElement = document.querySelector('#input');
inputElement.select();
document.execCommand('cut');
@sabesansathananthan
sabesansathananthan / CopyText.js
Created March 5, 2021 03:50
Clipboard Operation in JavaScript
const inputElement = document.querySelector('#input');
inputElement.select();
document.execCommand('copy');
axios.all([
axios.get('https://api.github.com/users/sabesansathananthan'),
axios.get('https://api.github.com/users/rcvaram')
])
.then(axios.spread((obj1, obj2) => {
// Both requests are now complete
console.log(obj1.data.login + ' has ' + obj1.data.public_repos + ' public repos on GitHub');
console.log(obj2.data.login + ' has ' + obj2.data.public_repos + ' public repos on GitHub');
}));
Promise.all([
fetch('https://api.github.com/users/sabesansathananthan'),
fetch('https://api.github.com/users/rcvaram')
])
.then(async([res1, res2]) => {
const a = await res1.json();
const b = await res2.json();
console.log(a.login + ' has ' + a.public_repos + ' public repos on GitHub');
console.log(b.login + ' has ' + b.public_repos + ' public repos on GitHub');
})
import {fetch as fetchPolyfill} from 'whatwg-fetch'
window.fetch(...) // use native browser version
fetchPolyfill(...) // use polyfill implementation
axios({
method: 'post',
url: '/login',
timeout: 5000, // 5 seconds timeout
data: {
firstName: 'Sabesan',
lastName: 'Sathananthan'
}
})
.then(response => {/* handle the response */})