flitrx commited on
Commit
79f78e8
·
verified ·
1 Parent(s): 66a1967

make this into a fully functional dark web scraper without any "simulated" code - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +132 -100
index.html CHANGED
@@ -402,6 +402,8 @@
402
  // State
403
  let isTorConnected = false;
404
  let searchInProgress = false;
 
 
405
 
406
  // Event Listeners
407
  torCheckBtn.addEventListener('click', checkTorConnection);
@@ -415,23 +417,27 @@
415
  closeHelpBtn.addEventListener('click', () => helpModal.classList.add('hidden'));
416
  closeHelpBtn2.addEventListener('click', () => helpModal.classList.add('hidden'));
417
  cancelSettingsBtn.addEventListener('click', () => settingsModal.classList.add('hidden'));
418
- saveSettingsBtn.addEventListener('click', () => {
419
- settingsModal.classList.add('hidden');
420
- // In a real app, you would save settings here
421
- });
422
 
423
  // Functions
424
- function checkTorConnection() {
425
- // In a real app, this would make an API call to check Tor status
426
- // For demo purposes, we'll simulate it with a random result
427
-
428
  torCheckBtn.disabled = true;
429
  torCheckBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Checking...';
430
 
431
- // Simulate network delay
432
- setTimeout(() => {
433
- // Randomly determine if Tor is connected (70% chance for demo)
434
- isTorConnected = Math.random() > 0.3;
 
 
 
 
 
 
 
 
 
 
435
 
436
  if (isTorConnected) {
437
  torStatus.className = 'px-3 py-1 rounded-full text-xs font-medium flex items-center space-x-1 bg-neon-green/20 text-neon-green';
@@ -442,14 +448,20 @@
442
  torStatus.innerHTML = '<span class="w-2 h-2 rounded-full bg-red-500"></span><span>Tor Disconnected</span>';
443
  torWarning.classList.remove('hidden');
444
  }
445
-
446
- torStatus.classList.remove('hidden');
447
- torCheckBtn.disabled = false;
448
- torCheckBtn.innerHTML = '<span class="text-sm font-medium">Check Tor Connection</span><i class="fas fa-shield-alt ml-2"></i>';
449
- }, 1500);
 
 
 
 
 
 
450
  }
451
 
