const makeColor = ({selector, startClass = 'black', endClass, timeOut = 1000, }, i = 0) =>
() => new Promise((resolve) => {
setTimeout(() => {
const node = document.querySelector(selector);
const isEven = i % 2 === 0;
node.classList.remove(isEven ? startClass : endClass);
node.classList.add(isEven ? endClass : startClass);
i++;
resolve();
}, timeOut)
});
const red = makeColor({selector: '.red-item', endClass: 'red'});
const green = makeColor({selector: '.green-item', endClass: 'green'});
const yellow = makeColor({selector: '.yellow-item', endClass: 'yellow'});
red()
.then(green)
.then(yellow);
const buttons = document.querySelectorAll('button.datagrid-action[type="button"][aria-label="Добавить в любимые треки"]');
Array.from(buttons).forEach(b => {
b.click();
});
<a href="/news">News</a>
<Link to="/news">News</Link>
position: fixed;
position: sticky;
const receiveFile = (filepath, req, res) => {
const wstream = fs.createWriteStream(filepath, {flags: 'wx'});
req
.pipe(wstream)
.on('error', (e) => {
if (e.code === 'EEXIST') {
res.statusCode = 409;
res.end('File Already Exists');
return;
}
res.statusCode = 500;
res.end('Internal Server Error');
})
.on('close', () => {
res.statusCode = 201;
res.end('File Created');
});
res.on('close', () => {
if (res.finished) return;
fs.unlink(filepath, (err) => {});
});
};
import { YMaps, Map, Placemark } from "react-yandex-maps";
const mapData = {
center: [55.751574, 37.573856],
zoom: 5,
};
const coordinates = [
[55.684758, 37.738521],
[57.684758, 39.738521]
];
const App = () => (
<YMaps>
<Map defaultState={mapData}>
{coordinates.map(coordinate => <Placemark geometry={coordinate} />)}
</Map>
</YMaps>
);
const puppeteer = require('puppeteer');
const fs = require('fs');
const endOfLine = require('os').EOL;
const pageStart = "https://toster.ru/tags/?page=";
const selector = ".card__head-title a";
const fileName = "tags.txt";
const pages = 62;
(async () => {
const browser = await puppeteer.launch();
const promises = [];
for (let i = 1; i <= pages; i++) {
promises.push(browser.newPage().then(async page => {
const url = pageStart + i;
console.log(url);
await page.goto(url, {timeout: 100000});
return await page.$$eval(selector, elements => {
return Array.from(elements).map(element => element.innerText);
});
}));
}
const pagesData = await Promise.all(promises);
const logger = fs.createWriteStream(fileName, {
flags: 'a'
});
pagesDataByLines = pagesData.reduce((acc, el) => ([...acc, ...el]));
pagesDataByLines.forEach((line, index) => {
logger.write(`${index}. ${line} ${endOfLine}`);
});
await browser.close();
})();