<script src="https://cdnjs.cloudflare.com/ajax/libs/xml2js/0.4.23/xml2js.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OPML to JSON Converter</title>
<link rel="stylesheet" href="styles.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/xml2js/0.4.23/xml2js.min.js"></script>
</head>
<body>
<div class="container">
<h1>OPML to JSON Converter</h1>
<input type="file" id="fileInput" accept=".opml">
<button id="convertBtn">Convert</button>
<textarea id="outputJson" readonly placeholder="Converted JSON will appear here..."></textarea>
<div class="buttons">
<button id="copyBtn">Copy JSON</button>
<button id="downloadBtn">Download JSON</button>
<button id="themeToggle">🌙</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
/* General Styles */
body {
font-family: Arial, sans-serif;
background: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
/* Container */
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
width: 90%;
max-width: 600px;
text-align: center;
}
/* Title */
h1 {
color: #333;
}
/* File Input */
input[type="file"] {
margin: 10px 0;
}
/* Textarea */
textarea {
width: 100%;
height: 200px;
margin-top: 10px;
padding: 10px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 5px;
resize: none;
}
/* Buttons */
.buttons {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
button {
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
color: white;
transition: 0.3s;
}
#convertBtn { background: #28a745; }
#copyBtn { background: #007bff; }
#downloadBtn { background: #ff9800; }
#themeToggle { background: #333; }
button:hover {
opacity: 0.8;
}
/* Dark Mode */
.dark-mode {
background: #222;
color: white;
}
.dark-mode .container {
background: #333;
}
.dark-mode h1 {
color: white;
}
.dark-mode textarea {
background: #444;
color: white;
border: 1px solid #666;
}
.dark-mode button {
background: #666;
}
/* Responsive */
@media (max-width: 500px) {
.buttons {
flex-direction: column;
}
button {
margin-bottom: 10px;
}
}
/* General Styles */
body {
font-family: Arial, sans-serif;
background: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
/* Container */
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
width: 90%;
max-width: 600px;
text-align: center;
}
/* Title */
h1 {
color: #333;
}
/* File Input */
input[type="file"] {
margin: 10px 0;
}
/* Textarea */
textarea {
width: 100%;
height: 200px;
margin-top: 10px;
padding: 10px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 5px;
resize: none;
}
/* Buttons */
.buttons {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
button {
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
color: white;
transition: 0.3s;
}
#convertBtn { background: #28a745; }
#copyBtn { background: #007bff; }
#downloadBtn { background: #ff9800; }
#themeToggle { background: #333; }
button:hover {
opacity: 0.8;
}
/* Dark Mode */
.dark-mode {
background: #222;
color: white;
}
.dark-mode .container {
background: #333;
}
.dark-mode h1 {
color: white;
}
.dark-mode textarea {
background: #444;
color: white;
border: 1px solid #666;
}
.dark-mode button {
background: #666;
}
/* Responsive */
@media (max-width: 500px) {
.buttons {
flex-direction: column;
}
button {
margin-bottom: 10px;
}
}
document.getElementById('convertBtn').addEventListener('click', function () {
let fileInput = document.getElementById('fileInput').files[0];
if (!fileInput) {
alert('Please select an OPML file.');
return;
}
let reader = new FileReader();
reader.readAsText(fileInput);
reader.onload = function (event) {
let opmlContent = event.target.result;
xml2js.parseString(opmlContent, { explicitArray: false }, function (err, result) {
if (err) {
alert('Invalid OPML format.');
return;
}
let jsonOutput = JSON.stringify(result, null, 4);
document.getElementById('outputJson').value = jsonOutput;
});
};
});
document.getElementById('copyBtn').addEventListener('click', function () {
let outputJson = document.getElementById('outputJson');
outputJson.select();
document.execCommand('copy');
alert('Copied to clipboard!');
});
document.getElementById('downloadBtn').addEventListener('click', function () {
let jsonData = document.getElementById('outputJson').value;
if (jsonData.trim() === '') {
alert('No JSON data to download!');
return;
}
let blob = new Blob([jsonData], { type: 'application/json' });
let link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'converted.json';
link.click();
});
document.getElementById('themeToggle').addEventListener('click', function () {
document.body.classList.toggle('dark-mode');
this.textContent = document.body.classList.contains('dark-mode') ? '☀️' : '🌙';
});
