Skip to content

Commit 9a2e13a

Browse files
committed
new export script
1 parent 859c345 commit 9a2e13a

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ packages/sidebar/styles.css
55
packages/sidebar/script.js
66
packages/sidebar/icon.svg
77
packages/sidebar/preload.js
8+
packages/sidebar/export.js
89
packages/newtab/styles.css
910
packages/newtab/script.js
1011
packages/newtab/icon.svg
1112
packages/newtab/preload.js
13+
packages/newtab/export.js
1214
web-ext-artifacts

scripts/copy-shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require('path');
66
// Configuration
77
const sharedDir = path.join(__dirname, '../shared');
88
const packagesDir = path.join(__dirname, '../packages');
9-
const sharedFiles = ['script.js', 'styles.css', 'icon.svg', 'preload.js'];
9+
const sharedFiles = ['script.js', 'styles.css', 'icon.svg', 'preload.js', 'export.js'];
1010
const targets = ['newtab', 'sidebar'];
1111

1212
// Colors for console output

scripts/watch-shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { build } = require('./copy-shared.js');
88

99
// Configuration
1010
const sharedDir = path.join(__dirname, '../shared');
11-
const sharedFiles = ['script.js', 'styles.css', 'icon.svg'];
11+
const sharedFiles = ['script.js', 'styles.css', 'icon.svg', 'preload.js', 'export.js'];
1212

1313
// Colors for console output
1414
const colors = {

shared/export.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Export functionality for NoteKeeper
2+
const exportEls = {
3+
exportButton: document.getElementById("export-button"),
4+
notes: document.getElementById("notes"),
5+
status: document.getElementById("save-status"),
6+
};
7+
8+
// Generate timestamped filename: YYYYMMDDThhmm-notekeeper.txt
9+
const generateFilename = () => {
10+
const now = new Date();
11+
const year = now.getFullYear();
12+
const month = String(now.getMonth() + 1).padStart(2, "0");
13+
const day = String(now.getDate()).padStart(2, "0");
14+
const hours = String(now.getHours()).padStart(2, "0");
15+
const minutes = String(now.getMinutes()).padStart(2, "0");
16+
17+
return `${year}${month}${day}T${hours}${minutes}-notekeeper.txt`;
18+
};
19+
20+
// Export notes to local file
21+
const exportNotes = () => {
22+
const content = exportEls.notes.value;
23+
24+
if (!content.trim()) {
25+
exportEls.status.textContent = "Nothing to export";
26+
setTimeout(() => {
27+
exportEls.status.textContent = "Ready";
28+
}, 2000);
29+
return;
30+
}
31+
32+
try {
33+
const filename = generateFilename();
34+
const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
35+
const url = URL.createObjectURL(blob);
36+
37+
const a = document.createElement("a");
38+
a.href = url;
39+
a.download = filename;
40+
document.body.appendChild(a);
41+
a.click();
42+
document.body.removeChild(a);
43+
URL.revokeObjectURL(url);
44+
45+
exportEls.status.textContent = "Exported";
46+
setTimeout(() => {
47+
exportEls.status.textContent = "Ready";
48+
}, 2000);
49+
} catch (error) {
50+
console.error("Export error:", error);
51+
exportEls.status.textContent = "Export failed";
52+
setTimeout(() => {
53+
exportEls.status.textContent = "Ready";
54+
}, 2000);
55+
}
56+
};
57+
58+
// Initialize export functionality
59+
if (exportEls.exportButton && exportEls.notes && exportEls.status) {
60+
exportEls.exportButton.addEventListener("click", exportNotes);
61+
}

0 commit comments

Comments
 (0)