function fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position="fixed"; //avoid scrolling to bottom
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( "Твой текст" );
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generate_name(maxlength) {
var s = "";
var simb = 'abcdefghijklmnopqrstuwvxyz';
for (var i = 0; i < maxlength; i++) {
s = s + simb[getRandomIntInclusive(0, simb.length - 1)]
}
return s;
}
function generate_list(maxlimit) {
var arr = [];
for (let i = 1; i <= maxlimit; i++) {
arr.push({
id: "list-"+i,
name: generate_name(getRandomIntInclusive(7, 9)) + " " + generate_name(getRandomIntInclusive(10, 12))
});
}
return arr;
}
console.log( generate_list(100) );
var kb = {
"q":"й",
"w":"ц",
"e":"у",
"r":"к",
"t":"е",
"y":"н"
// и дальше
};
function chkb(s) {
var ret = '';
for(let i = 0; i < s.length; i++) {
if(s[i] in kb) {
ret = ret + kb[s[i]];
} else {
ret = ret + s[i];
}
}
return ret;
}
console.log( chkb("qwer") ); // йцук