Update functions.js
Description:
Using this alternative approach simplifies the code by leveraging the built-in capabilities of the browser's storage synchronization mechanism, eliminating the need for custom export/import logic. It also ensures that the extension's settings are automatically synchronized across the user's devices without requiring explicit user actions for exporting/importing data.
In this alternative approach:
- The
chrome.storage.syncAPI is used directly to synchronize extension settings with the user's Google Account, enabling automatic data synchronization across devices where the user is signed in. - The
syncSettingsfunction saves the entire extension storage data to the synced storage. - The
pullSettingsfunction retrieves all data from the synced storage and updates the extension's local storage with the synced data.
Code Changes:
var attributes = {
theme: true,
improvedtube_home: true,
title_version: true,
it_general: true,
it_appearance: true,
it_themes: true,
it_player: true,
it_playlist: true,
it_channel: true,
it_shortcuts: true,
it_blocklist: true,
it_analyzer: true,
layer_animation_scale: false
};
for (var attribute in attributes) {
var value = satus.storage.get(attribute);
if (attribute === 'improvedtube_home') {
attribute = 'home-style';
}
if (satus.isset(value)) {
extension.skeleton.rendered.setAttribute(attribute.replace('it_', '').replace(/_/g, '-'), value);
}
}
Wait a minute, not everyone uses chrome, and not everyone uses sync.
chrome.storage.sync.set
While this addition might be beneficial to those that do, it shouldnt remove settings raw file import/export like your pull request does.
Wait a minute, not everyone uses chrome, and not everyone uses sync.
Firefox implements the storage.sync api, though I don't know the details of how it works if you don't have sync enabled.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync
hi and thanks! @Durgesh4993 @raszpl @timtoo
-
we allow the use chrome.storage.sync on press of a button since @josephShokry's last PR #1994
- (makes sense when user doesn't have the exact same settings on two device. Could come with logic also comparing display resolution or so.)
-
we use chrome.storage.local in all browsers
- in chrome, chrome.storage.sync can be used synonym if the user is not logged in.
- If there is a browser not supporting the later (or both), then we can define the variable conditionally (or add that to specific build actions per browser)
- in chrome, chrome.storage.sync can be used synonym if the user is not logged in.
Hah I didnt even notice sync was already supported, so this patch just deletes manual file settings import/export while breaking sync. Weird.