-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from kairi003/develop
release v0.6.0
- Loading branch information
Showing
17 changed files
with
258 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,5 @@ dist | |
# TernJS port file | ||
.tern-port | ||
|
||
dst/ | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type Format = { | ||
ext: string; | ||
mimeType: string; | ||
serializer: (cookies: chrome.cookies.Cookie[]) => string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!-- This file is used to load the background script on Firefox. --> | ||
<script type="module" src="background.mjs"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"incognito": "spanning", | ||
"background": { | ||
"page": "background.html" | ||
}, | ||
"browser_specific_settings": { | ||
"gecko": { | ||
"id": "{ac87cfd8-47b1-4401-b32e-f033af5ed96b}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Convert Chrome's JSON format cookies data to a string array for Netscape format | ||
* @param {chrome.cookies.Cookie[]} cookies | ||
* @returns {string[][]} | ||
*/ | ||
export const jsonToNetscapeMapper = (cookies) => { | ||
return cookies.map(({ domain, expirationDate, path, secure, name, value }) => { | ||
const includeSubDomain = !!domain?.startsWith('.'); | ||
const expiry = expirationDate?.toFixed() ?? '0'; | ||
const arr = [domain, includeSubDomain, path, secure, expiry, name, value]; | ||
return arr.map((v) => (typeof v === 'boolean' ? v.toString().toUpperCase() : v)); | ||
}); | ||
}; | ||
|
||
/** @type {Record<string, Format>} */ | ||
export const formatMap = { | ||
netscape: { | ||
ext: '.txt', | ||
mimeType: 'text/plain', | ||
serializer: (cookies) => { | ||
const netscapeTable = jsonToNetscapeMapper(cookies); | ||
const text = [ | ||
'# Netscape HTTP Cookie File', | ||
'# http://curl.haxx.se/rfc/cookie_spec.html', | ||
'# This is a generated file! Do not edit.', | ||
'', | ||
...netscapeTable.map((row) => row.join('\t')), | ||
'' // Add a new line at the end | ||
].join('\n'); | ||
return text; | ||
} | ||
}, | ||
json: { | ||
ext: '.json', | ||
mimeType: 'application/json', | ||
serializer: JSON.stringify | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Get all cookies that match the given criteria. | ||
* @param {chrome.cookies.GetAllDetails} details | ||
* @returns {Promise<chrome.cookies.Cookie[]>} | ||
*/ | ||
export default async function getAllCookies(details) { | ||
details.storeId ??= await getCurrentCookieStoreId(); | ||
const { partitionKey, ...detailsWithoutPartitionKey } = details; | ||
const cookiesWithPartitionKey = partitionKey ? await chrome.cookies.getAll(details) : []; | ||
const cookies = await chrome.cookies.getAll(detailsWithoutPartitionKey); | ||
return [...cookies, ...cookiesWithPartitionKey]; | ||
} | ||
|
||
/** | ||
* Get the current cookie store ID. | ||
* @returns {Promise<string | undefined>} | ||
*/ | ||
const getCurrentCookieStoreId = async () => { | ||
// If the extension is in split incognito mode, return undefined to choose the default store. | ||
if (chrome.runtime.getManifest().incognito === 'split') return undefined; | ||
|
||
// Firefox supports the `tab.cookieStoreId` property. | ||
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); | ||
if (tab.cookieStoreId) return tab.cookieStoreId; | ||
|
||
// Chrome does not support the `tab.cookieStoreId` property. | ||
const stores = await chrome.cookies.getAllCookieStores(); | ||
return stores.find((store) => store.tabIds.includes(tab.id))?.id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,6 @@ | |
gap: 0.5em; | ||
} | ||
|
||
.netscape-table.nowrap { | ||
.netscape-table.nowrap tbody { | ||
white-space: nowrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.