youtube icon indicating copy to clipboard operation
youtube copied to clipboard

Update functions.js

Open Durgesh4993 opened this issue 2 years ago • 4 comments

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.sync API 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 syncSettings function saves the entire extension storage data to the synced storage.
  • The pullSettings function 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);
        }
    }

Durgesh4993 avatar Mar 03 '24 00:03 Durgesh4993

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.

raszpl avatar Mar 03 '24 02:03 raszpl

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

timtoo avatar Mar 03 '24 03:03 timtoo

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)

ImprovedTube avatar Mar 06 '24 04:03 ImprovedTube

Hah I didnt even notice sync was already supported, so this patch just deletes manual file settings import/export while breaking sync. Weird.

raszpl avatar Mar 06 '24 05:03 raszpl