update
This commit is contained in:
@@ -40,13 +40,16 @@ function collectVideos(elements) {
|
||||
let pendingVideos = [];
|
||||
let sendTimer = null;
|
||||
|
||||
function queueVideos(videos) {
|
||||
async function queueVideos(videos) {
|
||||
pendingVideos.push(...videos);
|
||||
if (!sendTimer) {
|
||||
sendTimer = setTimeout(() => {
|
||||
sendTimer = setTimeout(async () => {
|
||||
if (pendingVideos.length > 0) {
|
||||
console.log(`[YT-Erfasser] ${pendingVideos.length} Videos senden`);
|
||||
browser.runtime.sendMessage(pendingVideos);
|
||||
const stored = await browser.storage.local.get("profileId");
|
||||
const profileId = stored.profileId || null;
|
||||
const batch = pendingVideos.map((v) => ({ ...v, profile_id: profileId }));
|
||||
console.log(`[YT-Erfasser] ${batch.length} Videos senden (Profil: ${profileId})`);
|
||||
browser.runtime.sendMessage(batch);
|
||||
}
|
||||
pendingVideos = [];
|
||||
sendTimer = null;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"description": "Erfasst YouTube-Videos und sendet sie an den Server",
|
||||
"permissions": [
|
||||
"*://www.youtube.com/*",
|
||||
"http://localhost:8000/*"
|
||||
"http://localhost:8000/*",
|
||||
"storage"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
@@ -15,5 +16,9 @@
|
||||
],
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"browser_action": {
|
||||
"default_popup": "popup.html",
|
||||
"default_title": "Profil auswählen"
|
||||
}
|
||||
}
|
||||
|
||||
16
browser_extension/popup.html
Normal file
16
browser_extension/popup.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body { width: 200px; padding: 10px; font-family: sans-serif; font-size: 14px; }
|
||||
h3 { margin: 0 0 8px; }
|
||||
label { display: block; padding: 4px 0; cursor: pointer; }
|
||||
.error { color: red; font-size: 12px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h3>Profil</h3>
|
||||
<div id="profiles"></div>
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
30
browser_extension/popup.js
Normal file
30
browser_extension/popup.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const SERVER_URL = "http://localhost:8000/profiles";
|
||||
const container = document.getElementById("profiles");
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const res = await fetch(SERVER_URL);
|
||||
const profiles = await res.json();
|
||||
const stored = await browser.storage.local.get("profileId");
|
||||
const selectedId = stored.profileId || null;
|
||||
|
||||
for (const profile of profiles) {
|
||||
const label = document.createElement("label");
|
||||
const radio = document.createElement("input");
|
||||
radio.type = "radio";
|
||||
radio.name = "profile";
|
||||
radio.value = profile.id;
|
||||
radio.checked = profile.id === selectedId;
|
||||
radio.addEventListener("change", () => {
|
||||
browser.storage.local.set({ profileId: profile.id });
|
||||
});
|
||||
label.appendChild(radio);
|
||||
label.appendChild(document.createTextNode(" " + profile.name));
|
||||
container.appendChild(label);
|
||||
}
|
||||
} catch {
|
||||
container.innerHTML = '<span class="error">Server nicht erreichbar</span>';
|
||||
}
|
||||
}
|
||||
|
||||
load();
|
||||
Reference in New Issue
Block a user