auto refresh
This commit is contained in:
@@ -53,5 +53,6 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="/refresh.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -72,5 +72,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<p>If you want an account on any of these, want to suggest something new or get a subdomain, just message me</p>
|
<p>If you want an account on any of these, want to suggest something new or get a subdomain, just message me</p>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="/refresh.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
63
refresh.js
Normal file
63
refresh.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
(function() {
|
||||||
|
// Configuration
|
||||||
|
const SSE_PORT = 8765;
|
||||||
|
const RECONNECT_DELAY = 5000; // 5 seconds
|
||||||
|
|
||||||
|
let eventSource = null;
|
||||||
|
let reconnectTimer = null;
|
||||||
|
|
||||||
|
function connect() {
|
||||||
|
// Clear any existing reconnect timer
|
||||||
|
if (reconnectTimer) {
|
||||||
|
clearTimeout(reconnectTimer);
|
||||||
|
reconnectTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close existing connection
|
||||||
|
if (eventSource) {
|
||||||
|
eventSource.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to SSE server
|
||||||
|
const url = `${window.location.protocol}//${window.location.hostname}:${SSE_PORT}/events`;
|
||||||
|
eventSource = new EventSource(url);
|
||||||
|
|
||||||
|
eventSource.onmessage = function(event) {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(event.data);
|
||||||
|
if (data.type === 'reload') {
|
||||||
|
console.log('Repository updated, reloading page...');
|
||||||
|
// Hard reload to bypass cache
|
||||||
|
window.location.reload(true);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error parsing SSE message:', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
eventSource.onerror = function(error) {
|
||||||
|
console.log('SSE connection error, will reconnect...');
|
||||||
|
eventSource.close();
|
||||||
|
// Attempt to reconnect after delay
|
||||||
|
reconnectTimer = setTimeout(connect, RECONNECT_DELAY);
|
||||||
|
};
|
||||||
|
|
||||||
|
eventSource.onopen = function() {
|
||||||
|
console.log('Connected to auto-refresh service');
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start connection when page loads
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', connect);
|
||||||
|
} else {
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup on page unload
|
||||||
|
window.addEventListener('beforeunload', function() {
|
||||||
|
if (eventSource) {
|
||||||
|
eventSource.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
Reference in New Issue
Block a user