css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <body>

  <div class="container text-center">
    <form id="form" class="form">
      <input name="input" class="form-control" id="term" type="search" required placeholder="Search Wikipedia...">
      <button type="submit" value="click">
        <span id="search-icon"><i class="fas fa-search"></i></span>
      </button>
      <span class="formbutton" id="clear">Clear</span>
      <!-- <a href="#" class="formbutton" id="clear">Clear</a> -->
      <a href="https://en.wikipedia.org/wiki/Special:Random" target="_blank" class="formbutton"><i class="fas fa-random"></i> Random</a>
    </form>

    <div id="contents">
    </div>

  </div>

  <div class="container justify-content-center text-light text-center" id="footer" >
    Written and Coded By <a href="http://yingjiehu.com" target="_blank">Yingjie Hu</a> with <span style="color:red"><i class="fas fa-heart"></i></span><br>
    View <a href="https://github.com/huyingjie/wikipediaViewer" target="_blank">source code</a> at GitHub and latest <a href="http://wikipediaviewer.yingjiehu.com" target="_blank">updated website</a>
  </div>
</body>

            
          
!
            
              body {
  background-color: rgb(13, 38, 56) !important;
  color: silver !important;
  padding: 20px;
  font-size: 14px;
  margin: auto;
}

#search-icon {
  color: rgb(212, 99, 44);
  font-size: 2em;
  margin: 20px;
}

#footer {
  position:relative;
  bottom:20px !important;
  font-size: 14px;
  left: 0px;
  right: 0px;
  margin-top: 40px;
}

clear {
  cursor: pointer;
}

a {
  color: rgb(212, 99, 44) !important;
}
a, a:hover, a:active, a:visited{
  text-decoration: none !important;
}

*:focus {outline: none;}

.form {
  margin-top: 35%;
}
#form input{
  border: 0px;
  background-color: rgb(13, 38, 56);
  color: white;
  width: 300px;
  border: 5px solid;
  border-color: rgb(212, 99, 44);
  border-radius: 20px;
  display: inline-block;
  float: center;
}

#form button {
  color: rgb(212, 99, 44);
  background-color: rgb(13, 38, 56);
  border: 0px;
  display: inline-block;
  float: center;
}

.formbutton {
  border-radius: 20px;
  border: 2px solid rgb(212, 99, 44);
  padding: 6px;
  background-color: rgb(212, 99, 44);
  color: rgb(13, 38, 56) !important;
  font-weight: bold;
  margin-bottom: 20px;
}

#wiki {
  border: 1px solid rgb(212, 99, 44);
  border-radius: 10px;
  margin-top: 40px;
}
.search-url{
  cursor: pointer;
}

.search-block{
  background-color: #ffffff;
  margin: 20px 20px 20px 30px;
  padding: 20px;
  color: rgb(13, 38, 56);
  border-left: 10px solid transparent;
}

.search-block:hover {
  border-left: 10px solid rgb(212, 99, 44);
}

.search-title{
  text-align: left;
  font-weight: bold;
}

.search-result{
  text-align: left;
}

.searchmatch {
  color: rgb(212, 99, 44);
}

.no-result{
  padding: 20px;
  font-size: 20px;
}

.fa {
  display:inline !important;
}

            
          
!
            
              var searchTerm;
$(document).ready(function() {
  $("#clear").click(function(){
    $("#wiki").hide("");
    $("form").addClass("form");
    $("#term").val("");
  });

  $("#form").submit(function(){
    $(this).removeClass("form");
    event.preventDefault();
    var term =  $('#term').val();
    //console.log("term is: " + term);
    var url = createURL(encodeURI(term));
    //window.open(url,'_blank');

    $.getJSON(url, function(json){
      var contents = json.query.search;
      //console.log(contents);
      var html = "<div id='wiki'>";
      if(contents.length == 0) {
        html += "<div class='no-result'>No results found. Try again ! <div style='font-size: 40px'><i class='far fa-smile'></i><div></div>";
      } else {
        for(var i = 0; i < contents.length; i++){
          //console.log("i=",i, ", title", contents[i].title);
          //console.log(contents[i].snippet);
          html += "<a class='search-url' href='https://en.wikipedia.org/?curid=" + contents[i].pageid + "' target='_blank'><div class='search-block'>"
          html += "<p class='search-title'>" + contents[i].title + "</p>";
          html += "<div class='search-result'>" + contents[i].snippet + "</div>";
          html += "</div></a>";
        }
      }
      html += "</div>";
      $("#contents").html(html);
    });

  });

  function createURL(term){
    return "https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=" + term + "&origin=*";
  }

});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console