Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const browserTabsQuery = (x: Tabs.QueryQueryInfoType): TaskOption> =>
TO.tryCatch(() => browser.tabs.query(x));
export const getActiveTab: TaskOption = pipe(
browserTabsQuery({ active: true, currentWindow: true }),
TO.chainOption(A.head),
);
export const getActiveWindowTabs: TaskOption> = pipe(
browserTabsQuery({ currentWindow: true }),
TO.chainOption(NEA.fromArray),
);
export const getAllTabs: TaskOption> = pipe(
browserTabsQuery({}),
TO.chainOption(NEA.fromArray),
);
export const onTabActivity = (cb: Lazy): void => {
browser.tabs.onActivated.addListener(cb);
browser.tabs.onUpdated.addListener(cb);
};
// The imperfect title includes check is because Firefox's href changes
// according to the extension in use, if any
const isNewTabPage: Predicate> = ({ url = '', title = '' }) =>
['about:blank', 'chrome://newtab/'].includes(url) || title.includes('New Tab');
/// The active tab will not update quickly enough to allow this function to be
/// called safely in a loop. Therefore, the second argument forces consumers to
/// verify that this is only the first tab they're opening.
export const openBookmarkInAppropriateTab = (isFirstTab: boolean) => (url: string): Task => pipe(
const updateBadge = (badgeOpt: BadgeDisplay): Task => async (): Promise => {
const urlRes = await pipe(
getActiveTab,
TO.chainOption(tab => O.fromNullable(tab.url)),
TO.chainOption(flow(
fromString,
O.fromEither,
)),
TO.map(flip(checkUrl)(urlState)),
runTask,
);
if (O.isSome(urlRes)) {
const [result, numMatches] = urlRes.value;
if (badgeOpt === BadgeDisplay.None || result === URLMatch.None) {
disableBadge();
return;
}
const text = badgeOpt === BadgeDisplay.WithCount
import { BOOKMARKS_SCHEMA_VERSION } from 'Modules/config';
import { runIO } from 'Modules/fp';
import { sendIsomorphicMessage, IsomorphicMessage } from 'Modules/comms/isomorphic';
import { createUuid } from 'Modules/uuid';
import { error } from 'Modules/error';
import { LocalBookmark, LocalBookmarkUnsaved } from 'Modules/bookmarks';
import { StagedBookmarksGroup } from 'Modules/staged-groups';
const sequenceTTE = sequenceT(TE.taskEither);
const browserTabsQuery = (x: Tabs.QueryQueryInfoType): TaskOption> =>
TO.tryCatch(() => browser.tabs.query(x));
export const getActiveTab: TaskOption = pipe(
browserTabsQuery({ active: true, currentWindow: true }),
TO.chainOption(A.head),
);
export const getActiveWindowTabs: TaskOption> = pipe(
browserTabsQuery({ currentWindow: true }),
TO.chainOption(NEA.fromArray),
);
export const getAllTabs: TaskOption> = pipe(
browserTabsQuery({}),
TO.chainOption(NEA.fromArray),
);
export const onTabActivity = (cb: Lazy): void => {
browser.tabs.onActivated.addListener(cb);
browser.tabs.onUpdated.addListener(cb);
};
const updateBadge = (badgeOpt: BadgeDisplay): Task => async (): Promise => {
const urlRes = await pipe(
getActiveTab,
TO.chainOption(tab => O.fromNullable(tab.url)),
TO.chainOption(flow(
fromString,
O.fromEither,
)),
TO.map(flip(checkUrl)(urlState)),
runTask,
);
if (O.isSome(urlRes)) {
const [result, numMatches] = urlRes.value;
if (badgeOpt === BadgeDisplay.None || result === URLMatch.None) {
disableBadge();
return;
}