How to use the webext-options-sync 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 fregante / github-clean-feed / src / content.js View on Github external
async function init() {
	[options] = await Promise.all([
		new OptSync().getAll(),
		elementReady('.ajax-pagination-form')
	]);

	apply($('.account-switcher + *') || $('.news.column > :first-child'));

	const pages = [];

	// Prefetch all pages in parallel
	for (let i = 0; i < options.preloadPagesCount; i++) {
		pages.push(requestPage(i + 2));
	}

	// Append pages in series
	// uses the same method used by GitHub
	for (const page of pages) {
		// eslint-disable-next-line no-await-in-loop
github plibither8 / refined-hacker-news / src / libs / utils.js View on Github external
export const getOptions = new Promise(async resolve => {
	// Options defaults
	const options = {
		...defaultConfigs,
		...await new OptionsSync().getAll()
	};

	if (options.customCSS.trim().length > 0) {
		const style = document.createElement('style');
		style.innerHTML = options.customCSS;
		document.head.append(style);
	}

	// Create logging function
	if (options.logging) {
		options.log = (method, ...content) => {
			console[method](...content);
		};
	} else {
		options.log = () => {};
	}
github karlicoss / promnesia / extension / src / options.js View on Github external
// I guess
        // TODO not sure why that in background was necessary..  none repeat scroll 0% 0%;
        // TODO add some docs on configuring it...
        extra_css   : `
.src {
    font-weight: bold;
}
/* you can use devtools to find out which CSS classes you can tweak */
`.trim(),
    };
}


// TODO mm. don't really like having global object, but seems that it's easiest way to avoid race conditions
// TODO https://github.com/fregante/webext-options-sync/issues/38 -- fixed now
const _options = new OptionsSync({
    defaults: defaultOptions(),
});


function optSync() {
    return _options;
}

export async function getOptions(): Promise {
    return await optSync().getAll();
}

// TODO legacy; remove
export async function get_options_async() {
    return await getOptions();
}
github sindresorhus / refined-twitter / source / libs / utils.js View on Github external
import {h} from 'dom-chef';
import select from 'select-dom';
import elementReady from 'element-ready';
import domLoaded from 'dom-loaded';
import OptionsSync from 'webext-options-sync';

let options;
const optionsPromise = new OptionsSync().getAll();

/**
 * Enable toggling each feature via options.
 * Prevent fn's errors from blocking the remaining tasks.
 * https://github.com/sindresorhus/refined-github/issues/678
 */
export const enableFeature = async ({fn, id: _featureId = fn.name}) => {
	if (!options) {
		options = await optionsPromise;
	}

	const {logging = false} = options;
	const log = logging ? console.log : () => {};

	const featureId = _featureId.replace(/_/g, '-');
	if (/^$|^anonymous$/.test(featureId)) {
github refined-bitbucket / refined-bitbucket / src / main.js View on Github external
import setLineLengthLimit from './limit-line-length'

import observeForWordDiffs from './observe-for-word-diffs'

import {
    isPullRequest,
    isCreatePullRequestURL,
    isPullRequestList,
    isCommit,
    isBranch,
    isComparePage,
} from './page-detect'

import addStyleToPage from './add-style'

new OptionsSync().getAll().then(options => {
    const config = {
        ...options,
        autocollapsePaths: (options.autocollapsePaths || '').split('\n'),
        ignorePaths: (options.ignorePaths || '').split('\n'),
    }

    init(config)
})

function init(config) {
    if (config.autolinker) {
        require('./vendor/prism-autolinker.min')
    }

    if (isBranch()) {
        codeReviewFeatures(config)
github plibither8 / refined-hacker-news / src / popup.js View on Github external
const indentWidthInput = document.querySelector('input[name="commentsIndentWidth"]');
indentWidthInput.addEventListener('input', () => {
	for (const tab of activeItemTabs) {
		browser.tabs.sendMessage(tab.id, {
			indentWidth: indentWidthInput.value
		});
	}
});

const links = document.querySelectorAll('a');
for (const link of links) {
	link.addEventListener('click', () => browser.tabs.create({url: link.href}));
}

new OptionsSync({logging: false}).syncForm('#options-form');
github fregante / github-clean-feed / src / options-init.js View on Github external
import OptSync from 'webext-options-sync';

new OptSync().define({
	defaults: {
		starredRepos: 'group',
		forkedRepos: 'group',
		newRepos: 'group',
		comments: 'group',
		newIssues: 'group',
		collaborators: 'hide',
		branches: 'hide',
		tags: 'hide',
		commits: 'hide',
		closedIssues: 'hide',
		preloadPagesCount: 0
	},
	migrations: [
		savedOptions => {
			if (savedOptions.hideCollaborators) {
github plibither8 / refined-hacker-news / src / features / hide-read-stories.js View on Github external
form.id = 'hideReadStoriesForm';
	form.append(check, label);
	optionsBar.append(form);

	requestVisitedStories(options);
	check.addEventListener('input', () => {
		requestVisitedStories(options);
	});

	browser.runtime.onMessage.addListener(request => {
		if (request.visitedIds) {
			hideStories(request.visitedIds, check.checked);
		}
	});

	new OptionsSync({logging: false}).syncForm('#hideReadStoriesForm');
	return true;
}
github plibither8 / refined-hacker-news / src / features / auto-refresh.js View on Github external
input.addEventListener('input', () => {
		input.style.width = (input.value.length + 4) + 'ch';
	});

	form.addEventListener('change', () => {
		const isChecked = check.checked;
		input.disabled = !isChecked;

		if (!isChecked) {
			loader.classList.add('__rhn__no-display');
		}

		handleInterval(input, metadata.options, enabledOptions);
	});

	new OptionsSync({logging: false}).syncForm('#autoRefreshForm');
	return true;
}

webext-options-sync

Helps you manage and autosave your extension's options.

MIT
Latest version published 8 months ago

Package Health Score

56 / 100
Full package analysis

Popular webext-options-sync functions