本文整理匯總了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,
};
}
示例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>`;
};
示例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;
}
}
示例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);
}
}
}