async function test() {
// ...
if (msg.message.text.startsWith('!kick')) {
if (await isAdmin(msg)) {
const str = msg.message.text;
const idStart = str.indexOf(' ');
const idEnd = str.indexOf(' ', idStart + 1);
const id = str.slice(idStart + 2, idEnd);
const reason = str.slice(idEnd + 1);
if ((idStart < 0) || (idEnd < 0) || (id.length === 0) || (reason.length === 0)) {
messagesend('Неверная команда.');
} else {
vk.call('messages.removeChatUser', {
chat_id: msg.message.peer_id - 2000000000,
user_id: id
});
messagesend(`🔫 Был исключен vk.com/${id} | Причина: ${reason}`);
}
} else {
notmessage();
}
}
// ...
}
$(() => {
const imagesPreview = (input, container) => {
if (input.files) {
for (const file of input.files) {
const reader = new FileReader();
reader.onload = e => {
$($.parseHTML('<img>')).attr('src', e.target.result).appendTo(container);
$($.parseHTML('<div>')).text(file.name).appendTo(container);
}
reader.readAsDataURL(file);
}
}
};
$('#gallery-photo-add').on('change', e => imagesPreview(e.currentTarget, 'div.gallery'));
});
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
function getRandomRiver(n, arr) {
const indexes = new Set();
const limit = arr.length;
n = Math.min(n, limit);
while (indexes.size < n) {
const index = Math.floor(limit * Math.random());
indexes.add(index);
}
const result = [...indexes].map(index => arr[index]);
return result;
};
const randomSet = getRandomRiver(3, arr);
console.log(randomSet);
function splitOnTwoParts(str) {
const regexp = /\([^\(\)]*\d[^\(\)]*\)/;
const innerStr = str.match(regexp)[0];
const firstPart = innerStr.slice(1, -1);
const secondPart = str.replace(innerStr, '');
return [firstPart, secondPart];
}
splitOnTwoParts("Organix (сухие корма) для собак малых пород, с курицей, Adult Dog Small Breed Chicken (12 кг)");
// ["12 кг", "Organix (сухие корма) для собак малых пород, с курицей, Adult Dog Small Breed Chicken "]
const array = [
{
name: 'Jonh',
age: 32
}, {
name: 'James',
age: 33
}, {
name: 'Jacob',
age: 33
}
];
const key = 'age';
const values = new Set();
const filtredArray = array.filter(item => {
const value = item[key];
if (!values.has(value)) {
values.add(value);
return true;
}
return false;
});
let arr = [1, 2, 3];
console.log(arr);
function clear(arr) {
arr.length = 0;
}
clear(arr);
console.log(arr);
const songsNames = [
'sokol_in.mp3',
'turtle_in.mp3',
'wolf_in.mp3',
'bear_in.mp3'
];
let audio = new Audio('sokol_in.mp3');
$('.select > div').on('click', () => {
const index = Number($(this).attr('data-val'));
audio = new Audio(songsNames[index]);
});
document.getElementById('play').addEventListener('click', () => audio.pause());
audio
, которая уничтожается при выходе из условного оператора. ($(element) as any).keydown(e => {
const {
target: {
selectionStart,
selectionEnd
},
keyCode: direction
} = e;
const htmlNode = $(this);
const inputValue = htmlNode.val();
const splittedTime = splitTime(inputValue);
const selectedValue = inputValue.substring(selectionStart, selectionEnd);
if (!selectedValue) { return; }
const Point = (x, y) => ({x, y});
const points = [Point(0, 2), Point(3, 5), Point(6, 10)];
const targetPoint = Point(selectionStart, selectionEnd);
const LEFT = 37;
const UP = 38;
const RIGHT = 39;
const DOWN = 40;
if ((direction === LEFT) || (direction === RIGHT)) {
e.preventDefault();
const index = points.findIndex(p => ((p.x === targetPoint.x) && (p.y === targetPoint.y)));
if (index === -1) { return; }
index += ((direction === LEFT) ? points.length : 1);
points.push(targetPoint);
const point = points[index % points.length];
this.setSelectionRange(point.x, point.y);
}
if ((direction === DOWN) || (direction === UP)) {
e.preventDefault();
const Actions = Enums.ValueActions;
const action = ((direction === DOWN) ? Actions.decrement : Actions. increment);
changeAppendix(splittedTime, selectedValue, htmlNode);
adjustTime(splittedTime, htmlNode, action, selectionStart, selectedValue);
this.setSelectionRange(selectionStart, selectionEnd);
}
});
['first', 'last'].forEach(term => {
jQuery(val).each((index, value) => {
const elem = jQuery(value).find(`.woocommerce-Price-amount.amount:${term}`);
let price = elem.attr('data-orig-price') / data;
price = ((valute_text === '₽')
? price.toFixed(0).toString().replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ')
: price.toFixed(2));
elem.text(price + valute_text);
});
});