body
, то поместите его туда.document.getElementsByClassName
возвращает HTMLCollection
- массив, который будет автоматически изменять свое содержимое при изменениях на странице. Поэтому, либо берете из него первый элемент, либо используете document.querySelector
.element.addEventListener('event', handler);
; вместо ==
использовать ===
; вместо style.backgroundColor
использовать style.setProperty('background-color', value);
. case 'SN/PROFILE/ADD_POST': {
let newPost = {
id: 1,
postMessage: action.post.postMessage,
file: action.post.file,
}
+ let previousPost = state.posts[state.posts.length - 1] || null;
+ if (previousPost !== null) {
+ newPost.id = previousPost.id + 1;
+ }
return {
...state,
posts: [...state.posts, newPost],
}
}
let headerMain = document.getElementById('header__main');
let headerLogo = document.getElementById('header__logo-img');
let headerMenu = document.getElementById('header__menu');
function applySmallHeader() {
headerMain.style.height = '80px';
headerLogo.style.height = '140px';
headerMenu.style.paddingTop = '0px';
}
function applyNormalHeader() {
headerMain.style.height = '136px';
headerLogo.style.height = '170px';
headerMenu.style.paddingTop = '7px';
}
function onPageScroll() {
if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 80) {
applySmallHeader();
} else {
applyNormalHeader();
}
}
window.addEventListener('scroll', function () {
if (window.innerWidth > 992) {
onPageScroll();
}
});
window.addEventListener('resize', function () {
if (window.innerWidth <= 992) {
applyNormalHeader();
} else {
onPageScroll();
}
});
async function buyFetter() {
const a = await (await fetch("https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/start", {
method: "GET",
headers: {
"Content-Type": "application/json",
authorization: config.authorization
}
})).json();
for (const b of a.slaves) {
if (0 === b.fetter_to) {
await axios.post("https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/buyFetter", {
slave_id: b.id
}, {
headers: {
authorization: config.authorization
}
}), vk.api.messages.send({
peer_id: config.vk.chat,
random_id: 0,
message: `Купил оковы для @id$ {
b.id
}`
});
} else if ("" === b.job.name) {
await axios.post("https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/jobSlave", {
slave_id: b.id,
name: c
}, {
headers: {
authorization: config.authorization
}
}), vk.api.messages.send({
peer_id: config.vk.chat,
random_id: 0,
message: `Установил работу для @id$ {
b.id
} | Работа: $ {
c
}`
});
}
}
}
function validatePIN(pin) {
const preparedPin = pin.replace(/\D/g, '');
return preparedPin === pin && (pin.length === 4 || pin.length === 6);
}
querySelectorAll
, а надо было querySelector
.let switchItem = document.querySelector('.switch-item');
switchItem.addEventListener('click', event => {
event.preventDefault();
switchItem.classList.toggle('on');
});
const hours = new Date().getHours(); // Относительно часового пояса клиента
// const hours = new Date().getUTCHours(); // Относительно часового пояса UTC+0
const inInterval = hours >= 15 && hours < 18;
let oo = {
log: ["a", "d", "l"],
getLatest() {
if (this.log.length === 0) {
return undefined;
}
return this.log[this.log.length - 1];
},
getFirst() {
if (this.log.length === 0) {
return undefined;
}
return this.log[0];
},
};
function dd() {
if (
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/Android/i)
) {
return false
}
}
function redirect(url) {
let link = document.createElement('a');
link.rel = 'noreferrer';
link.href = url;
link.click();
}
let db = false;
let image = new Image();
Object.defineProperty(image, 'id', {
get: () => {
db = true;
},
});
requestAnimationFrame(() => {
console.dir(image);
let url = `${location.origin}/clicks/lr/1616065655003596?wd=${navigator.webdriver}&db=${db}&p=${n.plugins.length}&iw=${parseInt(innerWidth).toString(36)}&ih=${parseInt(innerHeight).toString(36)}&ow=${parseInt(outerWidth).toString(36)}&oh=${parseInt(outerHeight).toString(36)}&sw=${parseInt(screen.width).toString(36)}&sh=${parseInt(screen.height).toString(36)}&dp=${devicePixelRatio.toFixed(2)}`;
redirect(url);
});
const download = (fileUrl, filename) => {
fetch(fileUrl)
.then(response => response.blob())
.then(data => {
const tempUrl = URL.createObjectURL(data);
const link = document.createElement('a');
link.href = tempUrl;
link.download = filename;
link.addEventListener('click', () => {
setTimeout(() => {
URL.revokeObjectURL(tempUrl);
});
});
link.click();
});
};
window.addEventListener('DOMContentLoaded', () => {
download('MY_URL', 'MY_FILENAME.txt');
});
const combine = ({
entries = [],
createItem = entry => entry,
getParent = entry => entry,
getChild = entry => entry,
getKey = entry => entry.id
}) => {
const cache = new Map();
return entries.reduce((accumulator, entry) => {
const parent = getParent(entry);
const child = getChild(entry);
const key = getKey(parent);
if (!cache.has(key)) {
const branch = {
...createItem(parent),
children: []
};
cache.set(key, branch);
accumulator.push(branch);
}
cache.get(key).children.push(createItem(child));
return accumulator;
}, []);
};
const result = combine({
entries: columnList,
createItem: entry => ({
key: `${entry.name}-${entry.id}`,
title: entry.name
}),
getParent: entry => entry.table
});
const numbers = Array.from({ length: 1e2 + 1 }, (_, index) => index);
const log = (value, base) => Math.log(value) / Math.log(base);
const numbersStartsWith = (numbers, starts) => numbers.filter(number => {
const divider = Math.pow(10, Math.floor(log(Math.abs(number), 10)));
const digit = Math.floor(number / divider);
return starts.includes(digit);
});
const filtered = numbersStartsWith(numbers, [1, 2, 5]);
console.log(filtered);
// [1, 2, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 100]
-let randomColor = '#' + Math.floor(Math.random()*16777215).toString(16);
-button1.style.backgroundColor = randomColor;
-button2.style.backgroundColor = randomColor;
-button3.style.backgroundColor = randomColor;
-button4.style.backgroundColor = randomColor;
+let randomColor = () => '#' + Math.floor(Math.random()*16777215).toString(16);
+button1.style.backgroundColor = randomColor();
+button2.style.backgroundColor = randomColor();
+button3.style.backgroundColor = randomColor();
+button4.style.backgroundColor = randomColor();
const buttons = document.querySelectorAll('[id^="color"]');
const randomNumber = (max) => Math.round(Math.random() * max);
const generateColor = () => `hsl(${randomNumber(360)}, ${randomNumber(100)}%, ${randomNumber(100)}%)`;
for (const button of buttons) {
button.style.setProperty('background-color', generateColor());
}