[...document.querySelectorAll('.item')].forEach(item => {
item.addEventListener('mouseenter', function (e) {
e.target.closest('.block').style.background = '#000';
});
item.addEventListener('mouseleave', function (e) {
e.target.closest('.block').style.background = '#fff';
});
});
function Timer(t, ch) {
this.time = t;
this.channel = ch;
this.interval = setInterval(() => {
if (--this.time < 1) {
clearInterval(this.interval);
// здесь можно делать ченить с сокетом, он же полюбому глобальный
// либо сделать свои ивенты через эммитер
socket.to(this.channel).emit('TIMEOUT - STATUS ZERO');
};
}, 1000);
this.getTimeleft = () => this.time;
socket.to(this.channel).emit(`TIMER STARTS, YOU HAVE - ${this.time} SECONDS TO DO SOMETHING`);
};
var timer = new Timer(10, 'chanel2');
var timer2 = new Timer(3, 'chanel5');
document.getElementById('expiry_date').addEventListener('input', (ev) => {
let separator = ' / ';
ev.target.value = ev.target.value.replace(separator,'');
if (ev.target.value.length > 2) {
ev.target.value = ev.target.value.split('').reduce((a, v, i) => {
return a + v + (i === 1 ? separator:'');
}, '');
};
});
document.body.appendChild( renderer.domElement );
navigator.geolocation.getCurrentPosition((position) => position.coords.heading);
function factorial(n) {
if (n > 1) {
return n * factorial(n - 1);
} else {
return 1;
};
};
function S(n) {
if (n < 1) {
return 0;
} else {
return (1 / factorial(n)) + S(n - 1);
};
}
function factorial(n) {
return n > 1 ? (n * factorial(n - 1)) : 1;
}
function S(n) {
return n > 0 ? ((1 / factorial(n)) + S(n - 1)) : 0;
}
let messagesToDelete = [];
telegramBot.sendMessage('some').then((m) => {
messagesToDelete.push({
messageId: m.message_id,
chatId: m.chat.id
});
}).catch(console.error);
function wipeHistory() {
messagesToDelete.forEach(m => {
telegramBot.deleteMessage(m.chatId, m.messageId).then((success) => {
if (success) {
messagesToDelete = messagesToDelete.filter((v) => (v.messageId !== m.message_id && v.chatId !== m.chat.id));
};
}).catch(console.error);
});
};
setInterval(wipeHistory, 60 * 10 * 1000);
let someVar; // let someVar = undefined;
setTimeout(() => {
setValue('SOME VALUE');
}, 0);
console.log('Work, please! ' + someVar); // 'Work, please! undefined'
function setValue(value) {
someVar = value;
console.log('Variable Value: ' + someVar); // Variable Value: SOME VALUE
};
console.log('Work, please! ' + someVar); // 'Work, please! undefined'