-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinks.html
203 lines (182 loc) · 6.74 KB
/
links.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="src/black.ico" type="image/x-icon">
<title>Link Converter</title>
<style>
body {
background-color: #1a1a1a;
color: #ffffff;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
.container {
width: 100%;
max-width: 600px;
margin: 0 auto;
}
h1 {
color: #7cb9e8;
text-align: center;
margin-bottom: 30px;
font-weight: 300;
}
textarea {
width: 100%;
height: 100px;
background-color: #2d2d2d;
border: 1px solid #404040;
border-radius: 8px;
color: #ffffff;
padding: 15px;
font-size: 14px;
resize: none;
margin-bottom: 20px;
box-sizing: border-box;
}
textarea:focus {
outline: none;
border-color: #7cb9e8;
box-shadow: 0 0 5px rgba(124, 185, 232, 0.3);
}
#linkContainer {
width: 100%;
text-align: justify;
}
.link-wrapper {
display: flex;
align-items: center;
margin: 4px 0;
}
.delete-button {
width: 24px;
height: 24px;
margin-right: 8px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s ease;
color: #666;
border: none;
background: transparent;
font-size: 18px;
}
.link-wrapper:hover .delete-button {
opacity: 1;
}
.delete-button:hover {
color: #ff4444;
}
.link-item {
display: block;
color: #7cb9e8;
text-decoration: none;
padding: 8px 0;
transition: color 0.3s ease;
font-size: 14px;
word-break: break-all;
flex-grow: 1;
}
.link-item:hover {
color: #a8d5ff;
}
strong {
color: #7cb9e8;
display: block;
padding: 8px 0;
font-size: 16px;
margin-top: 8px;
}
hr {
border: 0;
border-top: 1px solid #404040;
margin: 12px 0;
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Link Converter</h1>
<textarea id="linkInput" placeholder="Paste links here, one per line..."></textarea>
<div id="linkContainer"></div>
</div>
<script>
document.getElementById('linkInput').addEventListener('input', function() {
// Get all lines including empty ones
const lines = this.value.split('\n');
const linkContainer = document.getElementById('linkContainer');
linkContainer.innerHTML = '';
lines.forEach(line => {
const trimmedLine = line.trim();
if (!trimmedLine) return; // Skip empty lines
const wrapper = document.createElement('div');
wrapper.className = 'link-wrapper';
// Handle headers (# prefix)
if (trimmedLine.startsWith('#')) {
const headerElement = document.createElement('strong');
headerElement.textContent = line; // Preserve original spacing
wrapper.appendChild(headerElement);
}
// Handle separators (---)
else if (/^-{3,}$/.test(trimmedLine)) {
const hr = document.createElement('hr');
hr.style.borderColor = '#404040';
wrapper.innerHTML = '<hr>';
}
// Handle links and other text
else {
// Auto-add https:// prefix if missing
let url = trimmedLine;
if (!url.startsWith('http://') &&
!url.startsWith('https://') &&
!url.startsWith('file://')) {
url = 'https://' + url;
}
// Delete button setup
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-button';
deleteButton.innerHTML = '×';
deleteButton.onclick = function() {
// Get current RAW lines (preserve empty lines)
const currentLines = document.getElementById('linkInput').value.split('\n');
// Find exact line index using original trim comparison
const lineIndex = currentLines.findIndex(l => l.trim() === trimmedLine);
if (lineIndex > -1) {
// 1. Remove the target line
currentLines.splice(lineIndex, 1);
// 2. Remove following empty line if exists
if (lineIndex < currentLines.length &&
currentLines[lineIndex].trim() === '') {
currentLines.splice(lineIndex, 1);
}
// Update textarea and trigger refresh
document.getElementById('linkInput').value = currentLines.join('\n');
document.getElementById('linkInput').dispatchEvent(new Event('input'));
}
};
// Link element setup
const linkElement = document.createElement('a');
linkElement.href = url;
linkElement.className = 'link-item';
linkElement.textContent = line; // Preserve original formatting
linkElement.target = '_blank';
linkElement.rel = 'noreferrer noopener';
wrapper.appendChild(deleteButton);
wrapper.appendChild(linkElement);
}
linkContainer.appendChild(wrapper);
});
});
</script>
</body>
</html>