wudysoft commited on
Commit
c9a8918
·
verified ·
1 Parent(s): 718b6c8

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +369 -227
app.js CHANGED
@@ -204,257 +204,399 @@ app.get('/cookie', async (req, res) => {
204
  }
205
  });
206
 
207
- // Gemini AI interaction function
208
- async function geminiAIInteraction(input) {
209
- const browser = await chromium.launch();
210
- const page = await browser.newPage();
211
 
212
- try {
213
- await page.goto('https://gemini.ai4you.top/');
214
- /*, {
215
- waitUntil: 'networkidle2'
216
- });
217
- */
218
- await page.type('.gen-textarea', input);
219
-
220
- // Scroll to the button
221
- await page.evaluate(() => {
222
- const button = document.querySelector('button[gen-slate-btn=""]');
223
- if (button) {
224
- button.scrollIntoView({ behavior: 'smooth', block: 'center' });
225
- }
226
- });
227
 
228
- // Wait for the button to be visible and click it
229
- await page.waitForSelector('button[gen-slate-btn=""]', { visible: true });
230
- await page.click('button[gen-slate-btn=""]');
 
 
 
 
 
 
 
 
 
 
 
231
 
232
- // Wait for the response to appear
233
- await page.waitForSelector('.gpt-retry-btn span', { timeout: 10000 });
234
 
235
- const response = await page.evaluate(() => {
236
- const responses = document.querySelectorAll('.message.prose.break-words.overflow-hidden');
237
- return responses.length > 1 ? responses[1].innerText : '';
238
- });
 
 
 
 
 
 
239
 
240
- // Optionally clear the chat
241
- try {
242
- await page.click('button[title="Clear"]');
243
- } catch (error) {
244
- console.error('Error during AI chat interaction:', error);
245
- }
246
 
247
- await browser.close();
248
- return response;
249
- } catch (error) {
250
- console.error('Error during AI interaction:', error);
251
- await browser.close();
252
- throw error;
253
- }
 
 
254
  }
255
 
256
- // Create the API route for AI Chat interaction
257
- app.get('/aichat', async (req, res) => {
258
- const { input } = req.query;
 
 
 
259
 
260
- if (!input) {
261
- return res.status(400).send('Missing input for AI chat.');
262
- }
 
263
 
264
- try {
265
- const aiResponse = await geminiAIInteraction(input);
266
- res.json({ aiResponse }); // Send the AI response as JSON
267
- } catch (error) {
268
- res.status(500).send('Error during AI chat interaction: ' + error.message);
269
- }
270
- });
271
 
 
 
 
 
 
 
 
 
272
 
273
- // Initialize perplexity object
274
- const perplexity = {
275
- isInitialized: false,
276
- page: null,
277
- categories: [
278
- "all",
279
- "academic",
280
- "writing",
281
- "wolfram",
282
- "youtube",
283
- "reddit",
284
- "wikipedia"
285
- ],
286
- currentCategory: "all",
287
- categoryChange: false,
288
- send: async (message) => {
289
- return new Promise(async (resolve, reject) => {
290
- async function sendMessage(i) {
291
- if (!perplexity.categoryChange) {
292
- await perplexity.page.goto("https://www.perplexity.ai/");
293
- } else perplexity.categoryChange = false;
294
- await perplexity.page.waitForSelector("textarea");
295
- await type("textarea", i.toString().trim());
296
- await click("button.bg-super.text-sm");
297
- let wait = setInterval(async () => {
298
- let content = await perplexity.page.content();
299
- if (content.includes("Answer")) {
300
- let response = await perplexity.page.evaluate(() => {
301
- return Object.values(document.querySelector("div.break-words.min-w-0").children[0].children[0].children)
302
- .map(x => x)
303
- .filter(x => x.className == "" && x.textContent.length > 5)
304
- .map(x => x.textContent)
305
- .join(" ");
306
- });
307
- resolve(response.trim());
308
- clearInterval(wait);
309
- }
310
- }, 1000);
311
- }
312
- if (!perplexity.isInitialized) {
313
- let wait = setInterval(async () => {
314
- if (perplexity.isInitialized) {
315
- sendMessage(message);
316
- clearInterval(wait);
317
- }
318
- })
319
- } else sendMessage(message);
320
- });
321
- },
322
- forget: async function() {
323
- perplexity.isInitialized = false;
324
- await perplexity.page.evaluate(`
325
- (() => {
326
- const cookies = document.cookie.split(";");
327
- for (let i = 0; i < cookies.length; i++) {
328
- const cookie = cookies[i];
329
- const eqPos = cookie.indexOf("=");
330
- const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
331
- document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
332
- }
333
- })();
334
- localStorage.clear();
335
- sessionStorage.clear();
336
- `);
337
- await perplexity.page.context().clearCookies();
338
- await perplexity.page.goto("https://www.perplexity.ai/");
339
- perplexity.isInitialized = true;
340
- },
341
- category: async function(type) {
342
- perplexity.categoryChange = true;
343
- perplexity.isInitialized = false;
344
- type = type.toString().toLowerCase().trim();
345
- await perplexity.page.goto("https://www.perplexity.ai/");
346
- if (perplexity.categories.includes(type)) {
347
- await perplexity.page.evaluate(`Object.values(document.querySelectorAll("button")).filter(x => x.textContent.includes("Focus"))[0].click(), setTimeout(() => Object.values(document.querySelectorAll(".mt-one ml-two light font-sans text-xs font-medium text-textOff".replace(/ /gi, "."))).map(x => x.parentElement).filter(x => x.textContent.toLowerCase().includes("${type}"))[0].click(), 500)`);
348
- setTimeout(() => perplexity.isInitialized = true, 500);
349
- } else throw new Error(`Perplexity.AI: No category found called "${type}"`);
350
- }
351
- };
352
 
