aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-05-31 16:26:21 -0700
committerPinapelz <yukais@pinapelz.com>2026-05-31 16:26:28 -0700
commitf1854f53553e201070ef5048a902e14946d4bb4b (patch)
treee8f723e2e5499c85261d6fc6c02a8927d53d023b
parent5ecc5a2df2aa2431a6877d8f7ca40ef7b35bab0b (diff)
update subtitle userscript to give up after 3 tries of connectingHEADmain
-rw-r--r--youtube-subtitle.user.js20
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);
}
};
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage