<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Выбор варианта</title>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
</head>
<body>
<h3>Выберите один из предложенных вариантов:</h3>
<div id="variants">
<script type="text/javascript">
let tg = window.Telegram.WebApp;
tg.ready();
const path = `${window.location.origin}/userData/`;
const parsedUrl = new URL(document.URL);
const userId = tg.initDataUnsafe.user.id;
const previewImages = parsedUrl.searchParams.get("images");
const imagesArray = previewImages ? JSON.parse(previewImages) : [];
imagesArray.forEach((image, index) => {
const imgElement = document.createElement("img");
imgElement.src = path + userId + "/" + image;
imgElement.alt = `Вариант ${index + 1}`;
imgElement.style.width = "100px";
imgElement.style.margin = "5px";
imgElement.onclick = () => selectOption(index);
document.getElementById("variants").appendChild(imgElement);
});
function selectOption(index) {
const data = JSON.stringify({ selected_variant: index });
tg.sendData(data);
}
</script>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://code.jquery.com/ui/1.14.0/jquery-ui.js"></script>
<script src="jquery.ui.touch-punch.min.js"></script>
<script>
$(function () {
const $sortable = $("#sortable");
$sortable.sortable({
disabled: true,
start: function(event, ui) {
console.log('Сортировка началась');
}
});
$sortable.on("contextmenu", function (e) {
e.preventDefault();
});
$sortable.on("touchstart", function (event) {
$(this).sortable("enable");
const touch = event.originalEvent.touches[0];
const targetElement = document.elementFromPoint(touch.clientX, touch.clientY);
if ($(targetElement).closest("li").length) {
const listItem = $(targetElement).closest("li");
listItem.trigger("mousedown");
}
});
});
</script>
$(function () {
const $sortable = $("#sortable");
$sortable.sortable({
disabled: true
});
$sortable.on("contextmenu", function (e) {
e.preventDefault();
});
$sortable.on("touchstart", function (event) {
$(this).sortable("option", "disabled", false);
const touch = event.originalEvent.touches[0];
const targetElement = document.elementFromPoint(touch.clientX, touch.clientY);
$(targetElement).trigger("mousedown");
});
});
<html>
<body onload="bodyload()">
<button onclick="colorchangerclick()">newcolor</button>
<script>
function bodyload() {
document.body.addEventListener("bodybgcolorchange", () => alert("bodybgcolorchange сработало!"));
}
function colorchangerclick() {
const currentColor = document.body.style.background;
const newColor = prompt("Введите новый цвет фона (например, red, #000, rgb(0, 0, 0))");
if (newColor && newColor !== currentColor) {
document.body.style.background = newColor;
const bodybgcolorchange = new CustomEvent("bodybgcolorchange", {
detail: {
name: "bodybgcolor",
oldColor: currentColor,
newColor: newColor,
},
});
document.body.dispatchEvent(bodybgcolorchange);
}
}
</script>
</body>
</html>
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/ssl/your_domain.crt;
ssl_certificate_key /etc/nginx/ssl/your_domain.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# Прокси для WebSocket (WSS)
location /wss/ {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
}
$server = stream_socket_server("tcp://0.0.0.0:8080", $errno, $errstr);
if (!$server) {
die("Ошибка: $errstr ($errno)");
}
while ($client = stream_socket_accept($server)) {
fwrite($client, "Привет, клиент!\n");
fclose($client);
}
fclose($server);
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
require __DIR__ . '/vendor/autoload.php';
class ChatServer implements MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
echo "Новое соединение! ({$conn->resourceId})\n";
}
public function onMessage(ConnectionInterface $from, $msg) {
foreach ($this->clients as $client) {
if ($from !== $client) {
$client->send($msg);
}
}
}
public function onClose(ConnectionInterface $conn) {
$this->clients->detach($conn);
echo "Соединение {$conn->resourceId} закрыто\n";
}
public function onError(ConnectionInterface $conn, \Exception $e) {
echo "Ошибка: {$e->getMessage()}\n";
$conn->close();
}
}
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\Server\IoServer;
$server = IoServer::factory(
new HttpServer(
new WsServer(
new ChatServer()
)
),
8080
);
echo "WebSocket сервер запущен на порту 8080\n";
$server->run();
useEffect(() => {
const handlePageHide = (event) => {
if (event.persisted || performance.navigation.type === performance.navigation.TYPE_RELOAD) {
return;
} else {
QDB.edit(manager.id, { online: 0, logout_date: D_TimeNow(), navigator: navigator.userAgent }, 'users');
}
};
window.addEventListener('pagehide', handlePageHide);
return () => {
window.removeEventListener('pagehide', handlePageHide);
};
}, []);