Skip to content

Commit 0e9369a

Browse files
authored
Merge pull request #5 from semanticdata/feat/basic-export
2 parents 07dc9b3 + 1df80e0 commit 0e9369a

7 files changed

Lines changed: 90 additions & 3 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

packages/newtab/newtab.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171
</select>
7272
</div>
7373

74+
<!-- Export Button -->
75+
<button id="export-button" aria-label="Export notes">
76+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
77+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
78+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
79+
<polyline points="7 10 12 15 17 10"></polyline>
80+
<line x1="12" y1="15" x2="12" y2="3"></line>
81+
</svg>
82+
</button>
83+
7484
<!-- Settings Trigger -->
7585
<button id="settings-toggle" aria-label="Open settings" aria-expanded="false">
7686
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
@@ -90,6 +100,7 @@
90100
</footer>
91101

92102
<script type="text/javascript" src="script.js"></script>
103+
<script type="text/javascript" src="export.js"></script>
93104
</body>
94105

95106
</html>

packages/sidebar/panel.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171
</select>
7272
</div>
7373

74+
<!-- Export Button -->
75+
<button id="export-button" aria-label="Export notes">
76+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
77+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
78+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
79+
<polyline points="7 10 12 15 17 10"></polyline>
80+
<line x1="12" y1="15" x2="12" y2="3"></line>
81+
</svg>
82+
</button>
83+
7484
<!-- Settings Trigger -->
7585
<button id="settings-toggle" aria-label="Open settings" aria-expanded="false">
7686
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
@@ -90,6 +100,7 @@
90100
</footer>
91101

92102
<script type="text/javascript" src="script.js"></script>
103+
<script type="text/javascript" src="export.js"></script>
93104
</body>
94105

95106
</html>

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+
}

shared/styles.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ textarea:focus {
126126

127127
/* Buttons (Shared for Theme & Settings) */
128128
#theme-toggle,
129-
#settings-toggle {
129+
#settings-toggle,
130+
#export-button {
130131
background: none;
131132
border: none;
132133
padding: 6px;
@@ -138,6 +139,7 @@ textarea:focus {
138139

139140
#theme-toggle:hover,
140141
#settings-toggle:hover,
142+
#export-button:hover,
141143
#settings-toggle[aria-expanded="true"] {
142144
background: rgba(127, 127, 127, 0.1);
143145
color: var(--fg);

0 commit comments

Comments
 (0)