const links = [...document.querySelectorAll('#filter_frm table')].reduce((acc, table) => {
table.querySelectorAll('tr > td:last-child > a').forEach((link) => {
if (link.textContent.includes('300 бр.')) { // /300\s+бр\./i.test(link.textContent)
acc.push(link.href);
}
});
return acc;
}, []);
console.log(links);
fetch('https://www.kartoteka.ru/')
.then((response) => response.arrayBuffer())
.then((buffer) => {
let html = new TextDecoder('windows-1251').decode(buffer);
let doc = new DOMParser().parseFromString(html, 'text/html');
let b = doc.querySelectorAll(".news_item .image_block_no_image p")[0].innerHTML;
console.log(b);
});
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const lineWidth = 60;
const radius = 200;
[canvas.width, canvas.height] = [radius * 2, radius * 2];
context.beginPath();
context.arc(radius, radius, radius - lineWidth / 2, 0, Math.PI * 2);
context.closePath();
context.lineWidth = lineWidth;
context.stroke();
document.body.append(canvas);
Cloning a node copies all of its attributes and their values, including intrinsic (inline) listeners. It does not copy event listeners added using addEventListener() or those assigned to element properties (e.g., node.onclick = someFunction). Additionally, for a element, the painted image is not copied.
(() => {
const gif = 'https://c.tenor.com/dIJjH_qEMpUAAAAC/sully-shock-monsters.gif';
const width = 3;
const space = ' '.repeat(width);
console.log(`%c${space}`, `font-size: 158px; background-image: url(${gif}); background-position: center; background-repeat: no-repeat;`);
})();
function randn_bm() {
let u = 0, v = 0;
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
while(v === 0) v = Math.random();
let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
num = num / 10.0 + 0.5; // Translate to 0 -> 1
if (num > 1 || num < 0) return randn_bm() // resample between 0 and 1
return num
}
function randomIntegerInRange(min, max) {
return Math.floor(randn_bm() * (max - min + 1)) + min;
}
console.log(randomIntegerInRange(1, 6));
main.js
или main.ts
импортируете его:import '@fontsource/source-sans-pro';
import '@fontsource/source-sans-pro/cyrillic.css';
document.addEventListener('DOMContentLoaded', () => {
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
while (walker.nextNode()) {
const node = walker.currentNode;
if (/^hello$/i.test(node.textContent.trim())) {
node.parentNode.closest('div').hidden = true;
}
}
});
/^[a-zA-Z\n]*$/g.test('abc\ndsa')
/^([a-zA-Z]|\r\n|\r|\n)*$/g.test('abc\ndsa')
new Promise((resolve) => resolve('много вычислений')).then(console.log);
console.log('стек');
// стек
// много вычислений
head
:+ function applyTheme() {
+ const isDark = (localStorage.getItem('is-dark-theme') ?? 'true') === 'true';
+ if (isDark) {
+ document.body.classList.remove('light-mode');
+ document.body.classList.add('dark-mode');
+ } else {
+ document.body.classList.remove('dark-mode');
+ document.body.classList.add('light-mode');
+ }
+ }
- var dark = true;
function themeChange() {
- var element = document.body;
-
- if (dark == true) {
- element.classList.remove("dark-mode");
- element.classList.add("light-mode");
- dark = false;
- }
-
- else {
- element.classList.remove("light-mode");
- element.classList.add("dark-mode");
- dark = true;
- }
+ localStorage.setItem('is-dark-theme', !((localStorage.getItem('is-dark-theme') ?? 'true') === 'true'));
+ applyTheme();
}
+ window.addEventListener('DOMContentLoaded', function () {
+ applyTheme();
+ });
intlTelInput(document.querySelector('#user-phone'), {
initialCountry: 'auto',
separateDialCode: true,
geoIpLookup: function (callback) {
fetch('https://ipinfo.io/json')
.then(response => response.json())
.then(data => callback(data && data.country ? data.country : 'us'));
}
});
document.querySelectorAll('[data-seen-params]').forEach(element => {
try {
const entry = JSON.parse(element.dataset.seenParams);
if (entry?.type === 'GIFT' && 'price' in entry?.data) {
element.remove():
}
} catch (error) {}
});