const menu = {
width: 200,
height: 300,
title: "My menu"
};
console.log(menu);
function multiplyNumeric(obj) {
const data = {}
for (const [key, val] of Object.entries(obj)) {
if (typeof val === 'number') {
data[key]*=2;
}
}
return {
...obj,
...data
}
const updated = multiplyNumeric(menu);
console.log(updated);
// Пример
// Перехват запроса, и блокирование если есть совпадения с url
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return {cancel: true}; },
{urls: ["*://www.domain.com/*"]},
["blocking"]);
function fillForm(form) {
var formName = form.id
var json = localStorage.getItem('form['+ formName +']')
var object = JSON.parse(json)
for (var item of Object.entries(object)) {
var key = item[0]
var value = item[1]
var input = form.querySelector('input[name='+ key +']')
input.value = value
}
}
function saveForm(form) {
var formName = form.id
var formData = new FormData(form)
var object = {}
formData.forEach(function(value, key) {
object[key] = value
})
var json = JSON.stringify(object)
localStorage.setItem('form['+ formName +']', json)
}
function syncForm(formName) {
var form = document.getElementById(formName)
fillForm(form)
form.addEventListener('submit', function(event) {
saveForm(event.target)
})
}
syncForm('registration')
telegram_api_key: 'Telegram token',
export TELEGRAM_API_KEY=TelegramToken
TELEGRAM_API_KEY=TelegramToken
require('dotenv').config()
var container = document.getElementById('yohoho')
container.addEventListener('DOMSubtreeModified', function listener(event) {
var iframe = document.getElementById('yohoho-iframe')
if (!iframe) {
// iframe еще не появился в dom
return
}
var url = iframe.src
var updated = url.replace('kLShoChnGWEE', 'LFHkCbyQOWUm')
iframe.src = updated
// Задача выполнена, можно удалить обработчик
container.removeEventListener('DOMSubtreeModified', listener)
})
window.addEventListener('DOMContentLoaded', function(){
var timerId = 0
function changeUrl() {
var iframe = document.getElementById('yohoho-iframe')
if (iframe && iframe.src) {
var url = iframe.src
var updated = url.replace('kLShoChnGWEE', 'LFHkCbyQOWUm')
iframe.src = updated
return clearTimeout(timerId)
}
// Каждые 100 мс делаем проверку на появление iframe в dom
timerId = setTimeout(changeUrl, 100)
}
changeUrl()
})
<input type="text" name="query" value="sort=new&page=1">
<input type="text" name="url" value="">
<button data-key="key1" data-value="value1">Add item 1</button>
<button data-key="key2" data-value="value2">Add item 2</button>
var $inputQuery = $('input[name=query]')
var $inputUrl = $('input[name=url]')
$('button').click(function(event) {
event.preventDefault()
var $this = $(this)
var key = $this.attr('data-key')
var value = $this.attr('data-value')
var query = $inputQuery.val()
var params = new URLSearchParams(query)
params.set(key, value)
var updatedQuery = params.toString()
$inputQuery.val(updatedQuery)
$inputUrl.val('http://test.ru/news?' + updatedQuery)
})
input query: sort=new&page=1&key2=value2&key3=value3
input url: http://test.ru/news?sort=new&page=1&key2=value2&key3=value3
// Сохранить данные
sessionStorage.setItem('username', 'Musk')
// Получить
const username sessionStorage.getItem('username')
<link rel="icon" href="/favicons/favicon.ico" type="image/x-icon">
function setFavicon(url) {
var link = document.querySelector('link[rel=icon]')
link.setAttribute('href', url)
}
function startAnimation(icons, initial) {
initial = initial === undefined ? 0 : initial
setFavicon(icons[initial])
var next = icons.length <= initial + 1 ? 0 : initial + 1
setTimeout(function () {
startAnimation(icons, next)
}, 1000)
}
var icons = [
'https://habr.com/images/favicon-32x32.png',
'https://nextjs.org/static/favicon/favicon.ico'
]
startAnimation(icons)