mirror of
https://github.com/SoPat712/videospeed.git
synced 2026-04-26 22:23:09 -04:00
Exclude Lucide cache from backups
This commit is contained in:
+78
-38
@@ -1,5 +1,55 @@
|
||||
// Import/Export functionality for Video Speed Controller settings
|
||||
|
||||
const EXPORTABLE_LOCAL_SETTINGS_KEYS = ["customButtonIcons"];
|
||||
|
||||
function getExportableLocalSettings(localStorage) {
|
||||
const exportable = {};
|
||||
const customButtonIcons =
|
||||
localStorage &&
|
||||
localStorage.customButtonIcons &&
|
||||
typeof localStorage.customButtonIcons === "object" &&
|
||||
!Array.isArray(localStorage.customButtonIcons)
|
||||
? localStorage.customButtonIcons
|
||||
: null;
|
||||
|
||||
if (customButtonIcons) {
|
||||
exportable.customButtonIcons = customButtonIcons;
|
||||
}
|
||||
|
||||
return exportable;
|
||||
}
|
||||
|
||||
function replaceImportableLocalSettings(localSettings, callback) {
|
||||
chrome.storage.local.remove(EXPORTABLE_LOCAL_SETTINGS_KEYS, function () {
|
||||
if (chrome.runtime.lastError) {
|
||||
showStatus(
|
||||
"Error: Failed to clear local icon overrides - " +
|
||||
chrome.runtime.lastError.message,
|
||||
true
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!localSettings || Object.keys(localSettings).length === 0) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.storage.local.set(localSettings, function () {
|
||||
if (chrome.runtime.lastError) {
|
||||
showStatus(
|
||||
"Error: Failed to save local icon overrides - " +
|
||||
chrome.runtime.lastError.message,
|
||||
true
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function generateBackupFilename() {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
@@ -13,28 +63,35 @@ function generateBackupFilename() {
|
||||
|
||||
function exportSettings() {
|
||||
chrome.storage.sync.get(null, function (storage) {
|
||||
chrome.storage.local.get(null, function (localStorage) {
|
||||
const backup = {
|
||||
version: "1.1",
|
||||
exportDate: new Date().toISOString(),
|
||||
settings: storage,
|
||||
localSettings: localStorage || {}
|
||||
};
|
||||
chrome.storage.local.get(
|
||||
EXPORTABLE_LOCAL_SETTINGS_KEYS,
|
||||
function (localStorage) {
|
||||
const localSettings = getExportableLocalSettings(localStorage);
|
||||
const backup = {
|
||||
version: "1.1",
|
||||
exportDate: new Date().toISOString(),
|
||||
settings: storage
|
||||
};
|
||||
|
||||
const dataStr = JSON.stringify(backup, null, 2);
|
||||
const blob = new Blob([dataStr], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
if (Object.keys(localSettings).length > 0) {
|
||||
backup.localSettings = localSettings;
|
||||
}
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = generateBackupFilename();
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
const dataStr = JSON.stringify(backup, null, 2);
|
||||
const blob = new Blob([dataStr], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
showStatus("Settings exported successfully");
|
||||
});
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = generateBackupFilename();
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
showStatus("Settings exported successfully");
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,10 +122,7 @@ function importSettings() {
|
||||
return;
|
||||
}
|
||||
|
||||
var localToImport =
|
||||
backup.localSettings && typeof backup.localSettings === "object"
|
||||
? backup.localSettings
|
||||
: null;
|
||||
var localToImport = getExportableLocalSettings(backup.localSettings);
|
||||
|
||||
function afterLocalImport() {
|
||||
chrome.storage.sync.clear(function () {
|
||||
@@ -93,21 +147,7 @@ function importSettings() {
|
||||
});
|
||||
}
|
||||
|
||||
if (localToImport && Object.keys(localToImport).length > 0) {
|
||||
chrome.storage.local.set(localToImport, function () {
|
||||
if (chrome.runtime.lastError) {
|
||||
showStatus(
|
||||
"Error: Failed to save local extension data - " +
|
||||
chrome.runtime.lastError.message,
|
||||
true
|
||||
);
|
||||
return;
|
||||
}
|
||||
afterLocalImport();
|
||||
});
|
||||
} else {
|
||||
afterLocalImport();
|
||||
}
|
||||
replaceImportableLocalSettings(localToImport, afterLocalImport);
|
||||
} catch (err) {
|
||||
showStatus("Error: Failed to parse backup file - " + err.message, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user