Skip to content

Commit

Permalink
Merge pull request #32 from kairi003/master
Browse files Browse the repository at this point in the history
master #31 to firefox (Fix: Improve Firefox compat in save/setClipboard)
  • Loading branch information
kairi003 authored Apr 11, 2023
2 parents d844df1 + e299d28 commit 7729973
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Get cookies.txt LOCALLY",
"description": "Get cookies.txt, NEVER send information outside with open-source",
"version": "0.4.2",
"version": "0.4.3",
"manifest_version": 3,
"permissions": [
"activeTab",
Expand Down
25 changes: 15 additions & 10 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,29 @@ const FormatMap = {
* @param {Format} format
* @param {boolean} saveAs
*/
const save = async (text, name, { ext, mimeType }, saveAs=false) => {
const url = `data:${mimeType},${encodeURIComponent(text)}`;
const save = async (text, name, { ext, mimeType }, saveAs = false) => {
const blob = new Blob([text], { 'type': mimeType });
const filename = name + ext;
await chrome.downloads.download({url, filename, saveAs});
const url = URL.createObjectURL(blob);
const downloadId = await chrome.downloads.download({ url, filename, saveAs });
/** @type {(downloadDelta: chrome.downloads.DownloadDelta) => void} */
const callback = delta => {
const { id, state, error } = delta;
if (id === downloadId && (state?.current === 'complete' || error)) {
URL.revokeObjectURL(url);
chrome.downloads.onChanged.removeListener(callback);
}
}
chrome.downloads.onChanged.addListener(callback);
}

/**
* Copy text data to the clipboard
* @param {string} text
*/
const setClipboard = async (text) => {
const type = 'text/plain';
const blob = new Blob([text], { type });
const data = [new ClipboardItem({ [type]: blob })];
navigator.clipboard.write(data)
.then(() => {
document.getElementById('copy').innerText = 'Copied!';
})
await navigator.clipboard.writeText(text);
document.getElementById('copy').innerText = 'Copied!';
}

/**
Expand Down

0 comments on commit 7729973

Please sign in to comment.