daily bookmarks

This commit is contained in:
2025-12-02 21:21:08 +01:00
parent 3ff25d3f7e
commit 839bd24309
10 changed files with 3303 additions and 49 deletions

View File

@@ -91,6 +91,13 @@ Das Web-Interface ist erreichbar unter `http://localhost:8080`
- Den Beitrag in neuem Tab zu öffnen
- Automatisch für dein Profil abzuhaken
### Daily-Bookmarks-Seite
- Öffne `http://localhost:8080/daily-bookmarks.html` für eine eigenständige Bookmark-Übersicht
- Lege Links mit dynamischen Platzhaltern an (z.B. `{{day}}`, `{{date-1}}`)
- Markiere Bookmarks einmal pro Tag als erledigt; der Status wird in der SQLite-DB gespeichert
- Links werden pro gewähltem Tag aufgelöst, z.B. `https://www.test.de/tag-{{day}}/`
## API-Endpunkte
Das Backend stellt folgende REST-API bereit:

View File

@@ -26,6 +26,10 @@ const MAX_POST_TEXT_LENGTH = 4000;
const MIN_TEXT_HASH_LENGTH = 120;
const MAX_BOOKMARK_LABEL_LENGTH = 120;
const MAX_BOOKMARK_QUERY_LENGTH = 200;
const DAILY_BOOKMARK_TITLE_MAX_LENGTH = 160;
const DAILY_BOOKMARK_URL_MAX_LENGTH = 800;
const DAILY_BOOKMARK_NOTES_MAX_LENGTH = 800;
const DAILY_BOOKMARK_MARKER_MAX_LENGTH = 120;
const SPORTS_SCORING_DEFAULTS = {
enabled: 1,
threshold: 5,
@@ -485,6 +489,222 @@ function serializeBookmark(row) {
};
}
function formatDayKeyFromDate(date = new Date()) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
function normalizeDayKeyValue(rawValue) {
if (!rawValue && rawValue !== 0) {
return null;
}
if (rawValue instanceof Date) {
if (!Number.isNaN(rawValue.getTime())) {
return formatDayKeyFromDate(rawValue);
}
return null;
}
if (typeof rawValue !== 'string' && typeof rawValue !== 'number') {
return null;
}
const stringValue = String(rawValue).trim();
if (!stringValue) {
return null;
}
const match = stringValue.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/);
if (match) {
const year = parseInt(match[1], 10);
const month = parseInt(match[2], 10);
const day = parseInt(match[3], 10);
const parsed = new Date(year, month - 1, day);
if (
!Number.isNaN(parsed.getTime())
&& parsed.getFullYear() === year
&& parsed.getMonth() === month - 1
&& parsed.getDate() === day
) {
return formatDayKeyFromDate(parsed);
}
}
const parsed = new Date(stringValue);
if (!Number.isNaN(parsed.getTime())) {
return formatDayKeyFromDate(parsed);
}
return null;
}
function resolveDayKey(dayKey, { defaultToToday = true } = {}) {
const normalized = normalizeDayKeyValue(dayKey);
if (normalized) {
return normalized;
}
return defaultToToday ? formatDayKeyFromDate() : null;
}
function dayKeyToDate(dayKey) {
const normalized = resolveDayKey(dayKey);
const match = normalized.match(/^(\d{4})-(\d{2})-(\d{2})$/);
if (!match) {
return new Date();
}
const year = parseInt(match[1], 10);
const month = parseInt(match[2], 10);
const day = parseInt(match[3], 10);
return new Date(year, month - 1, day);
}
function addDays(date, offsetDays = 0) {
const base = date instanceof Date ? date : new Date();
const result = new Date(base);
result.setDate(result.getDate() + offsetDays);
return result;
}
const DAILY_PLACEHOLDER_PATTERN = /\{\{\s*([^}]+)\s*\}\}/gi;
function resolveDynamicUrlTemplate(template, dayKey) {
if (typeof template !== 'string') {
return '';
}
const baseDayKey = resolveDayKey(dayKey);
const baseDate = dayKeyToDate(baseDayKey);
return template.replace(DAILY_PLACEHOLDER_PATTERN, (_match, contentRaw) => {
const content = (contentRaw || '').trim();
if (!content) {
return '';
}
const counterMatch = content.match(/^counter:\s*([+-]?\d+)([+-]\d+)?$/i);
if (counterMatch) {
const base = parseInt(counterMatch[1], 10);
const offset = counterMatch[2] ? parseInt(counterMatch[2], 10) || 0 : 0;
if (Number.isNaN(base)) {
return '';
}
const date = addDays(baseDate, offset);
return String(base + date.getDate());
}
const placeholderMatch = content.match(/^(date|day|dd|mm|month|yyyy|yy)([+-]\d+)?$/i);
if (!placeholderMatch) {
return content;
}
const token = String(placeholderMatch[1] || '').toLowerCase();
const offset = placeholderMatch[2] ? parseInt(placeholderMatch[2], 10) || 0 : 0;
const date = addDays(baseDate, offset);
switch (token) {
case 'date':
return formatDayKeyFromDate(date);
case 'day':
return String(date.getDate());
case 'dd':
return String(date.getDate()).padStart(2, '0');
case 'month':
case 'mm':
return String(date.getMonth() + 1).padStart(2, '0');
case 'yyyy':
return String(date.getFullYear());
case 'yy':
return String(date.getFullYear()).slice(-2);
default:
return token;
}
});
}
function normalizeDailyBookmarkTitle(value, fallback = '') {
const source = typeof value === 'string' ? value : fallback;
let title = (source || '').trim();
if (!title && fallback) {
title = String(fallback || '').trim();
}
if (!title) {
title = 'Bookmark';
}
title = title.replace(/\s+/g, ' ');
if (title.length > DAILY_BOOKMARK_TITLE_MAX_LENGTH) {
title = title.slice(0, DAILY_BOOKMARK_TITLE_MAX_LENGTH);
}
return title;
}
function normalizeDailyBookmarkUrlTemplate(value) {
if (typeof value !== 'string') {
return null;
}
let template = value.trim();
if (!template) {
return null;
}
if (template.length > DAILY_BOOKMARK_URL_MAX_LENGTH) {
template = template.slice(0, DAILY_BOOKMARK_URL_MAX_LENGTH);
}
return template;
}
function normalizeDailyBookmarkNotes(value) {
if (typeof value !== 'string') {
return '';
}
let notes = value.trim();
if (notes.length > DAILY_BOOKMARK_NOTES_MAX_LENGTH) {
notes = notes.slice(0, DAILY_BOOKMARK_NOTES_MAX_LENGTH);
}
return notes;
}
function normalizeDailyBookmarkMarker(value) {
if (typeof value !== 'string') {
return '';
}
let marker = value.trim();
marker = marker.replace(/\s+/g, ' ');
if (marker.length > DAILY_BOOKMARK_MARKER_MAX_LENGTH) {
marker = marker.slice(0, DAILY_BOOKMARK_MARKER_MAX_LENGTH);
}
return marker;
}
function serializeDailyBookmark(row, dayKey) {
if (!row) {
return null;
}
const resolvedDayKey = resolveDayKey(dayKey);
const resolvedUrl = resolveDynamicUrlTemplate(row.url_template, resolvedDayKey);
return {
id: row.id,
title: row.title,
url_template: row.url_template,
marker: row.marker || '',
resolved_url: resolvedUrl,
notes: row.notes || '',
created_at: sqliteTimestampToUTC(row.created_at),
updated_at: sqliteTimestampToUTC(row.updated_at),
last_completed_at: sqliteTimestampToUTC(row.last_completed_at),
completed_for_day: !!row.completed_for_day,
day_key: resolvedDayKey
};
}
function normalizeFacebookPostUrl(rawValue) {
if (typeof rawValue !== 'string') {
return null;
@@ -927,6 +1147,136 @@ const updateBookmarkLastClickedStmt = db.prepare(`
WHERE id = ?
`);
db.exec(`
CREATE TABLE IF NOT EXISTS daily_bookmarks (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
url_template TEXT NOT NULL,
notes TEXT,
marker TEXT DEFAULT '',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
`);
db.exec(`
CREATE TABLE IF NOT EXISTS daily_bookmark_checks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bookmark_id TEXT NOT NULL,
day_key TEXT NOT NULL,
completed_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (bookmark_id) REFERENCES daily_bookmarks(id) ON DELETE CASCADE,
UNIQUE(bookmark_id, day_key)
);
`);
db.exec(`
CREATE INDEX IF NOT EXISTS idx_daily_bookmark_checks_day
ON daily_bookmark_checks(day_key);
`);
db.exec(`
CREATE INDEX IF NOT EXISTS idx_daily_bookmarks_updated
ON daily_bookmarks(updated_at);
`);
ensureColumn('daily_bookmarks', 'marker', 'marker TEXT DEFAULT \'\'');
const listDailyBookmarksStmt = db.prepare(`
SELECT
b.id,
b.title,
b.url_template,
b.notes,
b.marker,
b.created_at,
b.updated_at,
(
SELECT MAX(completed_at)
FROM daily_bookmark_checks c
WHERE c.bookmark_id = b.id
) AS last_completed_at,
EXISTS(
SELECT 1
FROM daily_bookmark_checks c
WHERE c.bookmark_id = b.id
AND c.day_key = @dayKey
) AS completed_for_day
FROM daily_bookmarks b
ORDER BY datetime(b.updated_at) DESC, datetime(b.created_at) DESC, b.title COLLATE NOCASE
`);
const getDailyBookmarkStmt = db.prepare(`
SELECT
b.id,
b.title,
b.url_template,
b.notes,
b.marker,
b.created_at,
b.updated_at,
(
SELECT MAX(completed_at)
FROM daily_bookmark_checks c
WHERE c.bookmark_id = b.id
) AS last_completed_at,
EXISTS(
SELECT 1
FROM daily_bookmark_checks c
WHERE c.bookmark_id = b.id
AND c.day_key = @dayKey
) AS completed_for_day
FROM daily_bookmarks b
WHERE b.id = @bookmarkId
`);
const insertDailyBookmarkStmt = db.prepare(`
INSERT INTO daily_bookmarks (id, title, url_template, notes, marker)
VALUES (@id, @title, @url_template, @notes, @marker)
`);
const findDailyBookmarkByUrlStmt = db.prepare(`
SELECT id
FROM daily_bookmarks
WHERE LOWER(url_template) = LOWER(?)
LIMIT 1
`);
const findOtherDailyBookmarkByUrlStmt = db.prepare(`
SELECT id
FROM daily_bookmarks
WHERE LOWER(url_template) = LOWER(@url)
AND id <> @id
LIMIT 1
`);
const updateDailyBookmarkStmt = db.prepare(`
UPDATE daily_bookmarks
SET title = @title,
url_template = @url_template,
notes = @notes,
marker = @marker,
updated_at = CURRENT_TIMESTAMP
WHERE id = @id
`);
const deleteDailyBookmarkStmt = db.prepare(`
DELETE FROM daily_bookmarks
WHERE id = ?
`);
const upsertDailyBookmarkCheckStmt = db.prepare(`
INSERT INTO daily_bookmark_checks (bookmark_id, day_key)
VALUES (@bookmarkId, @dayKey)
ON CONFLICT(bookmark_id, day_key) DO NOTHING
`);
const deleteDailyBookmarkCheckStmt = db.prepare(`
DELETE FROM daily_bookmark_checks
WHERE bookmark_id = @bookmarkId
AND day_key = @dayKey
`);
ensureColumn('posts', 'checked_count', 'checked_count INTEGER DEFAULT 0');
ensureColumn('posts', 'screenshot_path', 'screenshot_path TEXT');
ensureColumn('posts', 'created_by_profile', 'created_by_profile INTEGER');
@@ -1936,8 +2286,13 @@ const selectAlternateUrlsForPostStmt = db.prepare(`
ORDER BY created_at ASC
`);
const selectPostByTextHashStmt = db.prepare('SELECT * FROM posts WHERE post_text_hash = ?');
const selectChecksForPostStmt = db.prepare('SELECT id, profile_number, checked_at FROM checks WHERE post_id = ?');
const updateCheckPostStmt = db.prepare('UPDATE checks SET post_id = ? WHERE id = ?');
const updateCheckTimestampStmt = db.prepare('UPDATE checks SET checked_at = ? WHERE id = ?');
const deleteCheckByIdStmt = db.prepare('DELETE FROM checks WHERE id = ?');
function storePostUrls(postId, primaryUrl, additionalUrls = []) {
function storePostUrls(postId, primaryUrl, additionalUrls = [], options = {}) {
const { skipContentKeyCheck = false } = options;
if (!postId || !primaryUrl) {
return;
}
@@ -1956,16 +2311,18 @@ function storePostUrls(postId, primaryUrl, additionalUrls = []) {
continue;
}
if (!skipContentKeyCheck) {
const candidateKey = extractFacebookContentKey(normalized);
if (!candidateKey || candidateKey !== primaryKey) {
continue;
}
}
const existingPostId = findPostIdByUrl(normalized);
if (existingPostId && existingPostId !== postId) {
continue;
}
insertPostUrlStmt.run(postId, normalized, 0);
insertPostUrlStmt.run(postId, normalized);
}
}
}
@@ -2289,6 +2646,276 @@ app.delete('/api/bookmarks/:bookmarkId', (req, res) => {
}
});
app.get('/api/daily-bookmarks', (req, res) => {
const dayKey = resolveDayKey(req.query && req.query.day);
try {
const rows = listDailyBookmarksStmt.all({ dayKey });
res.json(rows.map((row) => serializeDailyBookmark(row, dayKey)));
} catch (error) {
console.error('Failed to load daily bookmarks:', error);
res.status(500).json({ error: 'Daily Bookmarks konnten nicht geladen werden' });
}
});
app.post('/api/daily-bookmarks', (req, res) => {
const payload = req.body || {};
const rawDay = (payload && payload.day) || (req.query && req.query.day);
const dayKey = rawDay ? normalizeDayKeyValue(rawDay) : resolveDayKey(rawDay);
if (!dayKey) {
return res.status(400).json({ error: 'Ungültiges Tagesformat' });
}
const normalizedUrl = normalizeDailyBookmarkUrlTemplate(payload.url_template || payload.url);
const normalizedTitle = normalizeDailyBookmarkTitle(payload.title || payload.label, normalizedUrl);
const normalizedNotes = normalizeDailyBookmarkNotes(payload.notes);
const normalizedMarker = normalizeDailyBookmarkMarker(payload.marker || payload.tag);
if (!normalizedUrl) {
return res.status(400).json({ error: 'URL-Template ist erforderlich' });
}
if (findDailyBookmarkByUrlStmt.get(normalizedUrl)) {
return res.status(409).json({ error: 'Bookmark mit dieser URL existiert bereits' });
}
try {
const id = uuidv4();
insertDailyBookmarkStmt.run({
id,
title: normalizedTitle,
url_template: normalizedUrl,
notes: normalizedNotes,
marker: normalizedMarker
});
upsertDailyBookmarkCheckStmt.run({ bookmarkId: id, dayKey });
const saved = getDailyBookmarkStmt.get({ bookmarkId: id, dayKey });
res.status(201).json(serializeDailyBookmark(saved, dayKey));
} catch (error) {
console.error('Failed to create daily bookmark:', error);
res.status(500).json({ error: 'Daily Bookmark konnte nicht erstellt werden' });
}
});
app.post('/api/daily-bookmarks/import', (req, res) => {
const payload = req.body || {};
const rawDay = (payload && payload.day) || (req.query && req.query.day);
const dayKey = rawDay ? normalizeDayKeyValue(rawDay) : resolveDayKey(rawDay);
if (!dayKey) {
return res.status(400).json({ error: 'Ungültiges Tagesformat' });
}
const normalizedMarker = normalizeDailyBookmarkMarker(payload.marker || payload.tag);
const collected = [];
const addValue = (value) => {
if (typeof value !== 'string') {
return;
}
const trimmed = value.trim();
if (trimmed) {
collected.push(trimmed);
}
};
if (Array.isArray(payload.urls)) {
payload.urls.forEach(addValue);
}
if (Array.isArray(payload.url_templates)) {
payload.url_templates.forEach(addValue);
}
if (typeof payload.text === 'string') {
payload.text.split(/\r?\n|,/).forEach(addValue);
}
if (typeof payload.urls_text === 'string') {
payload.urls_text.split(/\r?\n|,/).forEach(addValue);
}
const inputCount = collected.length;
if (!inputCount) {
return res.status(400).json({ error: 'Keine URLs zum Import übergeben' });
}
const normalizedTemplates = collected
.map((raw) => normalizeDailyBookmarkUrlTemplate(raw))
.filter(Boolean);
const invalidCount = inputCount - normalizedTemplates.length;
const uniqueTemplates = [...new Set(normalizedTemplates)];
const duplicateCount = normalizedTemplates.length - uniqueTemplates.length;
const createdItems = [];
let skippedExisting = 0;
const insertMany = db.transaction((templates) => {
for (const template of templates) {
if (findDailyBookmarkByUrlStmt.get(template)) {
skippedExisting += 1;
continue;
}
const id = uuidv4();
const title = normalizeDailyBookmarkTitle('', template);
insertDailyBookmarkStmt.run({
id,
title,
url_template: template,
notes: '',
marker: normalizedMarker
});
upsertDailyBookmarkCheckStmt.run({ bookmarkId: id, dayKey });
const saved = getDailyBookmarkStmt.get({ bookmarkId: id, dayKey });
if (saved) {
createdItems.push(saved);
}
}
});
try {
insertMany(uniqueTemplates);
res.json({
created: createdItems.length,
skipped_existing: skippedExisting,
skipped_invalid: invalidCount,
skipped_duplicates: duplicateCount,
marker: normalizedMarker,
day_key: dayKey,
items: createdItems.map((row) => serializeDailyBookmark(row, dayKey))
});
} catch (error) {
console.error('Failed to import daily bookmarks:', error);
res.status(500).json({ error: 'Import fehlgeschlagen' });
}
});
app.put('/api/daily-bookmarks/:bookmarkId', (req, res) => {
const { bookmarkId } = req.params;
if (!bookmarkId) {
return res.status(400).json({ error: 'Bookmark-ID fehlt' });
}
const payload = req.body || {};
const rawDay = (payload && payload.day) || (req.query && req.query.day);
const dayKey = rawDay ? normalizeDayKeyValue(rawDay) : resolveDayKey(rawDay);
if (!dayKey) {
return res.status(400).json({ error: 'Ungültiges Tagesformat' });
}
const existing = getDailyBookmarkStmt.get({ bookmarkId, dayKey });
if (!existing) {
return res.status(404).json({ error: 'Bookmark nicht gefunden' });
}
const normalizedUrl = normalizeDailyBookmarkUrlTemplate(
payload.url_template ?? payload.url ?? existing.url_template
);
const normalizedTitle = normalizeDailyBookmarkTitle(
payload.title ?? payload.label ?? existing.title,
normalizedUrl || existing.url_template
);
const normalizedNotes = normalizeDailyBookmarkNotes(
payload.notes ?? existing.notes ?? ''
);
const normalizedMarker = normalizeDailyBookmarkMarker(
payload.marker ?? existing.marker ?? ''
);
if (!normalizedUrl) {
return res.status(400).json({ error: 'URL-Template ist erforderlich' });
}
const otherWithUrl = findOtherDailyBookmarkByUrlStmt.get({
url: normalizedUrl,
id: bookmarkId
});
if (otherWithUrl) {
return res.status(409).json({ error: 'Bookmark mit dieser URL existiert bereits' });
}
try {
updateDailyBookmarkStmt.run({
id: bookmarkId,
title: normalizedTitle,
url_template: normalizedUrl,
notes: normalizedNotes,
marker: normalizedMarker
});
const updated = getDailyBookmarkStmt.get({ bookmarkId, dayKey });
res.json(serializeDailyBookmark(updated, dayKey));
} catch (error) {
console.error('Failed to update daily bookmark:', error);
res.status(500).json({ error: 'Daily Bookmark konnte nicht aktualisiert werden' });
}
});
app.delete('/api/daily-bookmarks/:bookmarkId', (req, res) => {
const { bookmarkId } = req.params;
if (!bookmarkId) {
return res.status(400).json({ error: 'Bookmark-ID fehlt' });
}
try {
const result = deleteDailyBookmarkStmt.run(bookmarkId);
if (!result.changes) {
return res.status(404).json({ error: 'Bookmark nicht gefunden' });
}
res.status(204).send();
} catch (error) {
console.error('Failed to delete daily bookmark:', error);
res.status(500).json({ error: 'Daily Bookmark konnte nicht gelöscht werden' });
}
});
app.post('/api/daily-bookmarks/:bookmarkId/check', (req, res) => {
const { bookmarkId } = req.params;
if (!bookmarkId) {
return res.status(400).json({ error: 'Bookmark-ID fehlt' });
}
const rawDay = (req.body && req.body.day) || (req.query && req.query.day);
const dayKey = rawDay ? normalizeDayKeyValue(rawDay) : resolveDayKey(rawDay);
if (!dayKey) {
return res.status(400).json({ error: 'Ungültiges Tagesformat' });
}
try {
const existing = getDailyBookmarkStmt.get({ bookmarkId, dayKey });
if (!existing) {
return res.status(404).json({ error: 'Bookmark nicht gefunden' });
}
upsertDailyBookmarkCheckStmt.run({ bookmarkId, dayKey });
const updated = getDailyBookmarkStmt.get({ bookmarkId, dayKey });
res.json(serializeDailyBookmark(updated, dayKey));
} catch (error) {
console.error('Failed to complete daily bookmark:', error);
res.status(500).json({ error: 'Daily Bookmark konnte nicht abgehakt werden' });
}
});
app.delete('/api/daily-bookmarks/:bookmarkId/check', (req, res) => {
const { bookmarkId } = req.params;
if (!bookmarkId) {
return res.status(400).json({ error: 'Bookmark-ID fehlt' });
}
const rawDay = (req.body && req.body.day) || (req.query && req.query.day);
const dayKey = rawDay ? normalizeDayKeyValue(rawDay) : resolveDayKey(rawDay);
if (!dayKey) {
return res.status(400).json({ error: 'Ungültiges Tagesformat' });
}
try {
const existing = getDailyBookmarkStmt.get({ bookmarkId, dayKey });
if (!existing) {
return res.status(404).json({ error: 'Bookmark nicht gefunden' });
}
deleteDailyBookmarkCheckStmt.run({ bookmarkId, dayKey });
const updated = getDailyBookmarkStmt.get({ bookmarkId, dayKey });
res.json(serializeDailyBookmark(updated, dayKey));
} catch (error) {
console.error('Failed to undo daily bookmark completion:', error);
res.status(500).json({ error: 'Daily Bookmark konnte nicht zurückgesetzt werden' });
}
});
// Get all posts
app.get('/api/events', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
@@ -3188,6 +3815,183 @@ app.patch('/api/posts/:postId', (req, res) => {
}
});
app.post('/api/posts/merge', (req, res) => {
const { primary_post_id, secondary_post_id, primary_url } = req.body || {};
if (!primary_post_id || !secondary_post_id) {
return res.status(400).json({ error: 'primary_post_id und secondary_post_id sind erforderlich' });
}
if (primary_post_id === secondary_post_id) {
return res.status(400).json({ error: 'Die Post-IDs müssen unterschiedlich sein' });
}
try {
const primaryPost = db.prepare('SELECT * FROM posts WHERE id = ?').get(primary_post_id);
const secondaryPost = db.prepare('SELECT * FROM posts WHERE id = ?').get(secondary_post_id);
if (!primaryPost || !secondaryPost) {
return res.status(404).json({ error: 'Einer der Beiträge wurde nicht gefunden' });
}
const normalizedPrimaryUrl = primary_url
? normalizeFacebookPostUrl(primary_url)
: normalizeFacebookPostUrl(primaryPost.url);
if (!normalizedPrimaryUrl) {
return res.status(400).json({ error: 'primary_url ist ungültig' });
}
const conflictId = findPostIdByUrl(normalizedPrimaryUrl);
if (conflictId && conflictId !== primary_post_id && conflictId !== secondary_post_id) {
return res.status(409).json({ error: 'Die gewählte Haupt-URL gehört bereits zu einem anderen Beitrag' });
}
const collectUrlsForPost = (post) => {
const urls = [];
if (post && post.url) {
urls.push(post.url);
}
if (post && post.id) {
const alternates = selectAlternateUrlsForPostStmt.all(post.id).map(row => row.url);
urls.push(...alternates);
}
return urls;
};
const mergedUrlSet = new Set();
for (const url of [...collectUrlsForPost(primaryPost), ...collectUrlsForPost(secondaryPost)]) {
const normalized = normalizeFacebookPostUrl(url);
if (normalized) {
mergedUrlSet.add(normalized);
}
}
mergedUrlSet.add(normalizedPrimaryUrl);
const alternateUrls = Array.from(mergedUrlSet).filter(url => url !== normalizedPrimaryUrl);
const mergedDeadline = (() => {
if (primaryPost.deadline_at && secondaryPost.deadline_at) {
return new Date(primaryPost.deadline_at) <= new Date(secondaryPost.deadline_at)
? primaryPost.deadline_at
: secondaryPost.deadline_at;
}
return primaryPost.deadline_at || secondaryPost.deadline_at || null;
})();
const mergedTargetCount = Math.max(
validateTargetCount(primaryPost.target_count) || 1,
validateTargetCount(secondaryPost.target_count) || 1
);
const mergedPostText = (primaryPost.post_text && primaryPost.post_text.trim())
? primaryPost.post_text
: (secondaryPost.post_text || null);
const normalizedMergedPostText = mergedPostText ? normalizePostText(mergedPostText) : null;
const mergedPostTextHash = normalizedMergedPostText
? computePostTextHash(normalizedMergedPostText)
: null;
const mergedCreatorName = (primaryPost.created_by_name && primaryPost.created_by_name.trim())
? primaryPost.created_by_name
: (secondaryPost.created_by_name || null);
const mergedCreatorProfile = primaryPost.created_by_profile || secondaryPost.created_by_profile || null;
const mergedTitle = (primaryPost.title && primaryPost.title.trim())
? primaryPost.title
: (secondaryPost.title || null);
const mergeTransaction = db.transaction(() => {
// Move checks from secondary to primary (one per profile)
const primaryChecks = selectChecksForPostStmt.all(primary_post_id);
const secondaryChecks = selectChecksForPostStmt.all(secondary_post_id);
const primaryByProfile = new Map();
for (const check of primaryChecks) {
if (!check || !check.profile_number) {
continue;
}
const existing = primaryByProfile.get(check.profile_number);
if (!existing) {
primaryByProfile.set(check.profile_number, check);
} else {
if (new Date(check.checked_at) < new Date(existing.checked_at)) {
primaryByProfile.set(check.profile_number, check);
} else {
deleteCheckByIdStmt.run(check.id);
}
}
}
for (const check of secondaryChecks) {
if (!check || !check.profile_number) {
continue;
}
const existing = primaryByProfile.get(check.profile_number);
if (!existing) {
updateCheckPostStmt.run(primary_post_id, check.id);
primaryByProfile.set(check.profile_number, check);
} else {
const existingDate = new Date(existing.checked_at);
const candidateDate = new Date(check.checked_at);
if (candidateDate < existingDate) {
updateCheckTimestampStmt.run(check.checked_at, existing.id);
}
deleteCheckByIdStmt.run(check.id);
}
}
// Delete secondary post (post_urls are cascaded)
db.prepare('DELETE FROM posts WHERE id = ?').run(secondary_post_id);
const primaryContentKey = extractFacebookContentKey(normalizedPrimaryUrl);
db.prepare(`
UPDATE posts
SET url = ?, content_key = ?, target_count = ?, created_by_name = ?, created_by_profile = ?,
deadline_at = ?, title = ?, post_text = ?, post_text_hash = ?, last_change = CURRENT_TIMESTAMP
WHERE id = ?
`).run(
normalizedPrimaryUrl,
primaryContentKey || null,
mergedTargetCount,
mergedCreatorName,
mergedCreatorProfile,
mergedDeadline,
mergedTitle,
normalizedMergedPostText,
mergedPostTextHash,
primary_post_id
);
storePostUrls(primary_post_id, normalizedPrimaryUrl, alternateUrls, { skipContentKeyCheck: true });
recalcCheckedCount(primary_post_id);
const updated = db.prepare('SELECT * FROM posts WHERE id = ?').get(primary_post_id);
return updated;
});
const merged = mergeTransaction();
if (secondaryPost && secondaryPost.screenshot_path) {
const secondaryFile = path.join(screenshotDir, secondaryPost.screenshot_path);
if (fs.existsSync(secondaryFile)) {
try {
fs.unlinkSync(secondaryFile);
} catch (cleanupError) {
console.warn('Konnte Screenshot des zusammengeführten Beitrags nicht entfernen:', cleanupError.message);
}
}
}
const mapped = mapPostRow(merged);
broadcastPostChange(mapped, { reason: 'merged' });
broadcastPostDeletion(secondary_post_id, { reason: 'merged' });
res.json(mapped);
} catch (error) {
console.error('Merge failed:', error);
res.status(500).json({ error: 'Beiträge konnten nicht gemerged werden' });
}
});
// Delete post
app.delete('/api/posts/:postId', (req, res) => {
try {
@@ -3526,8 +4330,16 @@ function sanitizeAIComment(text) {
return '';
}
// Clean up AI output: drop hidden tags, replace dashes, normalize spacing.
return text
.replace(/<think>[\s\S]*?<\/think>/gi, '')
.replace(/[-–—]+/g, (match, offset, full) => {
const prev = full[offset - 1];
const next = full[offset + match.length];
const prevIsWord = prev && /[A-Za-z0-9ÄÖÜäöüß]/.test(prev);
const nextIsWord = next && /[A-Za-z0-9ÄÖÜäöüß]/.test(next);
return prevIsWord && nextIsWord ? match : ', ';
})
.replace(/\s{2,}/g, ' ')
.trim();
}

View File

@@ -3434,6 +3434,7 @@ let selectionAINoteButton = null;
let selectionAIRaf = null;
let selectionAIHideTimeout = null;
let selectionAIEnabledCached = null;
let selectionAIContextElement = null;
const clearSelectionAIHideTimeout = () => {
if (selectionAIHideTimeout) {
@@ -3447,6 +3448,7 @@ const hideSelectionAIButton = () => {
if (selectionAIContainer) {
selectionAIContainer.style.display = 'none';
}
selectionAIContextElement = null;
if (selectionAIButton) {
selectionAIButton.dataset.selectionText = '';
}
@@ -3511,10 +3513,12 @@ const ensureSelectionAIButton = () => {
showToast('Textauswahl aus Eingabefeldern kann nicht genutzt werden', 'error');
return;
}
const anchorElement = anchorNode && anchorNode.nodeType === Node.TEXT_NODE
? anchorNode.parentElement
: anchorNode;
const postContext = anchorElement ? ensurePrimaryPostElement(anchorElement) : null;
const postContext = selectionAIContextElement
|| (anchorElement ? ensurePrimaryPostElement(anchorElement) : null);
if (!postContext) {
showToast('Keinen zugehörigen Beitrag gefunden', 'error');
return;
@@ -3669,6 +3673,18 @@ const updateSelectionAIButton = async () => {
return;
}
const contextElement = (() => {
const containerNode = range.commonAncestorContainer || anchorNode;
if (!containerNode) {
return null;
}
const element = containerNode.nodeType === Node.TEXT_NODE
? containerNode.parentElement
: containerNode;
return element ? ensurePrimaryPostElement(element) : null;
})();
selectionAIContextElement = contextElement;
const container = ensureSelectionAIButton();
if (!selectionAIButton || !selectionAINoteButton) {
hideSelectionAIButton();
@@ -4636,8 +4652,7 @@ function sanitizeAIComment(comment) {
* Generate AI comment for a post
*/
async function generateAIComment(postText, profileNumber, options = {}) {
const { signal = null, preferredCredentialId = null } = options;
try {
const { signal = null, preferredCredentialId = null, maxAttempts = 3 } = options;
const payload = {
postText,
profileNumber
@@ -4647,6 +4662,11 @@ async function generateAIComment(postText, profileNumber, options = {}) {
payload.preferredCredentialId = preferredCredentialId;
}
let lastError = null;
const attempts = Math.max(1, maxAttempts);
for (let attempt = 1; attempt <= attempts; attempt += 1) {
try {
const response = await backendFetch(`${API_URL}/ai/generate-comment`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -4662,16 +4682,23 @@ async function generateAIComment(postText, profileNumber, options = {}) {
const data = await response.json();
const sanitizedComment = sanitizeAIComment(data.comment);
if (!sanitizedComment) {
throw new Error('AI-Antwort enthält keinen gültigen Text');
}
if (sanitizedComment) {
return sanitizedComment;
} catch (error) {
console.error('[FB Tracker] AI comment generation failed:', error);
throw error;
}
lastError = new Error('AI response empty');
} catch (error) {
lastError = error;
}
if (attempt < attempts) {
console.warn(`[FB Tracker] AI comment generation attempt ${attempt} failed, retrying...`, lastError);
await delay(200);
}
}
console.error('[FB Tracker] AI comment generation failed after retries:', lastError);
throw new Error('AI-Antwort konnte nicht erzeugt werden. Bitte später erneut versuchen.');
}
async function handleSelectionAIRequest(selectionText, sendResponse) {

View File

@@ -5,12 +5,15 @@ COPY posts.html /usr/share/nginx/html/
COPY dashboard.html /usr/share/nginx/html/
COPY settings.html /usr/share/nginx/html/
COPY bookmarks.html /usr/share/nginx/html/
COPY daily-bookmarks.html /usr/share/nginx/html/
COPY style.css /usr/share/nginx/html/
COPY dashboard.css /usr/share/nginx/html/
COPY settings.css /usr/share/nginx/html/
COPY daily-bookmarks.css /usr/share/nginx/html/
COPY app.js /usr/share/nginx/html/
COPY dashboard.js /usr/share/nginx/html/
COPY settings.js /usr/share/nginx/html/
COPY daily-bookmarks.js /usr/share/nginx/html/
COPY assets /usr/share/nginx/html/assets/
EXPOSE 80

View File

@@ -20,6 +20,9 @@ let currentTab = 'pending';
let posts = [];
let includeExpiredPosts = false;
let profilePollTimer = null;
const MERGE_MAX_SELECTION = 2;
let mergeMode = false;
const mergeSelection = new Set();
const UPDATES_RECONNECT_DELAY = 5000;
let updatesEventSource = null;
let updatesReconnectTimer = null;
@@ -232,11 +235,17 @@ const bookmarkForm = document.getElementById('bookmarkForm');
const bookmarkNameInput = document.getElementById('bookmarkName');
const bookmarkQueryInput = document.getElementById('bookmarkQuery');
const bookmarkCancelBtn = document.getElementById('bookmarkCancelBtn');
const bookmarkQuickForm = document.getElementById('bookmarkQuickForm');
const bookmarkQuickQueryInput = document.getElementById('bookmarkQuickQuery');
const bookmarkQuickStatus = document.getElementById('bookmarkQuickStatus');
const bookmarkSearchInput = document.getElementById('bookmarkSearchInput');
const bookmarkSortSelect = document.getElementById('bookmarkSortSelect');
const bookmarkSortDirectionToggle = document.getElementById('bookmarkSortDirectionToggle');
const profileSelectElement = document.getElementById('profileSelect');
const includeExpiredToggle = document.getElementById('includeExpiredToggle');
const mergeControls = document.getElementById('mergeControls');
const mergeModeToggle = document.getElementById('mergeModeToggle');
const mergeSubmitBtn = document.getElementById('mergeSubmitBtn');
const REFRESH_SETTINGS_KEY = 'trackerRefreshSettings';
const SORT_SETTINGS_KEY = 'trackerSortSettings';
@@ -294,6 +303,37 @@ function updateIncludeExpiredToggleVisibility() {
wrapper.style.display = currentTab === 'all' ? 'inline-flex' : 'none';
}
function resetMergeSelection() {
mergeSelection.clear();
}
function updateMergeControlsUI() {
if (!mergeControls) {
return;
}
const isAllTab = currentTab === 'all';
mergeControls.hidden = !isAllTab;
mergeControls.style.display = isAllTab ? 'flex' : 'none';
if (!isAllTab && mergeMode) {
mergeMode = false;
resetMergeSelection();
}
if (mergeModeToggle) {
mergeModeToggle.disabled = !isAllTab;
mergeModeToggle.classList.toggle('active', mergeMode);
mergeModeToggle.textContent = mergeMode ? 'Merge-Modus: aktiv' : 'Merge-Modus';
}
if (mergeSubmitBtn) {
const count = mergeSelection.size;
mergeSubmitBtn.disabled = !mergeMode || !isAllTab || count !== MERGE_MAX_SELECTION;
mergeSubmitBtn.textContent = `Beiträge mergen (${count}/${MERGE_MAX_SELECTION})`;
}
}
function initializeFocusParams() {
try {
const params = new URLSearchParams(window.location.search);
@@ -996,6 +1036,21 @@ function buildBookmarkSearchQueries(baseQuery) {
return BOOKMARK_SUFFIXES.map((suffix) => `${trimmed} ${suffix}`.trim());
}
function openBookmarkQueries(baseQuery) {
const queries = Array.isArray(baseQuery) ? baseQuery : buildBookmarkSearchQueries(baseQuery);
let opened = 0;
queries.forEach((searchTerm) => {
const url = buildBookmarkSearchUrl(searchTerm);
if (url) {
window.open(url, '_blank', 'noopener');
opened += 1;
}
});
return opened;
}
function openBookmark(bookmark) {
if (!bookmark) {
return;
@@ -1032,13 +1087,7 @@ function openBookmark(bookmark) {
markBookmarkClick(stateBookmark.id);
}
queries.forEach((searchTerm) => {
const url = buildBookmarkSearchUrl(searchTerm);
if (url) {
window.open(url, '_blank', 'noopener');
}
});
openBookmarkQueries(queries);
}
async function markBookmarkClick(bookmarkId) {
@@ -1380,6 +1429,45 @@ async function handleBookmarkSubmit(event) {
}
}
function setBookmarkQuickStatus(message, isError = false) {
if (!bookmarkQuickStatus) {
return;
}
const hasMessage = typeof message === 'string' && message.trim();
bookmarkQuickStatus.hidden = !hasMessage;
bookmarkQuickStatus.textContent = hasMessage ? message : '';
bookmarkQuickStatus.classList.toggle('bookmark-status--error', !!isError);
}
function handleBookmarkQuickSubmit(event) {
event.preventDefault();
if (!bookmarkQuickForm) {
return;
}
const query = bookmarkQuickQueryInput ? bookmarkQuickQueryInput.value.trim() : '';
if (!query) {
setBookmarkQuickStatus('Bitte gib einen Suchbegriff ein.', true);
if (bookmarkQuickQueryInput) {
bookmarkQuickQueryInput.focus();
}
return;
}
const opened = openBookmarkQueries(query);
if (opened > 0) {
setBookmarkQuickStatus(`Suche „${query}“ geöffnet (ohne Speicherung).`);
if (bookmarkQuickQueryInput) {
bookmarkQuickQueryInput.value = '';
bookmarkQuickQueryInput.focus();
}
} else {
setBookmarkQuickStatus('Konnte die Suche nicht öffnen.', true);
}
}
function initializeBookmarks() {
if (!bookmarksList) {
return;
@@ -1418,7 +1506,17 @@ function initializeBookmarks() {
bookmarkForm.addEventListener('submit', handleBookmarkSubmit);
}
if (bookmarkSearchInput) {
if (bookmarkQuickForm) {
bookmarkQuickForm.addEventListener('submit', handleBookmarkQuickSubmit);
}
if (bookmarkQuickQueryInput) {
bookmarkQuickQueryInput.addEventListener('input', () => {
setBookmarkQuickStatus('');
});
}
if (bookmarkSearchInput) {
bookmarkSearchInput.value = bookmarkSearchTerm;
bookmarkSearchInput.addEventListener('input', () => {
bookmarkSearchTerm = typeof bookmarkSearchInput.value === 'string'
@@ -1665,8 +1763,13 @@ function setTab(tab, { updateUrl = true } = {}) {
} else {
currentTab = 'pending';
}
if (currentTab !== 'all' && mergeMode) {
mergeMode = false;
resetMergeSelection();
}
updateTabButtons();
loadSortMode({ fromTabChange: true });
updateMergeControlsUI();
if (updateUrl) {
updateTabInUrl();
}
@@ -2982,6 +3085,27 @@ if (searchInput) {
});
}
if (mergeModeToggle) {
mergeModeToggle.addEventListener('click', () => {
if (currentTab !== 'all') {
alert('Merge-Modus ist nur in „Alle Beiträge“ verfügbar.');
return;
}
mergeMode = !mergeMode;
if (!mergeMode) {
resetMergeSelection();
}
updateMergeControlsUI();
renderPosts();
});
}
if (mergeSubmitBtn) {
mergeSubmitBtn.addEventListener('click', () => {
mergeSelectedPosts();
});
}
if (sortModeSelect) {
sortModeSelect.addEventListener('change', () => {
const value = sortModeSelect.value;
@@ -3195,6 +3319,104 @@ function highlightPostCard(post) {
clearFocusParamsFromUrl();
}
function toggleMergeSelection(postId, checkboxEl = null) {
if (!mergeMode || currentTab !== 'all') {
resetMergeSelection();
if (checkboxEl) {
checkboxEl.checked = false;
}
updateMergeControlsUI();
return;
}
if (mergeSelection.has(postId)) {
mergeSelection.delete(postId);
} else {
if (mergeSelection.size >= MERGE_MAX_SELECTION) {
alert(`Es können maximal ${MERGE_MAX_SELECTION} Beiträge ausgewählt werden.`);
if (checkboxEl) {
checkboxEl.checked = false;
}
updateMergeControlsUI();
return;
}
mergeSelection.add(postId);
}
updateMergeControlsUI();
}
async function mergeSelectedPosts() {
if (!mergeMode || currentTab !== 'all') {
alert('Mergen ist nur in „Alle Beiträge“ möglich.');
return;
}
if (mergeSelection.size !== MERGE_MAX_SELECTION) {
alert('Bitte genau zwei Beiträge auswählen.');
return;
}
const [primaryId, secondaryId] = Array.from(mergeSelection);
const confirmed = window.confirm(
`Beitrag ${primaryId} als Haupt-URL behalten und Beitrag ${secondaryId} anhängen?`
);
if (!confirmed) {
return;
}
if (mergeSubmitBtn) {
mergeSubmitBtn.disabled = true;
mergeSubmitBtn.textContent = 'Mergen...';
}
try {
const response = await apiFetch(`${API_URL}/posts/merge`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
primary_post_id: primaryId,
secondary_post_id: secondaryId
})
});
if (!response.ok) {
const data = await response.json().catch(() => null);
const message = data && data.error ? data.error : 'Beiträge konnten nicht gemerged werden.';
throw new Error(message);
}
const mergedPost = await response.json();
posts = posts
.filter((post) => {
if (post.id === secondaryId) {
return false;
}
if (post.id === primaryId) {
return false;
}
return true;
});
posts.push(mergedPost);
sortPostsByCreatedAt();
mergeMode = false;
resetMergeSelection();
updateMergeControlsUI();
renderPosts();
alert('Beiträge wurden gemerged.');
} catch (error) {
console.error('Merge error:', error);
alert(error.message || 'Beiträge konnten nicht gemerged werden.');
} finally {
if (mergeSubmitBtn) {
mergeSubmitBtn.disabled = false;
}
updateMergeControlsUI();
}
}
// Render posts
function renderPosts() {
hideLoading();
@@ -3206,6 +3428,7 @@ function renderPosts() {
}
updateIncludeExpiredToggleVisibility();
updateMergeControlsUI();
closeActiveDeadlinePicker();
updateTabButtons();
cleanupLoadMoreObserver();
@@ -3359,6 +3582,13 @@ function attachPostEventHandlers(post, status) {
return;
}
const mergeCheckbox = card.querySelector('.merge-checkbox');
if (mergeCheckbox) {
mergeCheckbox.addEventListener('change', () => {
toggleMergeSelection(post.id, mergeCheckbox);
});
}
const openBtn = card.querySelector('.btn-open');
if (openBtn) {
openBtn.addEventListener('click', () => openPost(post.id));
@@ -3548,6 +3778,15 @@ function createPostCard(post, status, meta = {}) {
const tabTotalCount = typeof meta.tabTotalCount === 'number' ? meta.tabTotalCount : posts.length;
const searchActive = !!meta.searchActive;
const indexBadge = displayIndex !== null ? `<span class="post-index">#${String(displayIndex).padStart(2, '0')}</span>` : '';
const mergeSelectable = mergeMode && currentTab === 'all';
const mergeCheckboxHtml = mergeSelectable
? `
<label class="merge-select">
<input type="checkbox" class="merge-checkbox" data-post-id="${post.id}" ${mergeSelection.has(post.id) ? 'checked' : ''}>
<span>Merge</span>
</label>
`
: '';
const profileRowsHtml = status.profileStatuses.map((profileStatus) => {
const classes = ['profile-line', `profile-line--${profileStatus.status}`];
@@ -3690,6 +3929,7 @@ function createPostCard(post, status, meta = {}) {
<div class="post-card ${status.isComplete ? 'complete' : ''}" id="post-${post.id}">
<div class="post-header">
<div class="post-title-with-checkbox">
${mergeCheckboxHtml}
${indexBadge}
<div class="post-title">${escapeHtml(titleText)}</div>
<label class="success-checkbox success-checkbox--header">
@@ -4308,6 +4548,7 @@ initializeBookmarks();
loadAutoRefreshSettings();
initializeFocusParams();
initializeTabFromUrl();
updateMergeControlsUI();
loadSortMode();
resetManualPostForm();
loadProfile();

702
web/daily-bookmarks.css Normal file
View File

@@ -0,0 +1,702 @@
:root {
--bg: #f0f2f5;
--bg-strong: #ffffff;
--panel: #ffffff;
--panel-strong: #f8fafc;
--border: #e5e7eb;
--text: #111827;
--muted: #6b7280;
--accent: #2563eb;
--accent-2: #06b6d4;
--danger: #ef4444;
--success: #10b981;
--shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
--radius: 16px;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Space Grotesk', 'Inter', system-ui, -apple-system, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
min-height: 100vh;
}
a {
color: var(--accent-2);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
.daily-shell {
max-width: 1600px;
margin: 0 auto;
padding: 28px 18px 50px;
}
.hero {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 20px;
padding: 26px 28px;
box-shadow: var(--shadow);
display: flex;
flex-direction: column;
gap: 12px;
}
.back-link {
align-self: flex-start;
color: var(--accent);
text-decoration: none;
font-weight: 600;
margin-bottom: 4px;
}
.back-link:hover {
text-decoration: underline;
}
.pill {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border-radius: 999px;
font-size: 13px;
letter-spacing: 0.02em;
color: var(--text);
border: 1px solid rgba(255, 255, 255, 0.14);
}
.pill--soft {
background: rgba(255, 255, 255, 0.08);
}
.pill--accent {
background: linear-gradient(120deg, rgba(37, 99, 235, 0.15), rgba(6, 182, 212, 0.15));
color: #0f172a;
border-color: rgba(37, 99, 235, 0.25);
}
.hero__title {
font-size: clamp(30px, 3vw, 36px);
margin: 0;
letter-spacing: -0.01em;
}
.hero__lead {
margin: 0;
color: var(--muted);
max-width: 840px;
}
.hero__lead code {
background: rgba(37, 99, 235, 0.08);
padding: 3px 6px;
border-radius: 8px;
color: var(--text);
border: 1px solid rgba(37, 99, 235, 0.15);
}
.hero__controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
justify-content: space-between;
}
.day-switch {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
background: #f8fafc;
border: 1px solid var(--border);
border-radius: 12px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}
.day-switch__label {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 170px;
}
.day-switch__day {
font-weight: 700;
}
.day-switch__sub {
color: var(--muted);
font-size: 13px;
}
.hero__actions {
display: flex;
align-items: center;
gap: 12px;
}
.hero__stats {
color: var(--muted);
font-size: 14px;
}
.bulk-actions {
display: inline-flex;
align-items: center;
gap: 8px;
background: #f8fafc;
border: 1px solid var(--border);
padding: 8px 10px;
border-radius: 12px;
}
.bulk-actions label {
color: var(--muted);
font-size: 13px;
}
.bulk-actions select {
background: #fff;
border: 1px solid var(--border);
color: var(--text);
border-radius: 10px;
padding: 8px 10px;
}
.panel {
background: var(--panel);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 20px;
box-shadow: var(--shadow);
}
.panel__header {
display: flex;
flex-direction: column;
gap: 6px;
margin-bottom: 10px;
}
.panel__header--row {
flex-direction: row;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.panel__eyebrow {
margin: 0;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--muted);
}
.panel__title {
margin: 0;
font-size: 22px;
}
.panel__subtitle {
margin: 0;
color: var(--muted);
font-size: 14px;
}
.list-status {
min-height: 18px;
color: var(--muted);
font-size: 14px;
margin-bottom: 10px;
}
.list-status--error {
color: var(--danger);
}
.field {
display: flex;
flex-direction: column;
gap: 6px;
margin-bottom: 12px;
}
.field span {
color: var(--muted);
font-size: 14px;
}
.field input,
.field textarea {
width: 100%;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.14);
background: rgba(255, 255, 255, 0.06);
color: var(--text);
padding: 12px 14px;
font-size: 15px;
outline: none;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:focus,
.field textarea:focus {
border-color: var(--accent-2);
box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
}
.form-preview {
margin-top: 8px;
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: space-between;
align-items: center;
background: var(--panel-strong);
border: 1px dashed rgba(255, 255, 255, 0.12);
border-radius: 14px;
padding: 12px 14px;
}
.form-preview__label {
margin: 0 0 4px 0;
color: var(--muted);
}
.form-preview__link {
display: inline-block;
max-width: 620px;
word-break: break-all;
}
.form-preview__actions {
display: flex;
gap: 8px;
}
.primary-btn,
.secondary-btn,
.ghost-btn {
border: none;
cursor: pointer;
border-radius: 12px;
padding: 10px 14px;
font-weight: 600;
letter-spacing: 0.01em;
font-size: 14px;
transition: transform 0.1s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.primary-btn {
background: linear-gradient(120deg, var(--accent), var(--accent-2));
color: #ffffff;
box-shadow: 0 10px 25px rgba(37, 99, 235, 0.25);
}
.primary-btn:hover {
transform: translateY(-1px);
box-shadow: 0 16px 45px rgba(34, 211, 238, 0.3);
}
.secondary-btn {
background: #f8fafc;
color: var(--text);
border: 1px solid var(--border);
}
.secondary-btn:hover {
border-color: var(--accent);
}
.ghost-btn {
background: #fff;
color: var(--text);
border: 1px solid var(--border);
padding: 8px 10px;
}
.ghost-btn--today {
background: rgba(37, 99, 235, 0.08);
border-color: rgba(37, 99, 235, 0.25);
}
.ghost-btn:hover {
transform: translateY(-1px);
border-color: var(--accent);
}
.ghost-btn--tiny {
padding: 6px 8px;
font-size: 12px;
border-radius: 8px;
}
.placeholder-help {
margin-top: 12px;
padding: 12px 14px;
border-radius: 12px;
background: #f8fafc;
border: 1px solid var(--border);
}
.placeholder-help__title {
margin: 0 0 6px 0;
font-weight: 700;
}
.placeholder-help__list {
margin: 0;
padding-left: 18px;
color: var(--muted);
display: grid;
gap: 4px;
}
.form-status {
min-height: 18px;
font-size: 14px;
color: var(--muted);
}
.form-status--error {
color: var(--danger);
}
.suggestion-box {
margin-top: -4px;
margin-bottom: 8px;
padding: 10px 12px;
border-radius: 12px;
border: 1px solid rgba(37, 99, 235, 0.25);
background: rgba(37, 99, 235, 0.08);
color: var(--text);
display: flex;
gap: 8px;
align-items: center;
flex-wrap: wrap;
}
.suggestion-box__item {
display: flex;
gap: 8px;
align-items: center;
background: #fff;
border: 1px solid var(--border);
border-radius: 10px;
padding: 6px 8px;
}
.suggestion-box__text {
color: var(--muted);
font-size: 14px;
}
.suggestion-btn {
border: 1px solid var(--border);
background: #f8fafc;
color: var(--text);
border-radius: 8px;
padding: 6px 8px;
cursor: pointer;
}
.suggestion-btn:hover {
border-color: var(--accent);
}
.suggestion-preview {
display: inline-block;
max-width: 320px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: var(--accent);
text-decoration: none;
font-size: 13px;
}
.suggestion-preview:hover {
text-decoration: underline;
}
.table-wrapper {
width: 100%;
overflow-x: auto;
}
.bookmark-table {
width: 100%;
border-collapse: collapse;
color: var(--text);
}
.bookmark-table th,
.bookmark-table td {
padding: 8px 10px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
text-align: left;
background: transparent;
}
.bookmark-table th {
font-size: 13px;
letter-spacing: 0.04em;
text-transform: uppercase;
color: var(--muted);
background: rgba(255, 255, 255, 0.04);
}
.bookmark-table th.col-marker {
width: 180px;
}
.bookmark-table th.col-last {
width: 220px;
}
.bookmark-table tr:hover td {
background: rgba(255, 255, 255, 0.02);
}
.bookmark-table tr.is-done td {
background: rgba(16, 185, 129, 0.12);
border-bottom-color: rgba(16, 185, 129, 0.3);
}
.bookmark-table tr.is-open td {
background: rgba(37, 99, 235, 0.08);
border-bottom-color: rgba(37, 99, 235, 0.2);
}
.chip {
border-radius: 12px;
padding: 6px 8px;
background: rgba(255, 255, 255, 0.07);
border: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 13px;
display: inline-flex;
gap: 4px;
align-items: center;
}
.chip--marker {
background: linear-gradient(120deg, rgba(37, 99, 235, 0.12), rgba(6, 182, 212, 0.12));
color: #0f172a;
border-color: rgba(37, 99, 235, 0.2);
}
.list-summary {
color: var(--muted);
font-size: 14px;
}
.empty-state,
.error-state,
.loading-state {
border: 1px dashed rgba(255, 255, 255, 0.2);
border-radius: 14px;
padding: 16px;
text-align: center;
color: var(--muted);
}
.danger {
color: var(--danger);
}
.table-actions {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.table-actions .ghost-btn {
padding: 6px 8px;
font-size: 13px;
border-radius: 10px;
}
.bookmark-table .note-cell {
max-width: 240px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.bookmark-table .url-cell {
max-width: 420px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.bookmark-table .marker-cell {
max-width: 220px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.modal {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: rgba(0, 0, 0, 0.6);
z-index: 1000;
}
.modal[hidden] {
display: none;
}
.modal__backdrop {
position: absolute;
inset: 0;
}
.modal__content {
width: min(720px, 92vw);
background: var(--bg-strong);
border: 1px solid var(--border);
border-radius: 18px;
padding: 18px;
box-shadow: var(--shadow);
position: relative;
}
.modal__header {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
margin-bottom: 6px;
}
.modal__close {
border-radius: 999px;
}
.table-wrapper::-webkit-scrollbar {
height: 8px;
}
.table-wrapper::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.18);
border-radius: 999px;
}
.sort-btn {
display: inline-flex;
align-items: center;
gap: 6px;
background: transparent;
border: none;
color: var(--muted);
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.04em;
cursor: pointer;
padding: 0;
}
.sort-btn::after {
content: '↕';
font-size: 12px;
color: var(--muted);
opacity: 0.6;
}
.sort-btn.is-active {
color: var(--text);
}
.sort-btn.is-active::after {
content: attr(data-sort-direction);
opacity: 1;
color: var(--accent);
}
.table-filter-row th {
background: rgba(37, 99, 235, 0.05);
border-bottom: 1px solid rgba(37, 99, 235, 0.15);
}
.table-filter-row select {
width: 100%;
border-radius: 10px;
border: 1px solid var(--border);
padding: 8px 10px;
background: #fff;
color: var(--text);
}
.filter-hint {
font-size: 12px;
color: var(--muted);
text-transform: none;
letter-spacing: 0;
display: flex;
align-items: center;
gap: 8px;
justify-content: space-between;
}
.import-hint {
background: #f8fafc;
border: 1px dashed var(--border);
border-radius: 12px;
padding: 10px 12px;
color: var(--muted);
font-size: 14px;
margin: 4px 0 10px;
}
.muted {
color: var(--muted);
}
@media (max-width: 640px) {
.panel__header--row {
flex-direction: column;
align-items: flex-start;
}
.hero__controls {
flex-direction: column;
align-items: flex-start;
}
.form-preview {
flex-direction: column;
align-items: flex-start;
}
}

184
web/daily-bookmarks.html Normal file
View File

@@ -0,0 +1,184 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Daily Bookmarks</title>
<link rel="icon" type="image/png" sizes="32x32" href="assets/app-icon-64.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="daily-bookmarks.css">
</head>
<body>
<div class="daily-shell">
<header class="hero">
<a class="back-link" href="index.html">← Zurück zur App</a>
<h1 class="hero__title">Daily Bookmarks</h1>
<div class="hero__controls">
<div class="day-switch">
<button class="ghost-btn" id="prevDayBtn" aria-label="Vorheriger Tag"></button>
<div class="day-switch__label">
<div id="dayLabel" class="day-switch__day">Heute</div>
<div id="daySubLabel" class="day-switch__sub"></div>
</div>
<button class="ghost-btn" id="nextDayBtn" aria-label="Nächster Tag"></button>
<button class="ghost-btn ghost-btn--today" id="todayBtn">Heute</button>
</div>
<div class="hero__actions">
<div class="bulk-actions">
<label for="bulkCountSelect">Anzahl</label>
<select id="bulkCountSelect">
<option value="1">1</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
</select>
<button class="secondary-btn" id="bulkOpenBtn" type="button">Öffnen & abhaken</button>
</div>
<button class="primary-btn" id="openCreateBtn" type="button">+ Bookmark</button>
<button class="secondary-btn" id="openImportBtn" type="button">Liste importieren</button>
<button class="ghost-btn" id="refreshBtn" type="button">Aktualisieren</button>
<span id="heroStats" class="hero__stats"></span>
</div>
</div>
</header>
<main class="panel list-panel">
<header class="panel__header panel__header--row">
<div>
<p class="panel__eyebrow">Tägliche Liste</p>
<h2 class="panel__title">Alle Bookmarks</h2>
</div>
<div class="list-summary" id="listSummary"></div>
</header>
<div id="listStatus" class="list-status" role="status" aria-live="polite"></div>
<div class="table-wrapper">
<table class="bookmark-table">
<thead>
<tr>
<th class="col-url">
<button type="button" class="sort-btn" data-sort-key="url_template">URL (aufgelöst)</button>
</th>
<th class="col-marker">
<button type="button" class="sort-btn" data-sort-key="marker">Marker</button>
</th>
<th class="col-last">
<button type="button" class="sort-btn" data-sort-key="last_completed_at">Letzte Erledigung</button>
</th>
<th>Aktionen</th>
</tr>
<tr class="table-filter-row">
<th></th>
<th>
<label class="visually-hidden" for="markerFilter">Nach Marker filtern</label>
<select id="markerFilter">
<option value="">Alle Marker</option>
<option value="__none">Ohne Marker</option>
</select>
</th>
<th colspan="2" class="filter-hint">
<span>Filter & Sortierung werden gespeichert</span>
<button type="button" class="ghost-btn ghost-btn--tiny" id="resetViewBtn">Zurücksetzen</button>
</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</main>
</div>
<div id="bookmarkModal" class="modal" hidden>
<div class="modal__backdrop"></div>
<div class="modal__content" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<header class="modal__header">
<div>
<p class="panel__eyebrow" id="formModeLabel">Neues Bookmark</p>
<h2 id="modalTitle" class="panel__title">Bookmark pflegen</h2>
<p class="panel__subtitle">Titel optional, URL-Template erforderlich. Platzhalter werden für den gewählten Tag aufgelöst.</p>
</div>
<button class="ghost-btn modal__close" type="button" id="modalCloseBtn" aria-label="Schließen">×</button>
</header>
<form id="bookmarkForm" class="bookmark-form" autocomplete="off">
<label class="field">
<span>Titel (optional)</span>
<input id="titleInput" type="text" name="title" maxlength="160" placeholder="z.B. Daily Gewinnspielrunde">
</label>
<label class="field">
<span>URL-Template *</span>
<input id="urlInput" type="url" name="url_template" maxlength="800" placeholder="https://www.test.de/tag-{{day}}/" required>
</label>
<div id="urlSuggestionBox" class="suggestion-box" hidden></div>
<label class="field">
<span>Notiz (optional)</span>
<textarea id="notesInput" name="notes" maxlength="800" rows="3" placeholder="Kurze Hinweise oder To-do für diesen Link"></textarea>
</label>
<label class="field">
<span>Marker (optional)</span>
<input id="markerInput" type="text" name="marker" maxlength="120" placeholder="z.B. März-Import oder Kampagne A">
</label>
<div class="form-preview">
<div>
<p class="form-preview__label">Aufgelöste URL für den gewählten Tag:</p>
<a id="previewLink" class="form-preview__link" href="#" target="_blank" rel="noopener"></a>
</div>
<div class="form-preview__actions">
<button class="secondary-btn" type="button" id="resetBtn">Zurücksetzen</button>
<button class="primary-btn" type="submit" id="submitBtn">Speichern</button>
</div>
</div>
<div class="placeholder-help">
<p class="placeholder-help__title">Dynamische Platzhalter</p>
<ul class="placeholder-help__list">
<li><code>{{day}}</code> Tag des Monats (131), <code>{{dd}}</code> zweistellig</li>
<li><code>{{date}}</code> liefert <code>YYYY-MM-DD</code></li>
<li><code>{{mm}}</code> Monat zweistellig, <code>{{yyyy}}</code> Jahr</li>
<li><code>{{day+1}}</code> oder <code>{{date-2}}</code> verschieben um Tage</li>
<li><code>{{counter:477}}</code> Basiswert + aktueller Tag, z.B. <code>https://www.test.de/sweepstakes/{{counter:477}}/</code></li>
</ul>
</div>
<div id="formStatus" class="form-status" role="status" aria-live="polite"></div>
</form>
</div>
</div>
<div id="importModal" class="modal" hidden>
<div class="modal__backdrop"></div>
<div class="modal__content" role="dialog" aria-modal="true" aria-labelledby="importModalTitle">
<header class="modal__header">
<div>
<p class="panel__eyebrow">Masseneingabe</p>
<h2 id="importModalTitle" class="panel__title">Viele Bookmarks importieren</h2>
<p class="panel__subtitle">Füge hunderte Links gleichzeitig hinzu und vergebe einen gemeinsamen Marker.</p>
</div>
<button class="ghost-btn modal__close" type="button" id="importCloseBtn" aria-label="Schließen">×</button>
</header>
<form id="importForm" class="bookmark-form" autocomplete="off">
<label class="field">
<span>Liste der URL-Templates *</span>
<textarea id="importInput" name="import_urls" maxlength="120000" rows="8" placeholder="Jeder Link in eine neue Zeile, z.B. https://example.com/{{date}}/"></textarea>
</label>
<label class="field">
<span>Marker für alle Einträge (optional)</span>
<input id="importMarkerInput" type="text" name="import_marker" maxlength="120" placeholder="z.B. Batch März 2024">
</label>
<p class="import-hint">Doppelte oder ungültige Zeilen werden automatisch übersprungen.</p>
<div class="form-preview">
<div>
<p class="form-preview__label">Filter und Sortierung gelten auch beim Batch-Öffnen.</p>
</div>
<div class="form-preview__actions">
<button class="secondary-btn" type="button" id="importResetBtn">Zurücksetzen</button>
<button class="primary-btn" type="submit" id="importSubmitBtn">Import starten</button>
</div>
</div>
<div id="importStatus" class="form-status" role="status" aria-live="polite"></div>
</form>
</div>
</div>
<script src="daily-bookmarks.js"></script>
</body>
</html>

1169
web/daily-bookmarks.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,7 @@
<a class="site-nav__btn" data-view-target="dashboard" href="dashboard.html">📊 Dashboard</a>
<a class="site-nav__btn" data-view-target="settings" href="settings.html">⚙️ Einstellungen</a>
<a class="site-nav__btn" data-view-target="bookmarks" href="bookmarks.html">🔖 Bookmarks</a>
<a class="site-nav__btn" href="daily-bookmarks.html">✅ Daily Bookmarks</a>
</div>
</div>
</div>
@@ -84,6 +85,12 @@
<button class="tab-btn active" data-tab="pending">Offene Beiträge</button>
<button class="tab-btn" data-tab="all">Alle Beiträge</button>
</div>
<div class="merge-controls" id="mergeControls" hidden>
<div class="merge-actions">
<button type="button" class="btn btn-secondary" id="mergeModeToggle">Merge-Modus</button>
<button type="button" class="btn btn-primary" id="mergeSubmitBtn" disabled>Beiträge mergen</button>
</div>
</div>
<div class="search-container">
<label class="search-filter-toggle" for="includeExpiredToggle">
<input type="checkbox" id="includeExpiredToggle">
@@ -766,6 +773,17 @@
</button>
</div>
</div>
<form id="bookmarkQuickForm" class="bookmark-quicksearch" autocomplete="off">
<div class="bookmark-quicksearch__fields">
<label class="bookmark-quicksearch__field">
<span>Einmalige Suche</span>
<input type="text" id="bookmarkQuickQuery" placeholder="Suchbegriff nur öffnen, nicht speichern">
</label>
<button type="submit" class="btn btn-secondary">Sofort suchen</button>
</div>
<p class="bookmark-quicksearch__hint">Öffnet die drei Varianten ohne ein Bookmark anzulegen.</p>
<div id="bookmarkQuickStatus" class="bookmark-status" aria-live="polite" hidden></div>
</form>
<div id="bookmarksList" class="bookmark-list" role="list" aria-live="polite"></div>
<form id="bookmarkForm" class="bookmark-form" autocomplete="off">
<div class="bookmark-form__fields">

View File

@@ -452,6 +452,36 @@ h1 {
justify-content: flex-end;
}
.merge-controls {
display: flex;
flex-direction: column;
gap: 4px;
padding: 0;
border: none;
background: transparent;
}
.merge-actions {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.merge-actions .btn {
height: 36px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 8px 12px;
line-height: 1.1;
}
#mergeModeToggle.active {
background: #0f172a;
color: #fff;
}
.search-filter-toggle {
display: inline-flex;
align-items: center;
@@ -631,6 +661,25 @@ h1 {
flex: 1;
}
.merge-select {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 8px;
border: 1px dashed #cbd5e1;
border-radius: 10px;
background: #f8fafc;
color: #0f172a;
font-size: 12px;
flex-shrink: 0;
}
.merge-select input {
width: 16px;
height: 16px;
accent-color: #0f172a;
}
.post-index {
font-size: 12px;
color: #6b7280;
@@ -1519,6 +1568,48 @@ h1 {
margin-bottom: 12px;
}
.bookmark-quicksearch {
border: 1px solid #e5e7eb;
background: #f9fafb;
border-radius: 12px;
padding: 12px 14px;
display: flex;
flex-direction: column;
gap: 10px;
}
.bookmark-quicksearch__fields {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 12px;
}
.bookmark-quicksearch__field {
display: flex;
flex-direction: column;
gap: 6px;
flex: 1 1 260px;
}
.bookmark-quicksearch__field span {
font-size: 13px;
color: #65676b;
}
.bookmark-quicksearch__field input {
border: 1px solid #d0d3d9;
border-radius: 8px;
padding: 8px 10px;
font-size: 14px;
}
.bookmark-quicksearch__hint {
margin: 0;
font-size: 12px;
color: #4b5563;
}
.bookmark-panel__search {
display: flex;
flex-direction: column;