Skip to content

Commit 4eba9c9

Browse files
committed
Add JSON format
Now, it is possible to use the JSON format when exporting the content of the dump. See #28
1 parent 0dc328d commit 4eba9c9

File tree

6 files changed

+96
-37
lines changed

6 files changed

+96
-37
lines changed

background.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ function getDownloadOptions(format) {
8585
filename: 'linkdump.bb',
8686
type: 'text/plain'
8787
};
88+
case 'json':
89+
return {
90+
filename: 'linkdump.json',
91+
type: 'application/json',
92+
transformer: JSON.stringify
93+
};
8894
default:
8995
return {
9096
reducer: textReducer,
@@ -98,7 +104,12 @@ function copy(downloadOptions) {
98104
browser.storage.local.get('urls').then(obj => {
99105
if (!obj.urls) return;
100106

101-
const content = obj.urls.reduce(downloadOptions.reducer, '');
107+
let content;
108+
if (downloadOptions.reducer) {
109+
content = obj.urls.reduce(downloadOptions.reducer, '');
110+
} else {
111+
content = downloadOptions.transformer(obj.urls);
112+
}
102113

103114
browser.runtime.sendMessage({
104115
action: 'copy',
@@ -111,7 +122,12 @@ function download(downloadOptions) {
111122
browser.storage.local.get('urls').then(obj => {
112123
if (!obj.urls) return;
113124

114-
const content = obj.urls.reduce(downloadOptions.reducer, '');
125+
let content;
126+
if (downloadOptions.reducer) {
127+
content = obj.urls.reduce(downloadOptions.reducer, '');
128+
} else {
129+
content = downloadOptions.transformer(obj.urls);
130+
}
115131
const blob = new Blob([content], { type: downloadOptions.type });
116132

117133
browser.downloads

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
"manifest_version": 2,
99
"name": "LinkDump",
10-
"version": "1.13.1",
10+
"version": "1.14",
1111
"description": "__MSG_extensionDescription__",
1212
"icons": {
1313
"48": "icons/linkdump-48.png"

options/options.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
<td><label class="switch"><input type="checkbox" checked="checked" data-action="download" data-format="phpbb"><span class="slider"></span></label></td>
4242
<td><label class="switch"><input type="checkbox" checked="checked" data-action="copy" data-format="phpbb"><span class="slider"></span></label></td>
4343
</tr>
44+
<tr>
45+
<th>JSON</th>
46+
<td><label class="switch"><input type="checkbox" checked="checked" data-action="download" data-format="json"><span class="slider"></span></label></td>
47+
<td><label class="switch"><input type="checkbox" checked="checked" data-action="copy" data-format="json"><span class="slider"></span></label></td>
48+
</tr>
4449
<tr>
4550
<td><label for="clearAfter">Clear dump after</label></td>
4651
<td><label class="switch"><input type="checkbox" data-action="clear" data-format="download"><span class="slider"></span></label></td>

package-lock.json

Lines changed: 67 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "linkdump",
3-
"version": "1.13.1",
3+
"version": "1.14",
44
"description": "Store links and dump them",
55
"main": "background.js",
66
"scripts": {
@@ -26,7 +26,7 @@
2626
"eslint-config-airbnb-base": "^12.1.0",
2727
"eslint-config-prettier": "^2.10.0",
2828
"eslint-plugin-compat": "^2.7.0",
29-
"eslint-plugin-import": "^2.17.2",
30-
"prettier": "^1.17.0"
29+
"eslint-plugin-import": "^2.18.2",
30+
"prettier": "^1.18.2"
3131
}
3232
}

popup/load.content.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<li><a data-action="download" data-format="html" href="#">HTML</a></li>
1717
<li><a data-action="download" data-format="dokuwiki" href="#">Dokuwiki</a></li>
1818
<li><a data-action="download" data-format="phpbb" href="#">PhpBB</a></li>
19+
<li><a data-action="download" data-format="json" href="#">JSON</a></li>
1920
</ul>
2021
</li>
2122
<li>
@@ -26,6 +27,7 @@
2627
<li><a data-action="copy" data-format="html" href="#">HTML</a></li>
2728
<li><a data-action="copy" data-format="dokuwiki" href="#">Dokuwiki</a></li>
2829
<li><a data-action="copy" data-format="phpbb" href="#">PhpBB</a></li>
30+
<li><a data-action="copy" data-format="json" href="#">JSON</a></li>
2931
</ul>
3032
</li>
3133
<li><img data-action="clear" src="../icons/trash-48.png"/></li>

0 commit comments

Comments
 (0)