diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-05-31 16:26:21 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-05-31 16:26:28 -0700 |
| commit | f1854f53553e201070ef5048a902e14946d4bb4b (patch) | |
| tree | e8f723e2e5499c85261d6fc6c02a8927d53d023b | |
| parent | 5ecc5a2df2aa2431a6877d8f7ca40ef7b35bab0b (diff) | |
| -rw-r--r-- | youtube-subtitle.user.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/youtube-subtitle.user.js b/youtube-subtitle.user.js index e915c94..85041bd 100644 --- a/youtube-subtitle.user.js +++ b/youtube-subtitle.user.js @@ -4,7 +4,6 @@ // @version 1.1 // @description Auto Translate Live Subtitles // @author pinapelz -// @match https://www.youtube.com/* // @grant none // @run-at document-idle // ==/UserScript== @@ -260,10 +259,23 @@ eventSource = null; } if (!reconnectTimer) { - reconnectTimer = setTimeout(() => { - reconnectTimer = null; + let attemptsLeft = 3; + const tryReconnect = () => { + if (attemptsLeft <= 0) { + reconnectTimer = null; + setSubtitleText(panel, "Connection lost. Gave up after 3 attempts."); + return; + } + attemptsLeft -= 1; connectEventSource(panel); - }, 2000); + + if (!isConnected) { + reconnectTimer = setTimeout(tryReconnect, 2000); + } else { + reconnectTimer = null; + } + }; + reconnectTimer = setTimeout(tryReconnect, 2000); } }; } |
