當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript webextension-polyfill-ts.browser.tabs類代碼示例

本文整理匯總了TypeScript中webextension-polyfill-ts.browser.tabs的典型用法代碼示例。如果您正苦於以下問題:TypeScript browser.tabs類的具體用法?TypeScript browser.tabs怎麽用?TypeScript browser.tabs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了browser.tabs類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

export const pushTab = async (): Promise<void> => {
	const windows: browser.windows.Window[] = await browser.windows.getAll({populate: true});

	// Just in case number of windows goes below 1
	if (windows.length <= 1) {
		return;
	} else if (windows.length === 2) {
		const tab: browser.tabs.Tab = await utils.tabs.getCurrent();

		const otherWindow: browser.windows.Window[] = windows.filter(
			(w: browser.windows.Window): boolean => w.id !== tab.windowId
		);

		browser.tabs.move(tab.id, {windowId: otherWindow[0].id, index: -1}).catch(
			(e: Error): void => {
				logging.error(e.message);
			}
		);

		browser.windows.update(otherWindow[0].id, {focused: true}).catch(
			(e: Error): void => {
				logging.error(e.message);
			}
		);

		browser.tabs.update(tab.id, {selected: true, pinned: tab.pinned}).catch(
			(e: Error): void => {
				logging.error(e.message);
			}
		);
	} else {
		const tab: browser.tabs.Tab = await utils.tabs.getCurrent();
		const newTab: browser.tabs.Tab = await browser.tabs.create(
			{
				url : `../tabbo.html#${tab.id}`
			}
		);

		const onTabChange: tabbo.TabsOnActivatedCallback = async (e: tabbo.TabsOnActivatedEvent) => {
			if (e.tabId !== newTab.id) {
				browser.tabs.onActivated.removeListener(onTabChange);

				browser.tabs.get(newTab.id).catch((e: Error): void => {
					logging.error(e.message);
				});

				if (!browser.runtime.lastError) {
					browser.tabs.remove(newTab.id).catch((e: Error): void => {
						logging.error(e.message);
					});
				}
			}
		};

		browser.tabs.onActivated.addListener(onTabChange);
	}
};
開發者ID:dqgorelick,項目名稱:tabbo,代碼行數:57,代碼來源:functionality.ts

示例2: onTabRemoved

async function onTabRemoved(id: number, info: Tabs.OnRemovedRemoveInfoType) {
    const state = getWindowState(info.windowId);

    // Since we don't have a good way of determining whether the removed tab was
    // previously the active tab, make an educated guess based on the fact that
    // the browser may focus some other tab before we get this message, so the
    // removed tab will be either:
    // 1. The most-recent tab in the window's history
    // 2. The second most-recent tab in the window's history, and the active
    //    window was just changed.
    const browserChangedFocus = activeChanged && id === state.history.second;

    const wasActive = browserChangedFocus || id === state.history.first;

    logger.enabled && logger.log(
        `wasActive = ${wasActive}, activeChanged = ${activeChanged}, browserChangedFocus = ${browserChangedFocus}`);

    // If we are overriding which tab gets focused after removing a tab, and the
    // browser focused some other tab before telling us which tab was removed,
    // rewind the state by one to ignore the unwanted change made by the browser.
    if (browserChangedFocus && settings.onClose !== 'default') {
        state.rewind();
    }

    state.removeTab(id);

    // If the removed tab was active, override which tab gets focus next.
    if (wasActive) {
        switch (settings.onClose) {
            case 'lastfocused':
                const newTab = state.history.first;
                logger.enabled && logger.log(`focusing last-focused tab ${newTab}`);

                if (newTab !== undefined) {
                    await focusTab(newTab);
                }
                break;

            case 'next':
            case 'previous':
                // If 'next', the next tab will be in the closing tab's old position.
                // If 'previous', focus the tab right before that, or the leftmost tab.
                let index = state.activeTabIndex;

                logger.enabled && logger.log(`focusing ${settings.onClose} tab from position ${index}`);

                if (index !== undefined) {
                    if (settings.onClose === 'previous') {
                        index = Math.max(0, index - 1);
                    }

                    const tabs = await browser.tabs.query({ windowId: info.windowId, index });
                    if (tabs.length > 0) {
                        await focusTab(tabs[0]);
                    }
                }
                break;
        }
    }
}
開發者ID:ChaosinaCan,項目名稱:ClassicTabs,代碼行數:60,代碼來源:TabManager.ts

示例3:

			w.tabs.forEach((t: browser.tabs.Tab): void => {
				browser.tabs.move(
					t.id,
					{windowId: firstWindowId, index: -1},
				).catch((e: Error): void => {
					logging.error(e.message);
				});
			});
開發者ID:dqgorelick,項目名稱:tabbo,代碼行數:8,代碼來源:functionality.ts

示例4: getNextTabPosition

async function getNextTabPosition(neighbor: Tabs.Tab | number) {
    if (typeof neighbor === 'number') {
        neighbor = await browser.tabs.get(neighbor);
    }

    return {
        index: neighbor.index + 1,
        windowId: neighbor.windowId,
    };
}
開發者ID:ChaosinaCan,項目名稱:ClassicTabs,代碼行數:10,代碼來源:TabManager.ts

示例5: initActiveTabs

async function initActiveTabs() {
    const activeTabs = await browser.tabs.query({ active: true});

    for (const tab of activeTabs) {
        if (tab.windowId === undefined || tab.id === undefined) {
            continue;
        }

        const state = getWindowState(tab.windowId);
        state.addTab(tab.id);
    }
}
開發者ID:ChaosinaCan,項目名稱:ClassicTabs,代碼行數:12,代碼來源:TabManager.ts


注:本文中的webextension-polyfill-ts.browser.tabs類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。