static Update(arr) {
try {
const prop = Properties.GetContext().Get(SAVE_PROP_NAME);
const updatedArr = arr.map(item => {
const functionMap = {};
Object.entries(item).forEach(([key, value]) => {
if (typeof value === 'function') {
functionMap[key] = {name: value.name, code: value.toString()};
}
});
return {...item, ...functionMap};
});
prop.Value = JSON.stringify(updatedArr);
return true;
} catch (error) {
return false;
}
}
let emailAddress = document.querySelector('[tabindex="0"]');
let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
nativeInputValueSetter.call(emailAddress, 'Ваше_Значение');
let inputEvent = new Event('input', { bubbles: true });
emailAddress.dispatchEvent(inputEvent);
Какого его не может получить «fetch»?Через браузер вы обращаетесь от домена эндпоинта, от которого хотите получить информацию.
const proxyUrl = 'https://api.allorigins.win/get?url=';
const targetUrl = 'https://rutube.ru/api/video/37daa4e656174d04db06c5fca7548751';
fetch(proxyUrl + encodeURIComponent(targetUrl))
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
// данные могут быть внутри data.contents
console.log('Data retrieved:', JSON.parse(data.contents));
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
let block = false;
$(document).scroll(function () {
if (!block && isScrolledIntoView(".contact-start-popup")) {
block = true;
MicroModal.show('poster-popup');
}
});
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "; expires=" + date.toUTCString();
document.cookie = `${name}=${value || ""}${expires}; path=/`;
}
function getCookie(name) {
const nameEQ = `${name}=`;
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
let c = cookie.trim();
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length);
}
return null;
}
function checkRedirect() {
const lastRedirect = getCookie("lastRedirect");
const now = Date.now();
if (!lastRedirect || now - parseInt(lastRedirect) > 24 * 60 * 60 * 1000) {
setCookie("lastRedirect", now, 1);
setTimeout(() => {
window.open("https://ya.ru", "_blank");
}, 1000);
}
}
window.addEventListener('load', checkRedirect);
// requests.js
(function(global) {
function RequestToSite() {
return fetch('https://somesite.com').then(function(data) {
return data.json();
});
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
RequestToSite
};
} else {
global.RequestToSite = RequestToSite;
}
})(this);
// background.js - service_worker
import { RequestToSite } from './requests.js';
async function someFunction() {
let data = await RequestToSite();
return data;
}
<!-- index.html - content page -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example</title>
<script type="text/javascript" src="./requests.js"></script>
<script type="text/javascript" src="./main.js"></script>
</head>
<body>
<!-- Content of the page -->
</body>
</html>
// main.js
async function getSomeData() {
let data = await RequestToSite();
console.log(data);
}
// Вызов функции для проверки
getSomeData();
npm install decimal.js
const Decimal = require('decimal.js');
let number = new Decimal('37.586582183837891');
console.log(number.toString());
const Decimal = require('decimal.js');
function processNumber(input) {
let preciseNumber = new Decimal(input);
return preciseNumber;
}
let inputNumber = '37.586582183837891';
let preciseResult = processNumber(inputNumber);
console.log('Точное число:', preciseResult.toString());
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Audio Context Example</title>
</head>
<body>
<input type="file" id="fileInput" accept=".mp3">
<audio id="audioElement" controls></audio>
<script>
const fileInput = document.getElementById('fileInput');
const audioElement = document.getElementById('audioElement');
const audioContext = new AudioContext();
fileInput.addEventListener('change', () => {
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
audioElement.src = e.target.result;
const source = audioContext.createMediaElementSource(audioElement);
source.connect(audioContext.destination);
audioElement.play();
};
reader.readAsDataURL(file);
}
});
</script>
</body>
</html>
['myCheckBox1', 'myCheckBox2', 'myCheckBox3'].forEach(className => {
let element = document.querySelector(`input[class="${className}"]`);
element.setAttribute('checked', 'true');
});
...