当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript browser.tabs.get方法代码示例

本文整理汇总了TypeScript中webextension-polyfill-ts.browser.tabs.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript browser.tabs.get方法的具体用法?TypeScript browser.tabs.get怎么用?TypeScript browser.tabs.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webextension-polyfill-ts.browser.tabs的用法示例。


在下文中一共展示了browser.tabs.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例2: async

export const main = async (sendTabID: number): Promise<void> => {
	const windows: browser.windows.Window[] = await browser.windows.getAll({populate: true});
	const current: browser.windows.Window = await browser.windows.getCurrent();
	let count: number = 1;

	const openWindowsElement: HTMLElement = utils.queryOrThrow('#open-windows');
	const t: browser.tabs.Tab = await browser.tabs.get(sendTabID);

	if (windows.length === 1) {
		const h1: HTMLElement = document.createElement('h1');
		h1.innerText = 'No other open windows';

		openWindowsElement.appendChild(h1);
	}

	windows.forEach((w: browser.windows.Window): void => {
		if (w.id === current.id) {
			return;
		}

		const windowNum = count.toString();
		utils.queryOrThrow('body').addEventListener(
			'keydown',
			(e: KeyboardEvent) => {
				if (e.key === windowNum) {
					moveTabToWindow(w, t);
				}
			}
		);

		if (w.tabs) {
			const div: HTMLDivElement = document.createElement('div');
			div.className = 'screenshot';
			div.innerHTML = `<div class="title-bar"> <img src="${w.tabs[0].favIconUrl}"/>
				<div class="screen-title">${w.tabs[0].title}</div></div>
				<div class="screen-index">${count}</div>
				<div class="tab-count">${w.tabs.length + (w.tabs.length === 1 ? " tab" : " tabs")}
				</div>`;

			div.addEventListener('click', (): void => {
				moveTabToWindow(w, t);
			});

			openWindowsElement.appendChild(div);
		}

		count++;
	});

	utils.queryOrThrow('#current-tab').innerHTML = `<div class="title-bar"><img src="${t.favIconUrl}"/>` +
		`<div class="screen-title">${t.title}</div></div>`;
};
开发者ID:dqgorelick,项目名称:tabbo,代码行数:52,代码来源:functionality.ts

示例3: moveNextToActive

async function moveNextToActive(tab: Tabs.Tab, windowId?: number) {
    if (tab.id === undefined) {
        console.warn('Cannot move tab with no ID:', tab);
        return;
    }

    if (windowId === undefined) {
        windowId = tab.windowId;

        if (windowId === undefined) {
            console.warn('Cannot move next to active tab with no window:', tab);
            return;
        }
    }

    const state = getWindowState(windowId);
    let active = state.history.first;

    // If we are opening tabs in order, place the tab next to the last tab
    // we opened instead of next to its opener.
    if (settings.openInOrder && state.inOrderTab !== undefined) {
        if (tab.openerTabId === active) {
            try {
                const prevTab = await browser.tabs.get(state.inOrderTab);
                active = prevTab.id;
            }
            catch (e) {
                console.warn(e);
            }
        }
    }

    if (active !== undefined) {
        logger.enabled && logger.log(`moving tab ${tab.id} next to active tab ${active}`);

        await moveNextToTab(tab, active);
        state.inOrderTab = tab.id;
    }
}
开发者ID:ChaosinaCan,项目名称:ClassicTabs,代码行数:39,代码来源:TabManager.ts

示例4: positionNewWindowTab

async function positionNewWindowTab(tab: Tabs.Tab) {
    if (tab.openerTabId === undefined || tab.windowId === undefined) {
        return;
    }

    if (shouldPreventNewWindow()) {
        try {
            const opener = await browser.tabs.get(tab.openerTabId);
            if (opener.windowId === undefined) {
                return;
            }

            if (tab.windowId !== opener.windowId) {
                logger.enabled && logger.log(`returning ${tab.id} to window ${opener.windowId}`);

                await moveToWindow(tab, opener.windowId);
                // TODO: focus tab here?
            }
        }
        catch (e) {
            console.warn(e);
        }
    }
}
开发者ID:ChaosinaCan,项目名称:ClassicTabs,代码行数:24,代码来源:TabManager.ts


注:本文中的webextension-polyfill-ts.browser.tabs.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。