353
- // Helper functions
354
- async function type(element, text) {
355
- await perplexity.page.fill(element, text);
 
 
 
356
  }
357
 
358
- async function click(element) {
359
- await perplexity.page.waitForSelector(element);
360
- await perplexity.page.click(element);
 
 
361
  }
362
 
363
- app.get('/perplexity', async (req, res) => {
364
- try {
365
- const query = req.query.q;
366
- /*
367
- const browser = await chromium.launch({ headless: true });
368
- const page = await browser.newPage();
369
- perplexity.page = page;
370
- await page.goto("https://perplexity.ai/");
371
- perplexity.isInitialized = true;
372
- */
373
- const response = await perplexity.send(query);
374
- res.json({ answer: response });
375
- } catch (error) {
376
- res.status(500).json({ error: error.message });
377
- }
378
- });
379
 
380
- async function downloadYouTubeVideo(url) {
381
- const browser = await chromium.launch({
382
- headless: true,
383
- args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'],
384
- });
385
 
386
- try {
387
- const page = await browser.newPage();
388
- console.log('Started automation.');
389
- await page.waitForTimeout(3000);
390
- await page.goto('https://www.ytmp3.nu/', { waitUntil: 'domcontentloaded' });
391
- await page.waitForTimeout(3000);
392
-
393
- // Use the keyboard to focus and type the URL
394
- await page.fill('input[name="url"]', url);
395
- await page.waitForTimeout(4000);
396
-
397
- // Trigger the convert button by hitting "Enter"
398
- await page.keyboard.press('Enter');
399
- await page.waitForTimeout(6000);
400
-
401
- console.log('URL processing completed.');
402
-
403
- const buttons = await page.$$('a[rel="nofollow"]');
404
- const buttonsAfterInput = await page.$$('a'); // Selects all buttons on the page
405
- buttonsAfterInput.forEach(async (button, index) => {
406
- const buttonValue = await button.textContent();
407
- console.log(`Index ${index}: ${buttonValue}`);
408
- });
409
 
410
- try {
411
- if (true) {
412
- const secondButton = buttonsAfterInput[8];
413
- const songURL = await secondButton.getAttribute('href');
414
- return songURL;
415
- }
416
- } catch (error) {
417
- console.log(`Error during download: ${error}`);
418
- }
419
- } finally {
420
- await browser.close();
421
- }
422
  }
423
 
