-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
22 lines (19 loc) · 904 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// script.js
document.getElementById('convertButton').addEventListener('click', function () {
const opmlContent = document.getElementById('opmlInput').value;
if (!opmlContent) {
alert('Please paste your OPML code.');
return;
}
// Replace & with &037;
const correctedOpmlContent = opmlContent.replace(/&(?!amp;|lt;|gt;|quot;|apos;)/g, '&037;');
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(correctedOpmlContent, "text/xml");
const title = xmlDoc.getElementsByTagName('title')[0]?.textContent || 'outline';
const blob = new Blob([correctedOpmlContent], { type: 'text/xml' });
const url = URL.createObjectURL(blob);
const downloadButton = document.getElementById('downloadButton');
downloadButton.href = url;
downloadButton.download = `${title}.opml`;
downloadButton.style.display = 'inline-block';
});