452
- function startSearch() {
453
  if (searchInProgress) return;
454
 
455
  if (!isTorConnected) {
@@ -468,104 +480,124 @@
468
  resultsContainer.innerHTML = '';
469
  resultCount.textContent = '0';
470
  searchBtn.disabled = true;
471
- searchBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Searching';
472
 
473
- // Simulate scraping delay
474
- setTimeout(() => {
475
- // Generate random number of results (0-15)
476
- const resultCountNum = Math.floor(Math.random() * 16);
477
- resultCount.textContent = resultCountNum;
 
 
 
 
 
 
 
 
 
478
 
479
- if (resultCountNum === 0) {
480
  noResults.classList.remove('hidden');
 
 
 
 
 
 
 
 
481
  } else {
482
- // Add sample results
483
- for (let i = 0; i < resultCountNum; i++) {
484
- const result = document.createElement('div');
485
- result.className = 'result-card bg-dark-800 rounded-lg p-4 hover:bg-dark-700 transition-colors';
486
- result.innerHTML = `
487
- <div class="flex items-start justify-between">
488
- <div>
489
- <h4 class="font-medium text-white mb-1">${generateRandomTitle()}</h4>
490
- <p class="text-xs text-neon-blue mb-2">${generateRandomOnionUrl()}</p>
491
- <p class="text-sm text-gray-300 line-clamp-2">${generateRandomContent()}</p>
492
- </div>
493
- <div class="flex space-x-2">
494
- <button class="p-1 text-gray-400 hover:text-neon-blue">
495
- <i class="fas fa-external-link-alt"></i>
496
- </button>
497
- <button class="p-1 text-gray-400 hover:text-neon-purple">
498
- <i class="fas fa-bookmark"></i>
499
- </button>
500
- </div>
501
- </div>
502
- <div class="mt-3 pt-2 border-t border-dark-700 flex items-center justify-between">
503
- <div class="flex space-x-3 text-xs text-gray-400">
504
- <span class="flex items-center space-x-1">
505
- <i class="fas fa-calendar-alt"></i>
506
- <span>${getRandomDate()}</span>
507
- </span>
508
- <span class="flex items-center space-x-1">
509
- <i class="fas fa-tag"></i>
510
- <span>${getRandomTag()}</span>
511
- </span>
512
- </div>
513
- ${Math.random() > 0.7 ? '<div class="text-xs text-neon-green"><span class="px-2 py-1 bg-neon-green/10 rounded">Verified</span></div>' : ''}
514
- </div>
515
- `;
516
- resultsContainer.appendChild(result);
517
- }
518
  }
519
-
520
- loadingIndicator.classList.add('hidden');
521
- searchInProgress = false;
522
- searchBtn.disabled = false;
523
- searchBtn.innerHTML = '<i class="fas fa-search mr-2"></i> Search';
524
- }, 3000);
525
- }
526
-
527
- // Helper functions for demo data
528
- function generateRandomTitle() {
529
- const prefixes = ['Dark', 'Hidden', 'Secret', 'Private', 'Anonymous', 'Secure'];
530
- const nouns = ['Market', 'Forum', 'Library', 'Archive', 'Hub', 'Network', 'Service'];
531
- return `${prefixes[Math.floor(Math.random() * prefixes.length)]} ${nouns[Math.floor(Math.random() * nouns.length)]}`;
 
532
  }
533
 
534
- function generateRandomOnionUrl() {
535
- const chars = 'abcdefghijklmnopqrstuvwxyz234567';
536
- let url = 'http://';
537
- for (let i = 0; i < 16; i++) {
538
- url += chars[Math.floor(Math.random() * chars.length)];
539
- }
540
- return url + '.onion';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
  }
542
 
543
- function generateRandomContent() {
544
- const sentences = [
545
- "This is a sample result from the dark web. The content would vary depending on the site being scraped.",
546
- "Marketplace offering various goods and services. Use with caution and verify all transactions.",
547
- "Discussion forum covering topics from technology to privacy and security.",
548
- "Archive of documents and information not available on the regular internet.",
549
- "Service providing anonymous communication channels for secure messaging.",
550
- "Repository of tools and resources for maintaining online privacy and anonymity."
551
- ];
552
- return sentences[Math.floor(Math.random() * sentences.length)];
553
  }
554
 
555
- function getRandomDate() {
556
- const start = new Date(2022, 0, 1);
557
- const end = new Date();
558
- const date = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
559
- return date.toISOString().split('T')[0];
560
  }
561
 
562
- function getRandomTag() {
563
- const tags = ['Marketplace', 'Forum', 'Library', 'Service', 'Blog', 'News'];
564
- return tags[Math.floor(Math.random() * tags.length)];
 
 
 
 
 
 
 
 
 
 
565
  }
566
 
567
  // Initialize with Tor check
568
- checkTorConnection();
569
  </script>
570
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=flitrx/dws2" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
571
  </html>
 
402
  // State
403
  let isTorConnected = false;
404
  let searchInProgress = false;
405
+ let torHost = '127.0.0.1';
406
+ let torPort = '9050';
407
 
408
  // Event Listeners
409
  torCheckBtn.addEventListener('click', checkTorConnection);
 
417
  closeHelpBtn.addEventListener('click', () => helpModal.classList.add('hidden'));
418
  closeHelpBtn2.addEventListener('click', () => helpModal.classList.add('hidden'));
419
  cancelSettingsBtn.addEventListener('click', () => settingsModal.classList.add('hidden'));
420
+ saveSettingsBtn.addEventListener('click', saveSettings);
 
 
 
421
 
422
  // Functions
423
+ async function checkTorConnection() {
 
 
 
424
  torCheckBtn.disabled = true;
425
  torCheckBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Checking...';
426
 
427
+ try {
428
+ const response = await fetch('/check-tor', {
429
+ method: 'POST',
430
+ headers: {
431
+ 'Content-Type': 'application/json'
432
+ },
433
+ body: JSON.stringify({
434
+ host: torHost,
435
+ port: torPort
436
+ })
437
+ });
438
+
439
+ const data = await response.json();
440
+ isTorConnected = data.connected;
441
 
442
  if (isTorConnected) {
443
  torStatus.className = 'px-3 py-1 rounded-full text-xs font-medium flex items-center space-x-1 bg-neon-green/20 text-neon-green';
 
448
  torStatus.innerHTML = '<span class="w-2 h-2 rounded-full bg-red-500"></span><span>Tor Disconnected</span>';
449
  torWarning.classList.remove('hidden');
450
  }
451
+ } catch (error) {
452
+ console.error('Tor check failed:', error);
453
+ isTorConnected = false;
454
+ torStatus.className = 'px-3 py-1 rounded-full text-xs font-medium flex items-center space-x-1 bg-red-500/20 text-red-500';
455
+ torStatus.innerHTML = '<span class="w-2 h-2 rounded-full bg-red-500"></span><span>Connection Error</span>';
456
+ torWarning.classList.remove('hidden');
457
+ }
458
+
459
+ torStatus.classList.remove('hidden');
460
+ torCheckBtn.disabled = false;
461
+ torCheckBtn.innerHTML = '<span class="text-sm font-medium">Check Tor Connection</span><i class="fas fa-shield-alt ml-2"></i>';
462
  }
463
 
464
+ async function startSearch() {
465
  if (searchInProgress) return;
466
 
467
  if (!isTorConnected) {
 
480
  resultsContainer.innerHTML = '';
481
  resultCount.textContent = '0';
482
  searchBtn.disabled = true;
483
+ searchBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Scraping';
484
 
485
+ try {
486
+ const response = await fetch('/scrape', {
487
+ method: 'POST',
488
+ headers: {
489
+ 'Content-Type': 'application/json'
490
+ },
491
+ body: JSON.stringify({
492
+ url: query,
493
+ host: torHost,
494
+ port: torPort
495
+ })
496
+ });
497
+
498
+ const data = await response.json();
499
 
500
+ if (data.error) {
501
  noResults.classList.remove('hidden');
502
+ noResults.innerHTML = `
503
+ <i class="fas fa-exclamation-triangle text-4xl text-red-500 mb-4"></i>
504
+ <h4 class="text-lg font-medium text-red-400">Scraping Error</h4>
505
+ <p class="text-gray-500 mt-2">${data.error}</p>
506
+ `;
507
+ } else if (data.results && data.results.length > 0) {
508
+ resultCount.textContent = data.results.length;
509
+ displayResults(data.results);
510
  } else {
511
+ noResults.classList.remove('hidden');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  }
513
+ } catch (error) {
514
+ console.error('Search failed:', error);
515
+ noResults.classList.remove('hidden');
516
+ noResults.innerHTML = `
517
+ <i class="fas fa-exclamation-triangle text-4xl text-red-500 mb-4"></i>
518
+ <h4 class="text-lg font-medium text-red-400">Connection Error</h4>
519
+ <p class="text-gray-500 mt-2">Failed to connect to the dark web site. Please check your Tor connection.</p>
520
+ `;
521
+ }
522
+
523
+ loadingIndicator.classList.add('hidden');
524
+ searchInProgress = false;
525
+ searchBtn.disabled = false;
526
+ searchBtn.innerHTML = '<i class="fas fa-search mr-2"></i> Search';
527
  }
528
 
529
+ function displayResults(results) {
530
+ resultsContainer.innerHTML = '';
531
+
532
+ results.forEach(result => {
533
+ const resultElement = document.createElement('div');
534
+ resultElement.className = 'result-card bg-dark-800 rounded-lg p-4 hover:bg-dark-700 transition-colors';
535
+ resultElement.innerHTML = `
536
+ <div class="flex items-start justify-between">
537
+ <div class="flex-1">
538
+ <h4 class="font-medium text-white mb-1">${escapeHtml(result.title || 'Untitled')}</h4>
539
+ <p class="text-xs text-neon-blue mb-2">${escapeHtml(result.url)}</p>
540
+ <p class="text-sm text-gray-300">${escapeHtml(result.description || 'No description available')}</p>
541
+ </div>
542
+ <div class="flex space-x-2 ml-4">
543
+ <button class="p-1 text-gray-400 hover:text-neon-blue" onclick="openInNewTab('${escapeHtml(result.url)}')">
544
+ <i class="fas fa-external-link-alt"></i>
545
+ </button>
546
+ <button class="p-1 text-gray-400 hover:text-neon-purple">
547
+ <i class="fas fa-bookmark"></i>
548
+ </button>
549
+ </div>
550
+ </div>
551
+ <div class="mt-3 pt-2 border-t border-dark-700 flex items-center justify-between">
552
+ <div class="flex space-x-3 text-xs text-gray-400">
553
+ <span class="flex items-center space-x-1">
554
+ <i class="fas fa-calendar-alt"></i>
555
+ <span>${new Date().toISOString().split('T')[0]}</span>
556
+ </span>
557
+ <span class="flex items-center space-x-1">
558
+ <i class="fas fa-tag"></i>
559
+ <span>${result.type || 'Unknown'}</span>
560
+ </span>
561
+ </div>
562
+ ${result.verified ? '<div class="text-xs text-neon-green"><span class="px-2 py-1 bg-neon-green/10 rounded">Verified</span></div>' : ''}
563
+ </div>
564
+ `;
565
+ resultsContainer.appendChild(resultElement);
566
+ });
567
  }
568
 
569
+ function escapeHtml(unsafe) {
570
+ if (!unsafe) return '';
571
+ return unsafe
572
+ .toString()
573
+ .replace(/&/g, "&amp;")
574
+ .replace(/</g, "&lt;")
575
+ .replace(/>/g, "&gt;")
576
+ .replace(/"/g, "&quot;")
577
+ .replace(/'/g, "&#039;");
 
578
  }
579
 
580
+ function openInNewTab(url) {
581
+ window.open(url, '_blank');
 
 
 
582
  }
583
 
584
+ function saveSettings() {
585
+ // Get settings from modal inputs
586
+ const hostInput = document.querySelector('#settingsModal input[type="text"]:nth-child(1)');
587
+ const portInput = document.querySelector('#settingsModal input[type="text"]:nth-child(2)');
588
+
589
+ if (hostInput && portInput) {
590
+ torHost = hostInput.value;
591
+ torPort = portInput.value;
592
+ }
593
+
594
+ settingsModal.classList.add('hidden');
595
+ // Re-check connection with new settings
596
+ checkTorConnection();
597
  }
598
 
599
  // Initialize with Tor check
600
+ window.addEventListener('DOMContentLoaded', checkTorConnection);
601
  </script>
602
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=flitrx/dws2" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
603
  </html>