v2.3: DOM-freies quicksave-core mit uid/ensureInbox/normalizeBookmark
This commit is contained in:
@@ -492,6 +492,7 @@
|
|||||||
<!-- Storage muss zuerst -->
|
<!-- Storage muss zuerst -->
|
||||||
<script src="src/js/storage.js"></script>
|
<script src="src/js/storage.js"></script>
|
||||||
<!-- State & Hilfsfunktionen -->
|
<!-- State & Hilfsfunktionen -->
|
||||||
|
<script src="src/js/quicksave-core.js"></script>
|
||||||
<script src="src/js/state.js"></script>
|
<script src="src/js/state.js"></script>
|
||||||
<!-- i18n (nach state.js, vor allen Modulen die t() nutzen könnten) -->
|
<!-- i18n (nach state.js, vor allen Modulen die t() nutzen könnten) -->
|
||||||
<script src="src/js/i18n.js"></script>
|
<script src="src/js/i18n.js"></script>
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/* =============================================
|
||||||
|
HELLION NEWTAB — quicksave-core.js
|
||||||
|
DOM-freie geteilte Helfer fuer Seite UND Background-Worker.
|
||||||
|
Laeuft als <script> (newtab.html) und via importScripts (Service-Worker/Event-Page).
|
||||||
|
KEIN window/document/Store-Zugriff. Alle Exporte auf globalThis.
|
||||||
|
============================================= */
|
||||||
|
(function (root) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Feste, nicht-zufaellige ID des Inbox-Boards (Quick-Save-Ziel).
|
||||||
|
// Bewusst KEIN uid(): die Inbox muss von Seite und Worker deterministisch
|
||||||
|
// wiedererkennbar sein, sonst entstehen Duplikate (QS-08).
|
||||||
|
const INBOX_ID = 'inbox';
|
||||||
|
|
||||||
|
// Kollisionsarme Kurz-ID. Identisch zur frueheren state.js-Variante,
|
||||||
|
// damit bestehende Aufrufer (boards.js, data.js, app.js, bookmark-import.js) unveraendert weiterlaufen.
|
||||||
|
function uid() {
|
||||||
|
return Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sichert, dass im uebergebenen boards-Array genau EIN Inbox-Board existiert,
|
||||||
|
// und gibt dieses Inbox-Board-Objekt zurueck. Idempotent: findet ein Board mit
|
||||||
|
// id === INBOX_ID, sonst legt es eins mit fester id vorne an (unshift) und mutiert
|
||||||
|
// das uebergebene Array dabei IN-PLACE. Der Worker schreibt anschliessend dasselbe
|
||||||
|
// (mutierte) boards-Array via storage zurueck; der Rueckgabewert ist das Board,
|
||||||
|
// damit Aufrufer direkt inbox.bookmarks.push(...) machen koennen (QS-08).
|
||||||
|
function ensureInbox(boardsArr) {
|
||||||
|
const list = Array.isArray(boardsArr) ? boardsArr : [];
|
||||||
|
let inbox = list.find(b => b && b.id === INBOX_ID);
|
||||||
|
if (!inbox) {
|
||||||
|
inbox = { id: INBOX_ID, title: 'Inbox', bookmarks: [], blurred: false };
|
||||||
|
list.unshift(inbox);
|
||||||
|
}
|
||||||
|
return inbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalisiert eine Bookmark in die kanonische Form { id, title, url, desc }.
|
||||||
|
// title-Fallback auf url, desc auf ''. Begrenzt Laengen wie data.js (200/500),
|
||||||
|
// damit Quick-Save-Eintraege das gleiche Schema wie Import/Manuell haben.
|
||||||
|
function normalizeBookmark(raw) {
|
||||||
|
const url = (raw && typeof raw.url === 'string') ? raw.url : '';
|
||||||
|
const title = (raw && typeof raw.title === 'string' && raw.title.trim())
|
||||||
|
? raw.title.trim()
|
||||||
|
: url;
|
||||||
|
return {
|
||||||
|
id: (raw && raw.id) ? raw.id : uid(),
|
||||||
|
title: String(title).slice(0, 200),
|
||||||
|
url: url,
|
||||||
|
desc: String((raw && raw.desc) || '').slice(0, 500)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
root.INBOX_ID = INBOX_ID;
|
||||||
|
root.uid = uid;
|
||||||
|
root.ensureInbox = ensureInbox;
|
||||||
|
root.normalizeBookmark = normalizeBookmark;
|
||||||
|
})(typeof globalThis !== 'undefined' ? globalThis : self);
|
||||||
Reference in New Issue
Block a user