Skip to content

Commit

Permalink
support firefox contextualidentities
Browse files Browse the repository at this point in the history
  • Loading branch information
Reeywhaar committed Sep 1, 2017
1 parent ab99a70 commit 4270945
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ext/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -19,7 +19,7 @@
"storage",
"tabs",
"downloads",
"activeTab"
"cookies"
],
"applications": {
"gecko": {
Expand Down
36 changes: 25 additions & 11 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
};

Expand Down
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 4270945

Please sign in to comment.