-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
380 lines (327 loc) · 13.3 KB
/
Copy pathscript.js
File metadata and controls
380 lines (327 loc) · 13.3 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
function notify(message, type){
notificationElement = `
<div class="notification ${type}">
<h2>${message}</h2>
</div>
`
notificationDiv = document.createElement("div")
notificationDiv.innerHTML = notificationElement
document.body.appendChild(notificationDiv)
setTimeout(() => {
document.body.removeChild(notificationDiv)
}, 3000)
}
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyClJtSEK7wybjP6Cqs3MGu1euVA3rasJ9Y",
authDomain: "swiftlybackend.firebaseapp.com",
projectId: "swiftlybackend",
storageBucket: "swiftlybackend.appspot.com",
messagingSenderId: "379805934715",
appId: "1:379805934715:web:7c03cf61061057297aeede"
};
// Initialize Firebase
const app = firebase.initializeApp(firebaseConfig);
// Initialize Firebase Auth and Firestore
const auth = firebase.auth();
const db = firebase.firestore();
let mainEmail;
const provider = new firebase.auth.GithubAuthProvider();
provider.addScope('user:email'); // This requests the user's email from GitHub.
function handleGitHubSignIn() {
auth.signInWithPopup(provider)
.then((result) => {
const token = result.credential.accessToken;
fetch('https://api.github.com/user/emails', {
headers: {
'Authorization': `token ${token}`
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(emails => {
const primaryEmail = emails.find(email => email.primary).email;
mainEmail = primaryEmail;
return fetch('https://api.github.com/user', {
headers: {
'Authorization': `token ${token}`
}
});
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(userData => {
const githubUrl = userData.html_url;
saveUserEmailToWaitlist(result.user.uid, mainEmail, githubUrl);
})
.catch((error) => {
console.error('Error fetching data from GitHub:', error);
notify("Error fetching data :(", "warning");
});
})
.catch((error) => {
console.error('Error during GitHub sign-in:', error);
notify("Error during sign in :(", "warning");
});
}
auth.getRedirectResult().then((result) => {
if (result.credential) {
// This gives you a GitHub Access Token.
const token = result.credential.accessToken;
// Use token to fetch the user's profile information from GitHub.
fetch('https://api.github.com/user/emails', {
headers: {
'Authorization': `token ${token}`
}
})
.then(response => response.json())
.then(emails => {
// The user's primary email address is the one marked as 'primary'.
const primaryEmail = emails.find(email => email.primary).email;
// Call the function to save the email to Firestore.
saveUserEmailToWaitlist(result.user.uid, primaryEmail);
})
.catch((error) => {
console.error('Error fetching user email from GitHub:', error);
notify("Error fetching user email :(", "warning")
});
}
}).catch((error) => {
// Handle errors
console.error('Error during GitHub redirect sign-in:', error);
notify("Error with github sign in :(", "warning")
});
document.addEventListener('DOMContentLoaded', function() {
const signInButton = document.getElementById('github-signin');
if (signInButton) {
signInButton.addEventListener('click', handleGitHubSignIn);
}
});
document.addEventListener('DOMContentLoaded', function() {
const signInButton = document.getElementById('github-signin');
signInButton.addEventListener('click', handleGitHubSignIn);
});
function addedToWaitlistFunc(){
document.querySelector(".github_signin").classList.add("signedIn")
document.querySelector(".github_signin").innerHTML = "Joined Waitlist :)"
}
function saveUserEmailToWaitlist(userId, email, githubUrl) {
// Assuming your collection is named 'waitlist'
db.collection('waitlist').doc(userId).set({
Email: email,
GitHubUrl: githubUrl,
Approved: false, // Set to false by default, as per your Firestore screenshot
Timestamp: firebase.firestore.FieldValue.serverTimestamp() // Add this line for timestamp
})
.then(() => {
console.log('User email added to waitlist with timestamp!');
notify("Email added to waitlist!", "success");
// Set initial values
localStorage.setItem('addedToWaitlist', 'True');
localStorage.setItem('approved', 'False');
addedToWaitlistFunc();
})
.catch((error) => {
console.error('Error adding user to waitlist: ', error);
notify("Some error occured, please try again.", "warning");
// Handle any errors here, such as showing a message to the user
});
}
// Get values
var addedToWaitlist = localStorage.getItem('addedToWaitlist');
var approved = localStorage.getItem('approved');
document.addEventListener("DOMContentLoaded", function() {
// Parses the query string and returns an object of parameters
function getQueryParams() {
var queryParams = {};
var queryString = window.location.search.substring(1);
var queryParamsArray = queryString.split('&');
for (var i = 0; i < queryParamsArray.length; i++) {
var pair = queryParamsArray[i].split('=');
queryParams[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
return queryParams;
}
// Get the query parameters
var params = getQueryParams();
// Check if 'approved' is 'true'
if (params.approved === "true") {
localStorage.setItem('approved', 'True');
window.location.replace("https://www.goodgit.io/approved.html");
}
});
if (addedToWaitlist == 'True'){
addedToWaitlistFunc()
}
if (approved == 'True'){
window.location.replace("https://www.goodgit.io/approved.html");
}
function copyFeedback(event) {
let copyElement = event.target;
let rect = copyElement.getBoundingClientRect();
let copiedText = document.createElement('div');
copiedText.innerHTML = "Copied";
copiedText.classList.add('copied');
copiedText.style.left = rect.left + "px";
copiedText.style.top = rect.top + "px";
document.body.appendChild(copiedText);
setTimeout(() => {
copiedText.style.opacity = 0;
}, 100); // Initiate fade-out right away
setTimeout(() => {
document.body.removeChild(copiedText);
}, 1000); // Remove after fade-out
}
document.querySelectorAll('.copy').forEach(button => {
button.addEventListener('click', () => {
let siblingTextElement = [...button.parentNode.children].find(child => child.classList.contains('text'));
if (siblingTextElement) {
let span = siblingTextElement.querySelector('span');
if (span) {
navigator.clipboard.writeText(span.innerText)
.then(() => console.log('Text copied!'))
.catch(err => console.error('Error in copying text: ', err));
} else {
console.error('No span element found.');
}
} else {
console.error('No sibling .text element found.');
}
});
});
let tabs = document.querySelectorAll(".tab")
let allTerminals = document.querySelectorAll(".terminalContent")
let terminalAi = document.querySelector(".terminalContentAi")
let terminalSsh = document.querySelector(".terminalContentSsh")
let terminalTt = document.querySelector(".terminalContentTt")
let terminalMa = document.querySelector(".terminalContentMa")
let terminalMore = document.querySelector(".terminalContentMore")
tabs.forEach((tab) => {
tab.addEventListener("click", () => {
document.querySelector(".activeTab").classList.remove("activeTab")
tab.classList.add("activeTab")
let dataValue = tab.getAttribute("value")
if (dataValue == "AiCommits"){
allTerminals.forEach((allTerminal) => {
allTerminal.classList.remove('activeTerminal')
terminalAi.classList.add("activeTerminal")
})
}
else if (dataValue == "ssh"){
allTerminals.forEach((allTerminal) => {
allTerminal.classList.remove('activeTerminal')
terminalSsh.classList.add("activeTerminal")
})
}
else if (dataValue == "tt"){
allTerminals.forEach((allTerminal) => {
allTerminal.classList.remove('activeTerminal')
terminalTt.classList.add("activeTerminal")
})
}
else if (dataValue == "ma"){
allTerminals.forEach((allTerminal) => {
allTerminal.classList.remove('activeTerminal')
terminalMa.classList.add("activeTerminal")
})
}
else if (dataValue == "more"){
allTerminals.forEach((allTerminal) => {
allTerminal.classList.remove('activeTerminal')
terminalMore.classList.add("activeTerminal")
})
}
})
})
// terminal
// let inputContent = `
// <svg class="terminal_cursor" width="15" height="9" viewBox="0 0 15 9" fill="none" xmlns="http://www.w3.org/2000/svg">
// <rect width="3" height="3" fill="#AAAAAA"/>
// <rect x="3" y="3" width="3" height="3" fill="#AAAAAA"/>
// <rect y="6" width="3" height="3" fill="#AAAAAA"/>
// <rect x="9" y="6" width="3" height="3" fill="#AAAAAA"/>
// <rect x="12" y="6" width="3" height="3" fill="#AAAAAA"/>
// </svg>
// <input type="text" autofocus class="terminal_input">
// `
// document.addEventListener("DOMContentLoaded", () => {
// let terminal = document.querySelector(".terminal");
// let terminalInput = document.querySelector(".terminal_input");
// // Function to display output in the terminal
// function displayOutput(message) {
// let output = document.createElement("h3");
// output.innerHTML = message;
// output.classList.add("output");
// terminal.appendChild(output);
// }
// // Function to simulate pressing Enter
// function simulateEnterKeyPress() {
// const enterEvent = new KeyboardEvent('keydown', {
// key: 'Enter',
// code: 'Enter',
// which: 13,
// keyCode: 13,
// });
// terminalInput.dispatchEvent(enterEvent);
// }
// // Function to simulate typing each character
// function typeCharacterByCharacter(text, index = 0, callback) {
// if (index < text.length) {
// terminalInput.value += text[index];
// setTimeout(() => typeCharacterByCharacter(text, index + 1, callback), 100); // Adjust 100ms for typing speed
// } else if (callback) {
// callback();
// }
// }
// // Set up the keypress event listener
// terminal.addEventListener("keypress", function(event) {
// terminalInput = event.target; // Update the terminalInput to the current active input
// if (terminalInput.classList.contains('terminal_input') && event.key === "Enter") {
// event.preventDefault();
// let command = terminalInput.value.trim().toLowerCase(); // Get and trim the input value, make it lowercase
// switch(command) {
// case 'gg':
// // Handle 'gg' command
// displayOutput("GG command executed.");
// break;
// case 'help':
// displayOutput("Commands available: gg, help, info, quit");
// break;
// case 'info':
// displayOutput("This is a cool terminal app.");
// break;
// case 'quit':
// displayOutput("Goodbye!");
// break;
// default:
// displayOutput("Invalid Command");
// }
// // Disable the current input
// terminalInput.setAttribute("disabled", "");
// // Remove activeInput class from the current input's container
// terminalInput.parentElement.classList.remove("activeInput");
// // Create a new input container
// let inputContainer = document.createElement("div");
// inputContainer.innerHTML = inputContent;
// inputContainer.classList.add("inputDiv", "activeInput");
// terminal.appendChild(inputContainer);
// // Focus the new input
// let newInput = inputContainer.querySelector(".terminal_input");
// if (newInput) {
// newInput.focus();
// }
// }
// });
// // Start typing "gg" and then simulate pressing Enter
// setTimeout(() => {
// typeCharacterByCharacter("gg", 0, simulateEnterKeyPress);
// }, 300)
// });