Skip to content

Commit ba00d84

Browse files
committed
feat: enhance CSV editor with iCal URL generation
1 parent 601fbd3 commit ba00d84

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

docs/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ <h1>CSV-to-iCal</h1>
1717
<a href="https://github.com/fantasticmao/csv-to-ical" target="_blank">project page</a>.
1818
</p>
1919

20-
<h2>CSV Data Edit And Preview</h2>
20+
<h2>Edit CSV Data, Download or Get iCal URL</h2>
2121
<div id="editor-controls">
2222
<button id="download-btn">Download CSV</button>
23+
<button id="get-link-btn">Get iCal URL</button>
2324
</div>
2425
<div id="csv-table-container"></div>
2526
</div>

docs/script.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ document.addEventListener('DOMContentLoaded', function () {
66

77
let tableData = [
88
["Name", "Month", "Day", "Year", "Calendar_Type"],
9-
["New Year's Day", "1", "1", "2026", "solar"],
10-
["Chinese New Year's Day", "1", "1", "2026", "lunar"],
9+
["New Year", "1", "1", "2026", "solar"],
10+
["Chinese New Year", "1", "1", "2026", "lunar"],
1111
["Women's Day", "3", "8", "2026", "solar"],
12-
["Children's Day", "6", "1", "2026", "solar"],
1312
["Dragon Boat Festival", "5", "5", "2026", "lunar"],
14-
["Magpie Festival", "7", "7", "2026", "lunar"],
13+
["Children's Day", "6", "1", "2026", "solar"],
1514
["Mid-Autumn Festival", "8", "15", "2026", "lunar"],
16-
["Christmas Day", "12", "25", "2026", "solar"]
15+
["Bruce Lee", "11", "27", "1940", "birthday_solar"],
16+
["Bruce Lee", "10", "28", "1940", "birthday_lunar"],
1717
];
1818

1919
// Find column indexes once
@@ -61,7 +61,7 @@ document.addEventListener('DOMContentLoaded', function () {
6161
for (let i = 1; i <= daysInMonth; i++) options += `<option value="${i}" ${i == cellText ? 'selected' : ''}>${i}</option>`;
6262
} else if (colIndex === yearColIndex) {
6363
const currentYear = new Date().getFullYear();
64-
for (let i = currentYear - 50; i <= currentYear + 50; i++) options += `<option value="${i}" ${i == cellText ? 'selected' : ''}>${i}</option>`;
64+
for (let i = 1900; i <= 2100; i++) options += `<option value="${i}" ${i == cellText ? 'selected' : ''}>${i}</option>`;
6565
} else if (colIndex === calendarTypeColIndex) {
6666
CALENDAR_TYPES.forEach(type => options += `<option value="${type}" ${type === cellText ? 'selected' : ''}>${type}</option>`);
6767
}
@@ -133,12 +133,28 @@ document.addEventListener('DOMContentLoaded', function () {
133133
const link = document.createElement('a');
134134
const url = URL.createObjectURL(blob);
135135
link.setAttribute('href', url);
136-
link.setAttribute('download', 'calendar.csv');
136+
link.setAttribute('download', 'csv-to-ical.csv');
137137
document.body.appendChild(link);
138138
link.click();
139139
document.body.removeChild(link);
140140
});
141141

142+
const getLinkBtn = document.getElementById('get-link-btn');
143+
if (getLinkBtn) {
144+
getLinkBtn.addEventListener('click', function () {
145+
const csvContent = tableToCSV();
146+
try {
147+
const base64Content = btoa(csvContent);
148+
const urlEncodedContent = encodeURIComponent(base64Content);
149+
const subscriptionLink = `https://csv-to-ical.fantasticmao.cn/remote?base64=${urlEncodedContent}`;
150+
window.open(subscriptionLink, '_blank');
151+
} catch (e) {
152+
console.error("Failed to encode CSV content: ", e);
153+
alert("Could not generate link due to an encoding error.");
154+
}
155+
});
156+
}
157+
142158
// Drag and Drop handlers
143159
function handleDragStart(e) {
144160
draggedRowIndex = parseInt(e.target.dataset.rowIndex, 10);

docs/style.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ tr.drag-over {
118118
background-color: #218838;
119119
}
120120

121-
.action-buttons {
122-
display: flex;
123-
gap: 5px; /* Creates space between buttons */
121+
.action-buttons button {
122+
margin-right: 5px;
124123
}

0 commit comments

Comments
 (0)