Shell_Casing

version 1

Apr 5th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function searchReddit(searchTerm, sortBy, limit) {
  2.     return new Promise(((resolve) => {
  3.         fetch(`http://www.reddit.com/search.json?q=${searchTerm}&sort=${sortBy}&limit=${limit}`)
  4.             .then((res) => res.json())
  5.             .then((data) => {
  6.                 resolve(data);
  7.                 let results = data.data.children.map((data) => data.data);
  8.                 console.log(results);
  9.  
  10.                 // iterate though the posts
  11.                 results.forEach((post) => {
  12.                     let li = document.createElement('li');
  13.                     li.classList.add("list-group-item", "list-group-item-action", "mb-2");
  14.                     let button = document.createElement('button');
  15.                     button.innerText = "Go to Subreddit";
  16.                     button.classList.add("btn", "btn-success", "ml-5");
  17.                     let anchor = document.createElement('a');
  18.                     let link = post.url;
  19.                     anchor.setAttribute("href", link);
  20.                     anchor.setAttribute('target', '_blank');
  21.                     let title = post.title;
  22.                     li.textContent = title;
  23.                     button.append(anchor);
  24.                     li.append(button);
  25.                     output.append(li);
  26.                 })
  27.             })
  28.     }))
  29. }
Add Comment
Please, Sign In to add comment