Guest User

Untitled

a guest
Oct 18th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. const cheerio = require('cheerio');
  2. const google = require('google');
  3. const request = require('superagent');
  4. const util = require('util');
  5.  
  6. const misconfiguredCORS = require('./plugins/misconfiguredCORS');
  7.  
  8. google.resultsPerPage = 100;
  9. const g = util.promisify(google);
  10.  
  11. async function fetchURLsFromGoogle(q) {
  12. const { links } = await g(q);
  13. return links
  14. .filter(link => link.link)
  15. .map(link => link.link);
  16. }
  17.  
  18. function* createGenerator(urls, plugin, ...args) {
  19. let currIndex = 0;
  20. while(true) {
  21. if(currIndex >= urls.length)
  22. return { done: true };
  23. yield plugin(urls[currIndex++], ...args);
  24. }
  25. }
  26.  
  27. async function main(q) {
  28. const urls = await fetchURLsFromGoogle(q);
  29. const headers = await createGenerator(urls, misconfiguredCORS, 'lol.com');
  30. const results = await Promise.all(headers);
  31. return results.filter(result=>result);
  32. }
  33.  
  34. main(process.argv[2])
  35. .then(results=>console.log(results))
  36. .then(() => process.exit()) // Required otherwise shit hangs
  37. .catch(err => console.error(err));
Add Comment
Please, Sign In to add comment