diff --git a/src/js/opera/background.js b/src/js/opera/background.js index 221b65b..2e24644 100644 --- a/src/js/opera/background.js +++ b/src/js/opera/background.js @@ -31,4 +31,44 @@ chrome.tabs.onActivated.addListener((activeInfo) => { chrome.tabs.get(activeInfo.tabId, (tab) => { if (tab) forceRedirect(tab.id, tab.url); }); -}); \ No newline at end of file +}); + +// ---- QUICK SAVE (v2.3, additiv — Redirect oben unberuehrt) ---- +// Geteiltes Helfer-Modul: ensureInbox(boards), uid(), normalizeBookmark(...). +// Pfad ist relativ zu DIESER Datei (src/js/opera/), daher ../quicksave-core.js. +importScripts('../quicksave-core.js'); + +function quickSaveActiveTab() { + chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + const tab = tabs && tabs[0]; + if (!tab || !tab.url) { + chrome.action.setBadgeText({ text: chrome.i18n.getMessage('quickSaveNoTab') }); + setTimeout(() => chrome.action.setBadgeText({ text: '' }), 2000); + return; + } + // read-modify-write: aktuellen boards-Stand frisch holen, anhaengen, zurueckschreiben. + chrome.storage.local.get(['boards'], (r) => { + const boards = r.boards ?? []; + const inbox = ensureInbox(boards); + inbox.bookmarks.push(normalizeBookmark({ title: tab.title || tab.url, url: tab.url })); + chrome.storage.local.set({ boards }, () => { + if (chrome.runtime.lastError) { + console.error('Quick-Save fehlgeschlagen:', chrome.runtime.lastError.message); + return; + } + chrome.action.setBadgeText({ text: chrome.i18n.getMessage('quickSaveBadge') }); + if (chrome.action.setBadgeBackgroundColor) { + chrome.action.setBadgeBackgroundColor({ color: '#1f9d55' }); + } + setTimeout(() => chrome.action.setBadgeText({ text: '' }), 2000); + }); + }); + }); +} + +// onCommand SYNCHRON auf Top-Level (additiv neben den Redirect-Listenern). +chrome.commands.onCommand.addListener((command) => { + if (command === 'quick-save') { + quickSaveActiveTab(); + } +});