424
- app.post('/send_req', async (req, res) => {
425
- const url = req.body.url;
426
- if (!url) {
427
- return res.status(400).json({ error: 'Did not provide the url parameter, include the \'url\' parameter' });
428
- } else {
429
- const result = await downloadYouTubeVideo(url);
430
-
431
- const details = {
432
- Status: 'Online',
433
- 'song-url': url,
434
- 'Download-url': result,
435
- Author: 'Terminal',
436
- 'Launch-date': '4-11-23'
437
- };
438
- return res.json(details);
439
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
440
  });
 
 
 
 
441
 
442
- // Support for GET request as well
443
- app.get('/send_req', async (req, res) => {
444
- const url = req.query.url; // Get the URL from the query parameter
445
- if (!url) {
446
- return res.status(400).json({ error: 'Did not provide the url parameter, include the \'url\' parameter' });
447
- } else {
448
- const result = await downloadYouTubeVideo(url);
449
-
450
- const details = {
451
- Status: 'Online',
452
- 'song-url': url,
453
- 'Download-url': result,
454
- Author: 'Terminal',
455
- 'Launch-date': '4-11-23'
456
- };
457
- return res.json(details);
458
  }
459
  });
460
 
 
204
  }
205
  });
206
 
207
+ app.get('/welcome', async (req, res) => {
208
+ const { name, info } = req.query;
 
 
209
 
210
+ // Ensure all required query parameters are present
211
+ if (!name || !info) {
212
+ return res.status(400).json({ error: 'Missing required parameters' });
213
+ }
 
 
 
 
 
 
 
 
 
 
 
214
 
215
+ // Construct HTML content dynamically based on query parameters
216
+ const html = `
217
+ <!DOCTYPE html>
218
+ <html lang="en" >
219
+ <head>
220
+ <meta charset="UTF-8">
221
+ <title>Course Card UI Design - #094 of #100Days100Projects</title>
222
+ <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css'>
223
+ <style>
224
+ @import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
225
+
226
+ * {
227
+ box-sizing: border-box;
228
+ }
229
 
 
 
230
 
231
+ body {
232
+ background-image: linear-gradient(45deg, #7175da, #9790F2);
233
+ font-family: 'Muli', sans-serif;
234
+ display: flex;
235
+ align-items: center;
236
+ justify-content: center;
237
+ flex-direction: column;
238
+ min-height: 100vh;
239
+ margin: 0;
240
+ }
241
 
242
+ .courses-container {
243
+
244
+ }
 
 
 
245
 
246
+ .course {
247
+ background-color: #fff;
248
+ border-radius: 10px;
249
+ box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
250
+ display: flex;
251
+ max-width: 100%;
252
+ margin: 20px;
253
+ overflow: hidden;
254
+ width: 700px;
255
  }
256
 
257
+ .course h6 {
258
+ opacity: 0.6;
259
+ margin: 0;
260
+ letter-spacing: 1px;
261
+ text-transform: uppercase;
262
+ }
263
 
264
+ .course h2 {
265
+ letter-spacing: 1px;
266
+ margin: 10px 0;
267
+ }
268
 
269
+ .course-preview {
270
+ background-color: #2A265F;
271
+ color: #fff;
272
+ padding: 30px;
273
+ max-width: 250px;
274
+ }
 
275
 
276
+ .course-preview a {
277
+ color: #fff;
278
+ display: inline-block;
279
+ font-size: 12px;
280
+ opacity: 0.6;
281
+ margin-top: 30px;
282
+ text-decoration: none;
283
+ }
284
 
285
+ .course-info {
286
+ padding: 30px;
287
+ position: relative;
288
+ width: 100%;
289
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
 
291
+ .progress-container {
292
+ position: absolute;
293
+ top: 30px;
294
+ right: 30px;
295
+ text-align: right;
296
+ width: 150px;
297
  }
298
 
299
+ .progress {
300
+ background-color: #ddd;
301
+ border-radius: 3px;
302
+ height: 5px;
303
+ width: 100%;
304
  }
305
 
306
+ .progress::after {
307
+ border-radius: 3px;
308
+ background-color: #2A265F;
309
+ content: '';
310
+ position: absolute;
311
+ top: 0;
312
+ left: 0;
313
+ height: 5px;
314
+ width: 66%;
315
+ }
 
 
 
 
 
 
316
 
317
+ .progress-text {
318
+ font-size: 10px;
319
+ opacity: 0.6;
320
+ letter-spacing: 1px;
321
+ }
322
 
323
+ .btn {
324
+ background-color: #2A265F;
325
+ border: 0;
326
+ border-radius: 50px;
327
+ box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
328
+ color: #fff;
329
+ font-size: 16px;
330
+ padding: 12px 25px;
331
+ position: absolute;
332
+ bottom: 30px;
333
+ right: 30px;
334
+ letter-spacing: 1px;
335
+ }
 
 
 
 
 
 
 
 
 
 
336
 
337
+ /* SOCIAL PANEL CSS */
338
+ .social-panel-container {
339
+ position: fixed;
340
+ right: 0;
341
+ bottom: 80px;
342
+ transform: translateX(100%);
343
+ transition: transform 0.4s ease-in-out;
 
 
 
 
 
344
  }
345
 
346
+ .social-panel-container.visible {
347
+ transform: translateX(-10px);
348
+ }
349
+
350
+ .social-panel {
351
+ background-color: #fff;
352
+ border-radius: 16px;
353
+ box-shadow: 0 16px 31px -17px rgba(0,31,97,0.6);
354
+ border: 5px solid #001F61;
355
+ display: flex;
356
+ flex-direction: column;
357
+ justify-content: center;
358
+ align-items: center;
359
+ font-family: 'Muli';
360
+ position: relative;
361
+ height: 169px;
362
+ width: 370px;
363
+ max-width: calc(100% - 10px);
364
+ }
365
+
366
+ .social-panel button.close-btn {
367
+ border: 0;
368
+ color: #97A5CE;
369
+ cursor: pointer;
370
+ font-size: 20px;
371
+ position: absolute;
372
+ top: 5px;
373
+ right: 5px;
374
+ }
375
+
376
+ .social-panel button.close-btn:focus {
377
+ outline: none;
378
+ }
379
+
380
+ .social-panel p {
381
+ background-color: #001F61;
382
+ border-radius: 0 0 10px 10px;
383
+ color: #fff;
384
+ font-size: 14px;
385
+ line-height: 18px;
386
+ padding: 2px 17px 6px;
387
+ position: absolute;
388
+ top: 0;
389
+ left: 50%;
390
+ margin: 0;
391
+ transform: translateX(-50%);
392
+ text-align: center;
393
+ width: 235px;
394
+ }
395
+
396
+ .social-panel p i {
397
+ margin: 0 5px;
398
+ }
399
+
400
+ .social-panel p a {
401
+ color: #FF7500;
402
+ text-decoration: none;
403
+ }
404
+
405
+ .social-panel h4 {
406
+ margin: 20px 0;
407
+ color: #97A5CE;
408
+ font-family: 'Muli';
409
+ font-size: 14px;
410
+ line-height: 18px;
411
+ text-transform: uppercase;
412
+ }
413
+
414
+ .social-panel ul {
415
+ display: flex;
416
+ list-style-type: none;
417
+ padding: 0;
418
+ margin: 0;
419
+ }
420
+
421
+ .social-panel ul li {
422
+ margin: 0 10px;
423
+ }
424
+
425
+ .social-panel ul li a {
426
+ border: 1px solid #DCE1F2;
427
+ border-radius: 50%;
428
+ color: #001F61;
429
+ font-size: 20px;
430
+ display: flex;
431
+ justify-content: center;
432
+ align-items: center;
433
+ height: 50px;
434
+ width: 50px;
435
+ text-decoration: none;
436
+ }
437
+
438
+ .social-panel ul li a:hover {
439
+ border-color: #FF6A00;
440
+ box-shadow: 0 9px 12px -9px #FF6A00;
441
+ }
442
+
443
+ .floating-btn {
444
+ border-radius: 26.5px;
445
+ background-color: #001F61;
446
+ border: 1px solid #001F61;
447
+ box-shadow: 0 16px 22px -17px #03153B;
448
+ color: #fff;
449
+ cursor: pointer;
450
+ font-size: 16px;
451
+ line-height: 20px;
452
+ padding: 12px 20px;
453
+ position: fixed;
454
+ bottom: 20px;
455
+ right: 20px;
456
+ z-index: 999;
457
+ }
458
+
459
+ .floating-btn:hover {
460
+ background-color: #ffffff;
461
+ color: #001F61;
462
+ }
463
+
464
+ .floating-btn:focus {
465
+ outline: none;
466
+ }
467
+
468
+ .floating-text {
469
+ background-color: #001F61;
470
+ border-radius: 10px 10px 0 0;
471
+ color: #fff;
472
+ font-family: 'Muli';
473
+ padding: 7px 15px;
474
+ position: fixed;
475
+ bottom: 0;
476
+ left: 50%;
477
+ transform: translateX(-50%);
478
+ text-align: center;
479
+ z-index: 998;
480
+ }
481
+
482
+ .floating-text a {
483
+ color: #FF7500;
484
+ text-decoration: none;
485
+ }
486
+
487
+ @media screen and (max-width: 480px) {
488
+
489
+ .social-panel-container.visible {
490
+ transform: translateX(0px);
491
+ }
492
+
493
+ .floating-btn {
494
+ right: 10px;
495
+ }
496
+ }
497
+ </style>
498
+
499
+ </head>
500
+ <body>
501
+ <!-- partial:index.partial.html -->
502
+ <div class="courses-container">
503
+ <div class="course">
504
+ <div class="course-preview">
505
+ <h6>Course</h6>
506
+ <h2>${name}</h2>
507
+ <a href="#">View all chapters <i class="fas fa-chevron-right"></i></a>
508
+ </div>
509
+ <div class="course-info">
510
+ <div class="progress-container">
511
+ <div class="progress"></div>
512
+ <span class="progress-text">
513
+ 6/9 Challenges
514
+ </span>
515
+ </div>
516
+ <h6>${info}</h6>
517
+ <h2>Callbacks & Closures</h2>
518
+ <button class="btn">Continue</button>
519
+ </div>
520
+ </div>
521
+ </div>
522
+
523
+ <!-- SOCIAL PANEL HTML -->
524
+ <div class="social-panel-container">
525
+ <div class="social-panel">
526
+ <p>Created with <i class="fa fa-heart"></i> by
527
+ <a target="_blank" href="https://florin-pop.com">Florin Pop</a></p>
528
+ <button class="close-btn"><i class="fas fa-times"></i></button>
529
+ <h4>Get in touch on</h4>
530
+ <ul>
531
+ <li>
532
+ <a href="https://www.patreon.com/florinpop17" target="_blank">
533
+ <i class="fab fa-discord"></i>
534
+ </a>
535
+ </li>
536
+ <li>
537
+ <a href="https://twitter.com/florinpop1705" target="_blank">
538
+ <i class="fab fa-twitter"></i>
539
+ </a>
540
+ </li>
541
+ <li>
542
+ <a href="https://linkedin.com/in/florinpop17" target="_blank">
543
+ <i class="fab fa-linkedin"></i>
544
+ </a>
545
+ </li>
546
+ <li>
547
+ <a href="https://facebook.com/florinpop17" target="_blank">
548
+ <i class="fab fa-facebook"></i>
549
+ </a>
550
+ </li>
551
+ <li>
552
+ <a href="https://instagram.com/florinpop17" target="_blank">
553
+ <i class="fab fa-instagram"></i>
554
+ </a>
555
+ </li>
556
+ </ul>
557
+ </div>
558
+ </div>
559
+ <button class="floating-btn">
560
+ Get in Touch
561
+ </button>
562
+
563
+ <div class="floating-text">
564
+ Part of <a href="https://florin-pop.com/blog/2019/09/100-days-100-projects" target="_blank">#100Days100Projects</a>
565
+ </div>
566
+ <!-- partial -->
567
+ <script>
568
+ // INSERT JS HERE
569
+
570
+
571
+ // SOCIAL PANEL JS
572
+ const floating_btn = document.querySelector('.floating-btn');
573
+ const close_btn = document.querySelector('.close-btn');
574
+ const social_panel_container = document.querySelector('.social-panel-container');
575
+
576
+ floating_btn.addEventListener('click', () => {
577
+ social_panel_container.classList.toggle('visible')
578
+ });
579
+
580
+ close_btn.addEventListener('click', () => {
581
+ social_panel_container.classList.remove('visible')
582
  });
583
+ </script>
584
+
585
+ </body>
586
+ </html>`;
587
 
588
+ try {
589
+ const browser = await chromium.launch(); // Launch Playwright Chromium browser
590
+ const page = await browser.newPage();
591
+ await page.setContent(html);
592
+ const buffer = await page.screenshot({ type: 'png' });
593
+ await browser.close();
594
+
595
+ res.set('Content-Type', 'image/png');
596
+ return res.send(buffer);
597
+ } catch (error) {
598
+ console.error('Error generating PNG:', error);
599
+ res.status(500).json({ error: 'Failed to convert HTML to PNG' });
 
 
 
 
600
  }
601
  });
602