function fallbackCopyTextToClipboard (text) {
var textArea = document.createElement('textarea')
textArea.value = text
// Avoid scrolling to bottom
textArea.style.top = '0'
textArea.style.left = '0'
textArea.style.position = 'fixed'
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
try {
var successful = document.execCommand('copy')
var msg = successful ? 'successful' : 'unsuccessful'
console.log('Fallback: Copying text command was ' + msg)
} catch (err) {
console.error('Fallback: Oops, unable to copy', err)
}
document.body.removeChild(textArea)
}
function copyTextToClipboard (text) {
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(text)
return
}
navigator.clipboard.writeText(text).then(function () {
// console.log('Async: Copying to clipboard was successful!')
}, function (err) {
console.error('Async: Could not copy text: ', err)
})
}
copyTextToClipboard(val)
{"message": "что то "тебе понравиться, давай быстрей" "}
var json = `{"message": "success", "posts": {"17": "n", "16": "\u042f \u0441 \u043a\u043e\u043d\u0441\u043e\u043b\u0438", "15": "I'm from CLI", "14": "I'm from CLI", "13": "I'm from CLI", "11": "\u0421\u0430\u043b\u043e 2", "8": "\u0421\u0430\u043b\u043e", "7": "Hello world", "6": "Hello world", "5": "Hello world", "4": "Hello world", "3": "Hello world", "2": "32", "1": "jrtu"}}
`
var data = JSON.parse(json)
console.log(data)
{
"start": 0,
"items": [],
pgSize: 50
}
// Example POST method implementation:
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
return response.json(); // parses JSON response into native JavaScript objects
}
postData('https://example.com/answer', { answer: 42 })
.then(data => {
console.log(data); // JSON data parsed by `data.json()` call
});