-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscript.js
More file actions
555 lines (468 loc) · 18.5 KB
/
Copy pathscript.js
File metadata and controls
555 lines (468 loc) · 18.5 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
document.addEventListener('DOMContentLoaded', () => {
const rawMdUrl = 'https://raw.githubusercontent.com/bakinazik/rss/main/README.md';
const output = document.getElementById('output');
const themeToggle = document.getElementById('checkbox');
const searchInput = document.getElementById('searchInput');
const searchClearBtn = document.getElementById('searchClearBtn');
const chipsContainer = document.getElementById('chipsContainer');
const chipsScroll = document.getElementById('chipsScroll');
let allRssItems = [];
let categories = [];
let selectedSet = new Set();
let currentCategory = '';
let currentSearchTerm = '';
let displayedCount = 0;
const BATCH_SIZE = 15;
let isLoading = false;
let scrollSentinel = null;
let currentFilteredItems = [];
const selectAllBtn = document.getElementById('selectAllBtn');
const clearSelectionBtn = document.getElementById('clearSelectionBtn');
const exportBtn = document.getElementById('exportBtn');
const selectedCountSpan = document.getElementById('selectedCount');
const totalCountSpan = document.getElementById('totalCount');
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
function setTheme(isLight) {
if (isLight) {
document.documentElement.classList.add('light-theme');
localStorage.setItem('theme', 'light');
} else {
document.documentElement.classList.remove('light-theme');
localStorage.setItem('theme', 'dark');
}
}
const initializeTheme = () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
themeToggle.checked = true;
setTheme(true);
} else if (savedTheme === 'dark') {
themeToggle.checked = false;
setTheme(false);
} else {
themeToggle.checked = !prefersDarkScheme.matches;
setTheme(!prefersDarkScheme.matches);
}
};
themeToggle.addEventListener('change', () => setTheme(themeToggle.checked));
initializeTheme();
// Logo tıklanınca aramayı ve filtreleri sıfırla
const logoArea = document.querySelector('.logo-area');
if (logoArea) {
logoArea.addEventListener('click', () => {
searchInput.value = '';
currentSearchTerm = '';
currentCategory = '';
updateUrlParameter('');
displayedCount = 0;
document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
renderList();
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
let isDragging = false;
let startDragX = 0;
let startScrollLeft = 0;
chipsContainer.addEventListener('mousedown', (e) => {
isDragging = true;
startDragX = e.pageX;
startScrollLeft = chipsContainer.scrollLeft;
chipsContainer.style.cursor = 'grabbing';
chipsContainer.style.userSelect = 'none';
e.preventDefault();
});
window.addEventListener('mousemove', (e) => {
if (!isDragging) return;
const dx = (e.pageX - startDragX) * 2;
chipsContainer.scrollLeft = startScrollLeft - dx;
e.preventDefault();
});
window.addEventListener('mouseup', () => {
if (isDragging) {
isDragging = false;
chipsContainer.style.cursor = 'grab';
chipsContainer.style.userSelect = '';
}
});
chipsContainer.addEventListener('wheel', (e) => {
if (chipsContainer.scrollWidth > chipsContainer.clientWidth) {
e.preventDefault();
const delta = e.deltaY > 0 ? 400 : -400;
chipsContainer.scrollBy({
left: delta,
behavior: 'smooth'
});
}
}, { passive: false });
chipsContainer.style.cursor = 'grab';
document.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
e.preventDefault();
searchInput.focus();
searchInput.select();
}
});
let pendingKey = null;
function focusAndType() {
if (searchInput && document.activeElement !== searchInput && pendingKey) {
const activeTag = document.activeElement?.tagName;
const isEditable = document.activeElement?.isContentEditable;
const isInputOrTextarea = activeTag === 'INPUT' || activeTag === 'TEXTAREA';
if (!isInputOrTextarea && !isEditable) {
const keyToType = pendingKey;
pendingKey = null;
searchInput.focus();
const currentValue = searchInput.value;
const start = searchInput.selectionStart;
const end = searchInput.selectionEnd;
const newValue = currentValue.substring(0, start) + keyToType + currentValue.substring(end);
searchInput.value = newValue;
searchInput.selectionStart = searchInput.selectionEnd = start + 1;
const inputEvent = new Event('input', { bubbles: true });
searchInput.dispatchEvent(inputEvent);
}
}
pendingKey = null;
}
document.addEventListener('keydown', (event) => {
if (event.ctrlKey || event.altKey || event.metaKey || event.key === 'Escape') {
return;
}
const activeElement = document.activeElement;
const isSearchActive = activeElement === searchInput;
const isFormElement = activeElement?.tagName === 'INPUT' ||
activeElement?.tagName === 'TEXTAREA' ||
activeElement?.isContentEditable;
if (!isSearchActive && !isFormElement && (event.key.length === 1 || event.key === ' ')) {
event.preventDefault();
pendingKey = event.key;
focusAndType();
}
});
function handleSearch() {
currentSearchTerm = searchInput.value.trim().toLowerCase();
updateUrlParameter(currentSearchTerm);
displayedCount = 0;
renderList();
}
function clearSearch() {
searchInput.value = '';
currentSearchTerm = '';
updateUrlParameter('');
displayedCount = 0;
renderList();
searchInput.focus();
}
searchInput.addEventListener('input', handleSearch);
searchClearBtn?.addEventListener('click', clearSearch);
const updateUrlParameter = (searchTerm) => {
const url = new URL(window.location);
if (searchTerm) url.searchParams.set('q', searchTerm);
else url.searchParams.delete('q');
window.history.replaceState({}, '', url);
};
function buildChips() {
chipsScroll.innerHTML = '';
categories.forEach(cat => {
const chip = document.createElement('div');
chip.className = 'chip';
if (currentCategory === cat) chip.classList.add('active');
chip.setAttribute('data-category', cat);
const itemCount = allRssItems.filter(i => i.category === cat).length;
chip.textContent = `${cat} (${itemCount})`;
chip.addEventListener('click', (e) => {
e.stopPropagation();
const selectedCat = chip.getAttribute('data-category');
if (currentCategory === selectedCat) {
currentCategory = '';
document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
} else {
currentCategory = selectedCat;
document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
chip.classList.add('active');
}
displayedCount = 0;
renderList();
});
chipsScroll.appendChild(chip);
});
}
function renderList(reset = true) {
let filtered = [...allRssItems];
if (currentCategory) {
filtered = filtered.filter(item => item.category === currentCategory);
}
if (currentSearchTerm) {
filtered = filtered.filter(item =>
item.siteName.toLowerCase().includes(currentSearchTerm) ||
item.rssLink.toLowerCase().includes(currentSearchTerm)
);
}
filtered.sort((a, b) => a.siteName.localeCompare(b.siteName, 'tr'));
currentFilteredItems = filtered;
if (reset) {
displayedCount = Math.min(BATCH_SIZE, filtered.length);
}
if (filtered.length === 0) {
output.innerHTML = `
<div class="no-results">
<svg xmlns="http://www.w3.org/2000/svg" width="65" height="65" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-mood-sad"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" /><path d="M9 10l.01 0" /><path d="M15 10l.01 0" /><path d="M9.5 15.25a3.5 3.5 0 0 1 5 0" /></svg>
<p>Aramayla eşleşen bir sonuç bulunamadı</p>
<a href="https://github.com/bakinazik/rss/issues/new" target="_blank" class="btn github-issue-btn">Eksik bağlantıyı bildir</a>
</div>
`;
return;
}
let searchInfo = '';
const itemsToShow = filtered.slice(0, displayedCount);
let html = searchInfo + '<div class="rss-list">';
itemsToShow.forEach(item => {
const isChecked = selectedSet.has(item.rssLink);
const domain = getDomain(item.rssLink);
html += `
<div class="rss-item" data-rss-link="${escapeHtml(item.rssLink)}">
<input type="checkbox" class="rss-checkbox" data-rss="${escapeHtml(item.rssLink)}" data-site="${escapeHtml(item.siteName)}" ${isChecked ? 'checked' : ''}>
<img class="favicon" src="https://www.google.com/s2/favicons?domain=${domain}&sz=32" alt="" loading="lazy" onerror="this.src='data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22%2371717a%22><path d=%22M4 4h16v16H4z%22/></svg>'">
<div class="site-info">
<div class="site-name">${escapeHtml(item.siteName)}</div>
<a href="${item.rssLink}" target="_blank" class="rss-url" title="${item.rssLink}">${escapeHtml(item.rssLink)}</a>
</div>
<div class="item-actions">
<button class="copy-btn" data-url="${item.rssLink}" data-tooltip="Kopyala">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M8 4v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2v-12.5a1.5 1.5 0 0 0 -1.5 -1.5h-9a1.5 1.5 0 0 0 -1.5 1.5z"/>
<path d="M16 18v2a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h2"/>
</svg>
</button>
<a href="${item.rssLink}" target="_blank" class="external-link">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M18 13v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h6"/>
<path d="M15 3h6v6"/><path d="M10 14l11 -11"/>
</svg>
</a>
</div>
</div>
`;
});
html += '</div>';
if (displayedCount < filtered.length) {
html += `<div class="loading-more" id="loadingMore"><div class="loader-small"></div><span>Daha fazla yükleniyor...</span></div>`;
}
output.innerHTML = html;
attachCheckboxListeners();
attachCopyButtons();
attachItemClickListeners();
}
function loadMore() {
if (isLoading) return;
if (displayedCount >= currentFilteredItems.length) return;
isLoading = true;
const loadingMore = document.getElementById('loadingMore');
if (loadingMore) loadingMore.style.opacity = '0.5';
setTimeout(() => {
displayedCount = Math.min(displayedCount + BATCH_SIZE, currentFilteredItems.length);
renderList(false);
isLoading = false;
setupScrollObserver();
}, 100);
}
function setupScrollObserver() {
if (scrollSentinel) {
scrollSentinel.removeEventListener('click', loadMore);
}
scrollSentinel = document.getElementById('scrollSentinel');
if (scrollSentinel) {
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting && !isLoading && displayedCount < currentFilteredItems.length) {
loadMore();
}
}, { threshold: 0.1, rootMargin: '0px 0px 100px 0px' });
observer.observe(scrollSentinel);
}
}
function attachItemClickListeners() {
document.querySelectorAll('.rss-item').forEach(item => {
item.removeEventListener('click', itemClickHandler);
item.addEventListener('click', itemClickHandler);
});
}
function itemClickHandler(e) {
if (e.target.type !== 'checkbox' && !e.target.closest('.copy-btn') && !e.target.closest('.external-link') && !e.target.closest('.rss-url')) {
const cb = this.querySelector('.rss-checkbox');
if (cb) {
cb.checked = !cb.checked;
const changeEvent = new Event('change', { bubbles: true });
cb.dispatchEvent(changeEvent);
}
}
}
function getDomain(url) {
try {
return new URL(url).hostname.replace(/^www\./, '');
} catch {
return '';
}
}
function attachCopyButtons() {
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.removeEventListener('click', copyHandler);
btn.addEventListener('click', copyHandler);
});
}
async function copyHandler(e) {
e.stopPropagation();
const url = this.getAttribute('data-url');
if (url) {
await navigator.clipboard.writeText(url);
const original = this.innerHTML;
this.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 6L9 17l-5-5"/></svg>';
setTimeout(() => this.innerHTML = original, 1500);
}
}
function attachCheckboxListeners() {
document.querySelectorAll('.rss-checkbox').forEach(cb => {
cb.removeEventListener('change', onCheckboxChange);
cb.addEventListener('change', onCheckboxChange);
});
}
function onCheckboxChange(e) {
e.stopPropagation();
const rss = e.target.getAttribute('data-rss');
if (e.target.checked) {
selectedSet.add(rss);
} else {
selectedSet.delete(rss);
}
updateSelectedCount();
}
function updateSelectedCount() {
const count = selectedSet.size;
const countSpan = selectedCountSpan.querySelector('span');
if (countSpan) countSpan.textContent = count;
document.querySelectorAll('.rss-checkbox').forEach(cb => {
const rss = cb.getAttribute('data-rss');
cb.checked = selectedSet.has(rss);
});
}
function selectAll() {
let itemsToSelect = [...allRssItems];
if (currentCategory) {
itemsToSelect = itemsToSelect.filter(item => item.category === currentCategory);
}
if (currentSearchTerm) {
itemsToSelect = itemsToSelect.filter(item =>
item.siteName.toLowerCase().includes(currentSearchTerm) ||
item.rssLink.toLowerCase().includes(currentSearchTerm)
);
}
itemsToSelect.forEach(item => selectedSet.add(item.rssLink));
updateSelectedCount();
renderList();
}
function clearSelection() {
selectedSet.clear();
updateSelectedCount();
renderList();
}
function buildOPML() {
if (selectedSet.size === 0) {
alert('Dışa aktarmak için en az bir RSS kaynağı seçin.');
return null;
}
const categoryMap = new Map();
selectedSet.forEach(rss => {
const item = allRssItems.find(it => it.rssLink === rss);
if (item) {
if (!categoryMap.has(item.category)) categoryMap.set(item.category, []);
categoryMap.get(item.category).push(item);
}
});
let outlines = [];
for (const [category, items] of categoryMap) {
const subOutlines = items.map(item =>
`<outline type="rss" text="${escapeXml(item.siteName)}" title="${escapeXml(item.siteName)}" xmlUrl="${escapeXml(item.rssLink)}"/>`
).join('\n ');
outlines.push(`<outline text="${escapeXml(category)}" title="${escapeXml(category)}">\n ${subOutlines}\n </outline>`);
}
return `<?xml version="1.0" encoding="UTF-8"?>\n<opml version="1.0">\n <head>\n <title>RSS Bağlantıları - Seçili Kaynaklar</title>\n </head>\n <body>\n ${outlines.join('\n ')}\n </body>\n</opml>`;
}
function exportOPML() {
const opml = buildOPML();
if (!opml) return;
const blob = new Blob([opml], { type: 'text/xml' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const now = new Date();
a.href = url;
a.download = `rss-${now.getFullYear()}${String(now.getMonth()+1).padStart(2,'0')}${String(now.getDate()).padStart(2,'0')}.opml`;
a.click();
URL.revokeObjectURL(url);
}
selectAllBtn?.addEventListener('click', (e) => {
e.preventDefault();
selectAll();
});
clearSelectionBtn?.addEventListener('click', (e) => {
e.preventDefault();
clearSelection();
});
exportBtn?.addEventListener('click', (e) => {
e.preventDefault();
exportOPML();
});
function escapeHtml(str) {
return String(str).replace(/[&<>]/g, m => m === '&' ? '&' : m === '<' ? '<' : '>');
}
function escapeXml(s) {
return String(s).replace(/[&<>]/g, m => m === '&' ? '&' : m === '<' ? '<' : '>');
}
fetch(rawMdUrl)
.then(res => res.text())
.then(md => {
const categoryRegex = /#\s+([^\n]+)\n\n\| Site Adı \| RSS Bağlantısı \|\n\|:-------- \| -----------:\|\n([\s\S]+?)(?=\n# |$)/g;
let match;
while ((match = categoryRegex.exec(md)) !== null) {
const category = match[1].trim();
const tableContent = match[2].trim();
const items = tableContent.split('\n').map(line => {
const parts = line.split('|').map(p => p.trim());
if (parts.length === 4 && parts[0] === '' && parts[3] === '') {
return { siteName: parts[1], rssLink: parts[2], category };
}
return null;
}).filter(item => item !== null);
if (items.length > 0) {
categories.push(category);
allRssItems.push(...items);
}
}
totalCountSpan.textContent = allRssItems.length;
buildChips();
renderList();
setupScrollObserver();
const urlParams = new URLSearchParams(window.location.search);
const searchQuery = urlParams.get('q');
if (searchQuery) {
searchInput.value = searchQuery;
currentSearchTerm = searchQuery;
renderList();
}
})
.catch(err => {
output.innerHTML = `<div class="no-results"><p>Veri yüklenemedi: ${err.message}</p><small>Lütfen daha sonra tekrar deneyin.</small></div>`;
console.error('Fetch error:', err);
});
const scrollTopBtn = document.getElementById('scrollTopBtn');
if (scrollTopBtn) {
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
scrollTopBtn.classList.add('visible');
} else {
scrollTopBtn.classList.remove('visible');
}
}, { passive: true });
scrollTopBtn.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
});