<html>
<head></head>
<body>
<button id="someButton">Click me</button>
<script type="module">
const someButton = document.querySelector('#someButton')
someButton.onclick = e => {
console.log(e)
// сам себя открепляет
someButton.onclick = null
}
</script>
</body>
</html>
<body style="height: 200vh;">
<div class="swiper" style="width: 50vw; height: 50vh; margin: auto; background-color: black;"></div>
</body>
const swiper = document.querySelector('.swiper')
if(swiper){
swiper.onmouseenter = () => {
const X = window.scrollX
const Y = window.scrollY
window.onscroll = () => {
window.scrollTo(X, Y)
}
swiper.onmouseleave = () => {
window.onscroll = () => null
}
}
}
<html>
<head>
<style>
:root[lang="ru-RU"] [lang="ru-RU"] {
display: block;
}
:root[lang="ru-RU"] [lang="en-US"] {
display: none;
}
:root[lang="en-US"] [lang="en-US"] {
display: block;
}
:root[lang="en-US"] [lang="ru-RU"] {
display: none;
}
</style>
</head>
<body>
<div id="root">
<div lang="ru-RU">
Содержимое на русском
</div>
<div lang="en-US">
Content in english
</div>
<button id="languageSwitcher"></button>
<script type="module">
const { documentElement } = document
documentElement.setAttribute('lang', navigator.language)
const languageSwitcherButton = documentElement.querySelector('button#languageSwitcher')
const determineLanguage = () => documentElement.getAttribute('lang') === 'ru-RU' ? 'Switch to English' : 'Переключить на Русский'
languageSwitcherButton.textContent = determineLanguage()
languageSwitcherButton.onclick = ({ target }) => {
documentElement.getAttribute('lang') === 'en-US' ? (
documentElement.setAttribute('lang', 'ru-RU')
) : documentElement.setAttribute('lang', 'en-US')
target.textContent = determineLanguage()
}
</script>
</div>
</body>
</html>
const mutationObserver = new MutationObserver(records => {
records.forEach(record => record.addedNodes.forEach(({ classList }) => {
classList?.contains('taskblackout') ? location.reload() : undefined
}))
})
mutationObserver.observe(
document.querySelector('body'), {
childList: true
}
)
setTimeout(() => {
document.body.appendChild(
document.createElement('div')
).classList.add('taskblackout')
}, 5000)
const routes = [
['USA', 'BRA'], ['JPN', 'PHL'], ['BRA', 'UAE'], ['UAE', 'JPN']
]
const length = routes.length
const start = routes.shift()
const chain = [ start ]
while(chain.length !== length){
const [ _, to ] = chain[ chain.length -1 ]
routes.forEach(([ from ], index) => {
if(to === from){
chain.push(routes[index])
}
})
}
const set = new Set()
chain.forEach(([ from, to ]) => set.add(from).add(to))
const route = []
set.forEach(any => route.push(any))
const string = route.join(',')
console.log(string)
const data = [
['A', 'B'], ['O', 'P'], // [начало], [конец (возможно)]
['E', 'F'], ['J', 'K'],
['F', 'G'], ['K', 'L'],
['N', 'O'], ['M', 'N'],
['L', 'M'], ['G', 'H'],
['B', 'C'], ['H', 'I'],
['M', 'N'], ['C', 'D'],
['D', 'E'], ['I', 'J']
]
const [ length, chain, [ start, end ], routes ] = [ data.length, [ ], [ ...data ], data.slice(2) ]
chain.push(start)
while(chain.length !== length -1){
const [ , to ] = chain[ chain.length -1 ]
routes.forEach(([ from ], index) => to === from ? chain.push(routes[ index ]) : void(0))
}
chain.push(end)
console.log(chain.map(([ from, to ], index) => index === chain.length -1 ? [ from, to ].join(',') : from).join(', '))
// $script = file_get_contents(...);
?><script type="module"><?=$script;?></script><?
const ws = new WebSocket("wss://stream.binance.com:9443/ws/xrpusdt@bookTicker")
let dd = null
ws.onmessage = (event) => {
const obj = JSON.parse(event.data)
if(obj.s=='XRPUSDT'){ /* ... */ }
dd = obj.s
console.log(dd)
}
let vv = dd
console.log(vv)