• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript webextension-polyfill-ts.browser.tabs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript webextension-polyfill-ts.browser.windows类代码示例发布时间:2022-05-25
下一篇:
TypeScript webdriverio.remote函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap