From 42709450f26b840b4381b7cb8ba1cd3035563f8b Mon Sep 17 00:00:00 2001 From: Mikhail Vyrtsev Date: Fri, 1 Sep 2017 11:44:19 +0300 Subject: [PATCH] support firefox contextualidentities --- ext/manifest.json | 4 ++-- src/background.js | 36 +++++++++++++++++++++++++----------- src/utils.js | 5 +++++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ext/manifest.json b/ext/manifest.json index e4ee1b9..14bb178 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Tab Saver", - "version": "0.0.8", + "version": "0.0.9", "description": "Allows you to manage and save tabs", "icons": { "48": "icons/icon.png" @@ -19,7 +19,7 @@ "storage", "tabs", "downloads", - "activeTab" + "cookies" ], "applications": { "gecko": { diff --git a/src/background.js b/src/background.js index 1df29f5..07b8947 100644 --- a/src/background.js +++ b/src/background.js @@ -1,6 +1,18 @@ -import {readFileAsJson, saveFile, first, setsAreEqual, firstIndex, oneOf, sleep, strAfter} from "./utils.js"; +import { + readFileAsJson, + saveFile, + first, + setsAreEqual, + firstIndex, + oneOf, + sleep, + strAfter, + getKey +} from "./utils.js"; import {data} from "./shared.js"; +const DEFAULT_COOKIE_STORE_ID = "firefox-default"; + async function main(){ const extensionURL = await browser.extension.getURL("/html/handler.html"); @@ -47,6 +59,7 @@ async function main(){ .map(x => ({ url: x.url, pinned: x.pinned, + cookieStoreId: x.cookieStoreId || DEFAULT_COOKIE_STORE_ID, })) .filter(x => { return !oneOf(x.url, "about:blank", "about:newtab"); @@ -111,16 +124,17 @@ async function main(){ x.url = getMangledURL(x.url); return x; }); - const window = await browser.windows.create({ - url: allowedTabs.map(x => x.url), - }); - for(let [index, tab] of window.tabs.entries()){ - await browser.tabs.update( - tab.id, - { - pinned: "pinned" in allowedTabs[index] ? allowedTabs[index].pinned : false, - }, - ) + let window = await browser.windows.create(); + const tabNeedToBeClosed = window.tabs[0]; + for(const [index, tab] of allowedTabs.entries()){ + await browser.tabs.create({ + url: tab.url, + windowId: window.id, + pinned: getKey(tab, "pinned", false), + cookieStoreId: getKey(tab, "cookieStoreId", DEFAULT_COOKIE_STORE_ID), + active: false, + }); + if(index === 0) await browser.tabs.remove(tabNeedToBeClosed.id); } }; diff --git a/src/utils.js b/src/utils.js index 6cde596..2d66c5f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -129,4 +129,9 @@ export function oneOf(obj, ...subjs){ export function strAfter(str, search){ if(str.indexOf(search) === -1) return str; return str.substr(str.indexOf(search) + search.length); +} + +export function getKey(obj, key, def = null){ + if(key in obj) return obj[key]; + return def; } \ No newline at end of file