feat(quick-save): Opera-Worker additiv um onCommand + importScripts ergaenzt, Redirect unberuehrt (CRLF)
This commit is contained in:
@@ -32,3 +32,43 @@ chrome.tabs.onActivated.addListener((activeInfo) => {
|
|||||||
if (tab) forceRedirect(tab.id, tab.url);
|
if (tab) forceRedirect(tab.id, tab.url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---- 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user