fix(quick-save): Opera-Worker — interne-URL-Filter, kurzer Fehler-Badge, Re-Entry-Schutz gegen Lost-Update
This commit is contained in:
@@ -38,12 +38,26 @@ chrome.tabs.onActivated.addListener((activeInfo) => {
|
|||||||
// Pfad ist relativ zu DIESER Datei (src/js/opera/), daher ../quicksave-core.js.
|
// Pfad ist relativ zu DIESER Datei (src/js/opera/), daher ../quicksave-core.js.
|
||||||
importScripts('../quicksave-core.js');
|
importScripts('../quicksave-core.js');
|
||||||
|
|
||||||
|
// Interne/nicht speicherbare Seiten (Browser-UI, Extension-Seiten) — kein sinnvolles Bookmark.
|
||||||
|
const UNSAVEABLE_URL = /^(chrome|chrome-extension|about|edge|opera|moz-extension|brave|vivaldi|view-source|devtools):/i;
|
||||||
|
|
||||||
|
// Re-Entry-Schutz: ein zweiter Quick-Save waehrend der erste laeuft wuerde read-modify-write
|
||||||
|
// rennen (lost update). Bei aktivem Save den zweiten Druck verwerfen.
|
||||||
|
let qsBusy = false;
|
||||||
|
|
||||||
function quickSaveActiveTab() {
|
function quickSaveActiveTab() {
|
||||||
|
if (qsBusy) return;
|
||||||
|
qsBusy = true;
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||||
const tab = tabs && tabs[0];
|
const tab = tabs && tabs[0];
|
||||||
if (!tab || !tab.url) {
|
if (!tab || !tab.url || UNSAVEABLE_URL.test(tab.url)) {
|
||||||
chrome.action.setBadgeText({ text: chrome.i18n.getMessage('quickSaveNoTab') });
|
// Kein speicherbarer Tab: kurzer roter Marker (langer Text wird im Badge abgeschnitten).
|
||||||
|
chrome.action.setBadgeText({ text: '×' });
|
||||||
|
if (chrome.action.setBadgeBackgroundColor) {
|
||||||
|
chrome.action.setBadgeBackgroundColor({ color: '#c0392b' });
|
||||||
|
}
|
||||||
setTimeout(() => chrome.action.setBadgeText({ text: '' }), 2000);
|
setTimeout(() => chrome.action.setBadgeText({ text: '' }), 2000);
|
||||||
|
qsBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// read-modify-write: aktuellen boards-Stand frisch holen, anhaengen, zurueckschreiben.
|
// read-modify-write: aktuellen boards-Stand frisch holen, anhaengen, zurueckschreiben.
|
||||||
@@ -54,6 +68,7 @@ function quickSaveActiveTab() {
|
|||||||
chrome.storage.local.set({ boards }, () => {
|
chrome.storage.local.set({ boards }, () => {
|
||||||
if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
console.error('Quick-Save fehlgeschlagen:', chrome.runtime.lastError.message);
|
console.error('Quick-Save fehlgeschlagen:', chrome.runtime.lastError.message);
|
||||||
|
qsBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chrome.action.setBadgeText({ text: chrome.i18n.getMessage('quickSaveBadge') });
|
chrome.action.setBadgeText({ text: chrome.i18n.getMessage('quickSaveBadge') });
|
||||||
@@ -61,6 +76,7 @@ function quickSaveActiveTab() {
|
|||||||
chrome.action.setBadgeBackgroundColor({ color: '#1f9d55' });
|
chrome.action.setBadgeBackgroundColor({ color: '#1f9d55' });
|
||||||
}
|
}
|
||||||
setTimeout(() => chrome.action.setBadgeText({ text: '' }), 2000);
|
setTimeout(() => chrome.action.setBadgeText({ text: '' }), 2000);
|
||||||
|
qsBusy = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user