This commit is contained in:
Marek Lenczewski
2026-04-15 23:07:21 +02:00
parent 1ca4371ea0
commit f439231e3c
8 changed files with 133 additions and 14 deletions

View File

@@ -1,9 +1,20 @@
const SERVER_BASE = "https://youtube.marha.de";
browser.runtime.onMessage.addListener(({ profileId, video }) => {
fetch(`${SERVER_BASE}/profiles/${profileId}/videos`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(video),
}).catch(() => {});
browser.runtime.onMessage.addListener((msg) => {
if (msg?.type === "sync-cookies") {
return syncCookies();
}
if (msg?.profileId && msg?.video) {
fetch(`${SERVER_BASE}/profiles/${msg.profileId}/videos`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(msg.video),
}).catch(() => {});
}
});
syncCookies();
browser.alarms.create("cookieSync", { periodInMinutes: 1440 });
browser.alarms.onAlarm.addListener((a) => {
if (a.name === "cookieSync") syncCookies();
});

View File

@@ -0,0 +1,37 @@
const COOKIE_SYNC_URL = "https://youtube.marha.de/cookies";
function toNetscape(cookies) {
const lines = ["# Netscape HTTP Cookie File"];
for (const c of cookies) {
const domain = c.httpOnly ? `#HttpOnly_${c.domain}` : c.domain;
const includeSubdomain = c.domain.startsWith(".") ? "TRUE" : "FALSE";
const secure = c.secure ? "TRUE" : "FALSE";
const expiration = Math.floor(c.expirationDate || 0);
lines.push([domain, includeSubdomain, c.path, secure, expiration, c.name, c.value].join("\t"));
}
return lines.join("\n") + "\n";
}
async function syncCookies() {
const when = new Date().toISOString();
try {
const cookies = await browser.cookies.getAll({ domain: ".youtube.com" });
if (cookies.length === 0) {
await browser.storage.local.set({ lastCookieSync: { when, ok: false, error: "keine YouTube-Cookies gefunden" } });
return;
}
const body = toNetscape(cookies);
const res = await fetch(COOKIE_SYNC_URL, {
method: "POST",
headers: { "Content-Type": "text/plain" },
body,
});
if (!res.ok) {
await browser.storage.local.set({ lastCookieSync: { when, ok: false, error: `HTTP ${res.status}` } });
return;
}
await browser.storage.local.set({ lastCookieSync: { when, ok: true, count: cookies.length } });
} catch (e) {
await browser.storage.local.set({ lastCookieSync: { when, ok: false, error: String(e) } });
}
}