How to use the webext-options-sync.migrations function in webext-options-sync

To help you get started, we’ve selected a few webext-options-sync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / refined-github / source / options-storage.ts View on Github external
// TypeScript doesn't merge the definitions so `...` is not equivalent.
// eslint-disable-next-line prefer-object-spread
const defaults = Object.assign({
	customCSS: '',
	personalToken: '',
	logging: false,
	minimizedUsers: ''
}, __featuresOptionDefaults__); // This variable is replaced at build time

const migrations = [
	featureWasRenamed('filter-pr-by-build-status', 'pr-filters'), // Merged on November 1st
	featureWasRenamed('linkify-branch-refs', 'linkify-branch-references'), // Merged on November 10th
	featureWasRenamed('prev-next-commit-buttons', 'previous-next-commit-buttons'), // Merged on November 10th

	// Removed features will be automatically removed from the options as well
	OptionsSync.migrations.removeUnused
];

// Keep this function "dumb". Don't move more "smart" domain selection logic in here
function getStorageName(host: string): string {
	if (/(^|\.)github\.com$/.test(host)) {
		return 'options';
	}

	return `options-${host}`;
}

function getOptions(host: string): OptionsSync {
	return new OptionsSync({storageName: getStorageName(host), migrations, defaults});
}

// This should return the options for the current domain or, if called from an extension page, for `github.com`
github sindresorhus / refined-twitter / source / background.js View on Github external
import OptionsSync from 'webext-options-sync';

import {featuresDefaultValues} from './features';

const optionsSync = new OptionsSync();

// Define defaults
optionsSync.define({
	defaults: Object.assign({}, featuresDefaultValues, {
		logging: false
	}),
	migrations: [
		OptionsSync.migrations.removeUnused
	]
});

// Make sure that all features have an option value
optionsSync.getAll().then(options => {
	const newOptions = Object.assign({}, featuresDefaultValues, options);
	optionsSync.setAll(newOptions);
});

// Fix the extension when right-click saving a tweet image
browser.downloads.onDeterminingFilename.addListener((item, suggest) => {
	suggest({
		filename: item.filename.replace(/\.(jpg|png)_(large|orig)$/, '.$1')
	});
});
github sindresorhus / refined-github / source / background.js View on Github external
},
	migrations: [
		options => {
			options.disabledFeatures = options.disabledFeatures.replace('toggle-all-things-with-alt', ''); // #1524
			options.disabledFeatures = options.disabledFeatures.replace('remove-diff-signs', ''); // #1524
			options.disabledFeatures = options.disabledFeatures.replace('add-confirmation-to-comment-cancellation', ''); // #1524
			options.disabledFeatures = options.disabledFeatures.replace('add-your-repositories-link-to-profile-dropdown', ''); // #1460
			options.disabledFeatures = options.disabledFeatures.replace('add-readme-buttons', 'hide-readme-header'); // #1465
			options.disabledFeatures = options.disabledFeatures.replace('add-delete-to-pr-files', ''); // #1462
			options.disabledFeatures = options.disabledFeatures.replace('auto-load-more-news', 'infinite-scroll'); // #1516
			options.disabledFeatures = options.disabledFeatures.replace('display-issue-suggestions', ''); // #1611
			options.disabledFeatures = options.disabledFeatures.replace('open-all-selected', 'batch-open-issues'); // #1402
			options.disabledFeatures = options.disabledFeatures.replace('copy-file-path', ''); // #1628
			options.disabledFeatures = options.disabledFeatures.replace('hide-issue-list-autocomplete', ''); // #1657
		},
		OptionsSync.migrations.removeUnused
	]
});

browser.runtime.onMessage.addListener(async message => {
	if (!message || message.action !== 'openAllInTabs') {
		return;
	}
	const [currentTab] = await browser.tabs.query({currentWindow: true, active: true});
	for (const [i, url] of message.urls.entries()) {
		browser.tabs.create({
			url,
			index: currentTab.index + i + 1,
			active: false
		});
	}
});
github faceit-enhancer / faceit-enhancer / src / background / index.js View on Github external
) {
        savedOptions.matchRoomAutoVetoMapItems = savedOptions.matchRoomAutoVetoMapItems.filter(
          map => map !== 'de_cbble'
        )
        savedOptions.matchRoomAutoVetoMapItems.push('de_vertigo')
      }

      if (savedOptions.bans) {
        delete savedOptions.bans
      }

      if (savedOptions.vips) {
        delete savedOptions.vips
      }
    },
    OptionsSync.migrations.removeUnused
  ]
})

browser.runtime.onMessage.addListener(async message => {
  if (!message) {
    return
  }

  switch (message.action) {
    case 'notification': {
      const { name } = browser.runtime.getManifest()
      delete message.action

      browser.notifications.create('', {
        type: 'basic',
        ...message,
github notlmn / browser-extension-template / source / options-storage.js View on Github external
import OptionsSync from 'webext-options-sync';

export default new OptionsSync({
	defaults: {
		colorRed: 244,
		colorGreen: 67,
		colorBlue: 54
	},
	migrations: [
		OptionsSync.migrations.removeUnused
	],
	logging: true
});
github sindresorhus / notifier-for-github / source / options-storage.js View on Github external
import OptionsSync from 'webext-options-sync';

const optionsStorage = new OptionsSync({
	defaults: {
		token: '',
		rootUrl: 'https://api.github.com/',
		playNotifSound: false,
		showDesktopNotif: false,
		onlyParticipating: false,
		reuseTabs: false,
		updateCountOnNavigation: false
	},
	migrations: [
		OptionsSync.migrations.removeUnused
	]
});

export default optionsStorage;
github fregante / github-clean-feed / src / options-init.js View on Github external
if (savedOptions.hideTags) {
				savedOptions.tags = 'hide';
			}
			if (savedOptions.hideCommits) {
				savedOptions.commits = 'hide';
			}
			if (savedOptions.hideClosedIssues) {
				savedOptions.closedIssues = 'hide';
			}
			delete savedOptions.hideCollaborators;
			delete savedOptions.hideBranches;
			delete savedOptions.hideTags;
			delete savedOptions.hideCommits;
			delete savedOptions.hideClosedIssues;
		},
		OptSync.migrations.removeUnused
	],
});
github refined-bitbucket / refined-bitbucket / src / background.js View on Github external
lineLengthLimitEnabled: true,
        lineLengthLimit: 80,
        customStyles: '',
        enableUpdateNotifications: true,
        stickyHeader: true,
    },
    migrations: [
        async savedOptions => {
            if (savedOptions.enableUpdateNotifications) {
                await justInstalledOrUpdated
                window.open(
                    'https://github.com/refined-bitbucket/refined-bitbucket/releases/latest'
                )
            }
        },
        OptionsSync.migrations.removeUnused,
    ],
})

webext-options-sync

Helps you manage and autosave your extension's options.

MIT
Latest version published 1 month ago

Package Health Score

70 / 100
Full package analysis

Popular webext-options-sync functions