|
1 |
| -document.addEventListener('DOMContentLoaded', () => { |
2 |
| - const terminalInput = document.getElementById('terminal-input'); |
3 |
| - const terminalContent = document.getElementById('terminal-content'); |
4 |
| - const searchForm = document.getElementById('search-form'); |
5 |
| - const searchInput = document.getElementById('search-input'); |
6 |
| - const searchResults = document.getElementById('search-results'); |
| 1 | +document.addEventListener("DOMContentLoaded", function () { |
| 2 | + const commandInput = document.getElementById("command-input"); |
| 3 | + const output = document.getElementById("output"); |
7 | 4 |
|
8 |
| - terminalInput.addEventListener('keypress', (e) => { |
9 |
| - if (e.key === 'Enter') { |
10 |
| - const command = terminalInput.value.trim(); |
| 5 | + // Fetch user's location and country via Geolocation API |
| 6 | + function getUserLocation() { |
| 7 | + if (navigator.geolocation) { |
| 8 | + navigator.geolocation.getCurrentPosition(function (position) { |
| 9 | + const latitude = position.coords.latitude; |
| 10 | + const longitude = position.coords.longitude; |
| 11 | + |
| 12 | + // Use reverse geocoding API to fetch country name |
| 13 | + fetch(`https://api.bigdatacloud.net/data/reverse-geocode-client?latitude=${latitude}&longitude=${longitude}&localityLanguage=en`) |
| 14 | + .then(response => response.json()) |
| 15 | + .then(data => { |
| 16 | + printOutput(`Your location: ${data.city || "Unknown City"}, ${data.countryName}`); |
| 17 | + }) |
| 18 | + .catch(error => { |
| 19 | + printOutput(`<span class="red">Could not fetch location.</span>`); |
| 20 | + }); |
| 21 | + }); |
| 22 | + } else { |
| 23 | + printOutput(`<span class="red">Geolocation is not supported by this browser.</span>`); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + getUserLocation(); |
| 28 | + |
| 29 | + commandInput.addEventListener("keypress", function (event) { |
| 30 | + if (event.key === "Enter") { |
| 31 | + event.preventDefault(); |
| 32 | + const command = commandInput.value.trim(); |
11 | 33 | executeCommand(command);
|
12 |
| - terminalInput.value = ''; |
| 34 | + commandInput.value = ""; |
13 | 35 | }
|
14 | 36 | });
|
15 | 37 |
|
16 | 38 | function executeCommand(command) {
|
17 |
| - if (command) { |
18 |
| - const commandElement = document.createElement('div'); |
19 |
| - commandElement.textContent = `> ${command}`; |
20 |
| - terminalContent.appendChild(commandElement); |
21 |
| - |
22 |
| - // Simulate response |
23 |
| - const responseElement = document.createElement('div'); |
24 |
| - responseElement.textContent = getResponseForCommand(command); |
25 |
| - terminalContent.appendChild(responseElement); |
| 39 | + printOutput(`<span class="prompt">guest@cyber-linux:~$</span> ${command}`); |
26 | 40 |
|
27 |
| - terminalContent.scrollTop = terminalContent.scrollHeight; |
| 41 | + if (command === "help") { |
| 42 | + printOutput(` |
| 43 | + Available commands: |
| 44 | + - github user <username> (Find GitHub user) |
| 45 | + - github repo <repo-name> (Find repositories) |
| 46 | + - github commit <keyword> (Search commits) |
| 47 | + - github issue <keyword> (Find issues/pull requests) |
| 48 | + - github code <keyword> (Search code) |
| 49 | + - github org <org-name> (Find organizations) |
| 50 | + - google dork <dork> (Google dorking search) |
| 51 | + - ls (List directories) |
| 52 | + - pwd (Show current path) |
| 53 | + - whoami (Show user) |
| 54 | + - clear (Clear terminal) |
| 55 | + - about (Go to GitHub portfolio) |
| 56 | + `); |
| 57 | + } else if (command.startsWith("github user ")) { |
| 58 | + fetchGitHubUser(command.split(" ")[2]); |
| 59 | + } else if (command.startsWith("github repo ")) { |
| 60 | + fetchGitHubRepo(command.split(" ")[2]); |
| 61 | + } else if (command.startsWith("google dork ")) { |
| 62 | + googleDork(command.substring(13)); |
| 63 | + } else if (command === "about") { |
| 64 | + window.location.href = "https://github.com/jusot99"; |
| 65 | + } else if (command === "clear") { |
| 66 | + output.innerHTML = ""; |
| 67 | + } else if (command === "ls") { |
| 68 | + printOutput("Documents Downloads Pictures Projects CyberLinux"); |
| 69 | + } else if (command === "pwd") { |
| 70 | + printOutput("/home/guest"); |
| 71 | + } else if (command === "whoami") { |
| 72 | + printOutput("guest"); |
| 73 | + } else { |
| 74 | + printOutput(`<span class="red">${command}: command not found.</span>`); |
28 | 75 | }
|
29 | 76 | }
|
30 | 77 |
|
31 |
| - function getResponseForCommand(command) { |
32 |
| - switch (command.toLowerCase()) { |
33 |
| - case 'help': |
34 |
| - return 'Available commands: help, about, clear'; |
35 |
| - case 'about': |
36 |
| - return 'Hacker Portal - The Ultimate Hacker Experience'; |
37 |
| - case 'clear': |
38 |
| - terminalContent.innerHTML = ''; |
39 |
| - return ''; |
40 |
| - default: |
41 |
| - return `Command not found: ${command}`; |
42 |
| - } |
| 78 | + function fetchGitHubUser(username) { |
| 79 | + fetch(`https://api.github.com/users/${username}`) |
| 80 | + .then(response => response.json()) |
| 81 | + .then(data => { |
| 82 | + if (data.message === "Not Found") { |
| 83 | + printOutput(`<span class="red">User '${username}' not found.</span>`); |
| 84 | + return; |
| 85 | + } |
| 86 | + printOutput(` |
| 87 | + <div><img src="${data.avatar_url}" class="avatar" alt="Avatar">Username: ${data.login}</div> |
| 88 | + <div>Name: ${data.name || "N/A"}</div> |
| 89 | + <div>Bio: ${data.bio || "No bio available"}</div> |
| 90 | + <div>Location: ${data.location || "N/A"}</div> |
| 91 | + <div>Followers: ${data.followers}</div> |
| 92 | + <div>Following: ${data.following}</div> |
| 93 | + <div>Repositories: ${data.public_repos}</div> |
| 94 | + <div>Profile: <a href="${data.html_url}" target="_blank">${data.html_url}</a></div> |
| 95 | + `); |
| 96 | + }); |
43 | 97 | }
|
44 | 98 |
|
45 |
| - searchForm.addEventListener('submit', (e) => { |
46 |
| - e.preventDefault(); |
47 |
| - const query = searchInput.value.trim(); |
48 |
| - if (query) { |
49 |
| - searchGitHub(query); |
50 |
| - } |
51 |
| - }); |
52 |
| - |
53 |
| - function searchGitHub(query) { |
54 |
| - fetch(`https://api.github.com/search/users?q=${query}`) |
| 99 | + function fetchGitHubRepo(repo) { |
| 100 | + fetch(`https://api.github.com/search/repositories?q=${repo}`) |
55 | 101 | .then(response => response.json())
|
56 | 102 | .then(data => {
|
57 |
| - displaySearchResults(data.items); |
58 |
| - }) |
59 |
| - .catch(error => { |
60 |
| - console.error('Error fetching GitHub users:', error); |
61 |
| - searchResults.innerHTML = '<p>Error fetching GitHub users.</p>'; |
| 103 | + if (data.items.length === 0) { |
| 104 | + printOutput(`<span class="red">No repositories found for '${repo}'.</span>`); |
| 105 | + return; |
| 106 | + } |
| 107 | + printOutput(` |
| 108 | + <div>Repositories found: ${data.items.length}</div> |
| 109 | + <div>First Repo: <a href="${data.items[0].html_url}" target="_blank">${data.items[0].full_name}</a></div> |
| 110 | + `); |
62 | 111 | });
|
63 | 112 | }
|
64 | 113 |
|
65 |
| - function displaySearchResults(users) { |
66 |
| - searchResults.innerHTML = ''; |
67 |
| - if (users.length === 0) { |
68 |
| - searchResults.innerHTML = '<p>No users found.</p>'; |
69 |
| - } else { |
70 |
| - users.forEach(user => { |
71 |
| - fetch(user.url) |
72 |
| - .then(response => response.json()) |
73 |
| - .then(userData => { |
74 |
| - const userName = userData.name ? userData.name : 'N/A'; |
75 |
| - const userBio = userData.bio ? `<p>${userData.bio}</p>` : ''; |
76 |
| - const userCard = ` |
77 |
| - <div class="card"> |
78 |
| - <div> |
79 |
| - <a href="${userData.html_url}" target="_blank"> |
80 |
| - <img src="${userData.avatar_url}" alt="${userData.name}" class="avatar"> |
81 |
| - </a> |
82 |
| - </div> |
83 |
| - <div class="user-info"> |
84 |
| - <h2>${userData.login}</h2> |
85 |
| - <h3>${userName}</h3> |
86 |
| - ${userBio} |
87 |
| - <ul> |
88 |
| - <li>${userData.followers} <strong>Followers</strong></li> |
89 |
| - <li>${userData.following} <strong>Following</strong></li> |
90 |
| - <li>${userData.public_repos} <strong>Repos</strong></li> |
91 |
| - </ul> |
92 |
| - </div> |
93 |
| - </div> |
94 |
| - `; |
95 |
| - searchResults.innerHTML += userCard; |
96 |
| - }); |
97 |
| - }); |
98 |
| - } |
| 114 | + function googleDork(query) { |
| 115 | + const googleSearch = `https://www.google.com/search?q=${encodeURIComponent(query)}`; |
| 116 | + printOutput(`Searching Google Dork: ${query}\n[Click here]( ${googleSearch} )`); |
| 117 | + window.open(googleSearch, "_blank"); |
| 118 | + } |
| 119 | + |
| 120 | + function printOutput(text) { |
| 121 | + output.innerHTML += `<p>${text}</p>`; |
| 122 | + output.scrollTop = output.scrollHeight; |
99 | 123 | }
|
100 | 124 | });
|
0 commit comments