Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.warn(
`Failed to execute Saka into tab. Instead, created new Saka tab after ${
currentTab.url
}`
);
}
}
// If tab couldn't be found (e.g. because query was made from devtools) create a new tab
} else {
await browser.tabs.create({
url: '/saka.html'
});
if (SAKA_DEBUG)
console.log("Couldn't find tab. Instead, created new Saka tab.");
}
const window = await browser.windows.getLastFocused();
await browser.windows.update(window.id, { focused: true });
if (SAKA_DEBUG) console.groupEnd();
}
window.openedWindowIds.map(windowId =>
browser.windows.remove(windowId).catch(() => {
/* Window was removed previously by the user */
})
)
async function focusOrCreateTab(url) {
const matchingTabs = await browser.tabs.query({ url });
if (matchingTabs && matchingTabs.length > 0) {
// If multiple matching tabs then just focus the first one
const existingTab = matchingTabs[0];
await browser.tabs.update(existingTab.id, { active: true });
await browser.windows.update(existingTab.windowId, { focused: true });
} else {
await browser.tabs.create({ url });
}
}
async closeAllOpenedWindows() {
const windowIds = Object.keys(this.openedWindowIds).map(id => parseInt(id))
for (let windowId of windowIds) {
await browser.windows.remove(windowId)
}
this.openedWindowIds = {}
}
function openPanel(tab) {
let contentWindowId = tab.windowId
if (ideWindowId) {
browser.windows
.update(ideWindowId, {
focused: true,
})
.catch(function() {
ideWindowId == undefined
openPanel(tab)
})
return
} else if (!clickEnabled) {
return
}
clickEnabled = false
setTimeout(function() {
clickEnabled = true
}, 1500)
export const addCurrentWindow = async id => {
log.info(logDir, "AddCurrentWindow()", id);
const session = await getSessions(id);
const currentWindow = await browser.windows.getCurrent({ populate: true });
//tabIdをユニークなIDに更新してマップに格納
let tabIdList = Object.values(session.windows).flatMap(window =>
Object.values(window).map(tab => tab.id)
);
let updatedTabIdMap = {};
for (const tab of currentWindow.tabs) {
const isTabIdDuplicate = id => tabIdList.some(tabId => tabId == id);
const newTabId = generateUniqueId(tab.id, isTabIdDuplicate);
updatedTabIdMap[tab.id] = newTabId;
tabIdList.push(newTabId);
}
const isWindowIdDuplicate = id => session.windows.hasOwnProperty(id);
const windowId = generateUniqueId(currentWindow.id, isWindowIdDuplicate);
export const openPopup = () => {
const { availHeight, availLeft, availTop, availWidth } = screen
const width = getInt(Math.max(MAX_WIDTH, availWidth / 2))
const height = getInt(Math.max(MAX_HEIGHT, availHeight / 2))
const top = getInt(availTop + (availHeight - height) / 2)
const left = getInt(availLeft + (availWidth - width) / 2)
browser.windows.create({
top,
left,
height,
width,
url: popupURL,
type: 'popup'
})
}
const dynamicDisableMenu = async () => {
const groupedTabs = await tabs.groupTabsInCurrentWindow()
const windows = await browser.windows.getAll()
browser.contextMenus.update('STORE.STORE_LEFT_TABS', {
enabled: groupedTabs.left.length !== 0,
title: __('menu_STORE_LEFT_TABS') + ` (${groupedTabs.left.length})`,
})
browser.contextMenus.update('STORE.STORE_RIGHT_TABS', {
enabled: groupedTabs.right.length !== 0,
title: __('menu_STORE_RIGHT_TABS') + ` (${groupedTabs.right.length})`,
})
browser.contextMenus.update('STORE.STORE_TWOSIDE_TABS', {
enabled: groupedTabs.twoSide.length !== 0,
title: __('menu_STORE_TWOSIDE_TABS') + ` (${groupedTabs.twoSide.length})`,
})
browser.contextMenus.update('STORE.STORE_ALL_TABS_IN_ALL_WINDOWS', {
enabled: windows.length > 1,
})
browser.contextMenus.update('STORE.STORE_ALL_TABS_IN_CURRENT_WINDOW', {
async function sortAndMergeWindows() {
const currentWindow = await browser.windows.getCurrent()
const allWindows = await browser.windows.getAll({populate: true})
let allTabs = []
let index = 0
allWindows.forEach((browserWindow) => {
browserWindow.tabs.forEach((tab) => {
allTabs.push({id: tab.id, domain: domain.origin(tab.url)})
})
allTabs = sortBy(allTabs, ['domain'])
allTabs.forEach((tab) => {
browser.tabs.move(tab.id, {windowId: currentWindow.id, index})
index += 1
})
window.close()
const thisItemInfo: Object = await getBookmark(itemInfo.id)
urlList.push(thisItemInfo.url)
}
if (!isNewWindow) {
await Promise.all(
urlList.map((url: string): Promise => {
return webExtension.tabs.create({
url,
active: false
})
})
)
} else {
await webExtension.windows.create({
url: urlList,
incognito: isIncognito
})
}
window.close()
}