Добавление мультиплеера и dockerfile
This commit is contained in:
41
generate.py
41
generate.py
@@ -56,6 +56,46 @@ document.addEventListener('mouseover', e => {
|
||||
}
|
||||
});
|
||||
""")
|
||||
websocket = minify("""
|
||||
(function() {
|
||||
const ws = new WebSocket(`${window.location.origin.replace(/^http(s?)/, 'ws$1')}/ws${window.location.search}`);
|
||||
ws.onopen = function(event) {
|
||||
console.log('WebSocket connected');
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
console.log('Received:', event.data);
|
||||
if (document.getElementsByName("g")[0].src != event.data) {
|
||||
document.getElementsByName("g")[0].src = event.data;
|
||||
}
|
||||
};
|
||||
ws.onclose = function(event) {
|
||||
console.log('WebSocket disconnected:', event.code, event.reason);
|
||||
};
|
||||
ws.onerror = function(error) {
|
||||
console.error('WebSocket error:', error);
|
||||
};
|
||||
window.wsSend = function(text) {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(text);
|
||||
console.log('Sent:', text);
|
||||
} else {
|
||||
console.error('WebSocket not connected. Current status:', ws.readyState);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const iframe = document.getElementsByName("g")[0];
|
||||
if (iframe) {
|
||||
iframe.addEventListener('load', () => {
|
||||
iframe.contentDocument.querySelectorAll(`a[href="../../../multiplayer"]`).forEach(link => link.remove());
|
||||
wsSend(iframe.contentWindow.location.href);
|
||||
});
|
||||
} else {
|
||||
console.error('Iframe with name "g" not found.');
|
||||
}
|
||||
});
|
||||
""")
|
||||
pages = {
|
||||
'index':
|
||||
minify(f"""<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
@@ -69,6 +109,7 @@ pages = {
|
||||
|
||||
scripts = {
|
||||
's': apply_css,
|
||||
'w': websocket,
|
||||
'p': preload,
|
||||
'a': (apply_css+preload)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user