123

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.

            
              <html>
  <body>
    <div>
      <h1>Wikipedia Viewer</h1>
    </div>    
    <div class="container-fluid" id="control">
      <label>Search random article </label>
      <input id="input" type-"text" name="Search" placeholder="search...">
      <button class="btn brn-default" id="btn_search">Search</button>
      <button class="btn brn-default" id="btn_rand">Random article</button>
    </div>
    <div class="container" id="display">
    </div>
    <div class="panel-footer" id="footer">Developed by Felnyr 2017</div>
  </body>
</html>

            
          
!
            
              body{
  text-align:center;
  margin:auto;
  color:lightgrey;
}
h1{
  color:black;
}
div{
  width:auto;
  padding:10px;
  margin:5px;
}
button{
  color:black;
  margin:3px 3px 0 0;
}
a{
  font-size:20px;
  margin:0;
  color:orange;
}
a:link, a:visited{
  font-size:20px;
  margin:0;
  color:orange;
  text-decoration:none;
}
a:hover, a:active{
  font-size:20px;
  color:white;
  text-decoration:none; 
}
a:focus{
  outline:none;
}
#control{
  padding:10px;
  background:orange;
}
#input{
  color:black;
  margin-bottom:5px;
  padding:5px 50px 6px 5px;
}
#footer{
  color:grey;
}


            
          
!
            
              $(document).ready(function(){
  
  $(document).keypress(function(e){
    if(e.which == 13) {
     $("#btn_search").click()
    }
  });
$("#btn_search").on("click", function(){
  var SearchValue = $("#input").val();
  var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search="+SearchValue;
  $("#display").empty();
  $.ajax({   
    url: url,
    type:"GET",
    dataType:"jsonp",
    async:true,
    success: function(data){
      for(var i=0;i<data[1].length;i++){
      $("#display").append("<div id=\"term"+i+"\"><a href=\""+data[3][i]+"\" target=\"_blank\">"+data[1][i]+"</a><br>"+data[2][i]+"</div>");
      $('#term'+i).hide();
      }
      
      //Random Color&slide script by Felnyr

      for(var i=0;i<data[1].length;i++){
      $("#term"+i).css("background-color", "#"+Math.floor(Math.random()*10)+Math.floor(Math.random()*10)+Math.floor(Math.random()*10));
      $("#term"+i).css("border-radius","6px");
      $("#term"+i).show(200*i+300);  
      }//end script
      
    },
    error: function(error){
      alert("You typed nothing");    
    }
    
  }); // ajax req end for normal search
});//btn search end

$("#btn_rand").on("click", function(){
  $("#display").empty();
  $.ajax({
    type: "GET",
    url: "https://en.wikipedia.org/w/api.php?format=json&action=query&generator=random&grnnamespace=0&grnlimit=5&prop=extracts&exsentences=5&exintro=true&exlimit=5excontinue=1",
    dataType: "jsonp",
    async: false,
    success:function(randId){ 
     
     console.log(Object.values(randId.query.pages));
     var randId2 = Object.values(randId.query.pages);
     $.each(randId2, function(index, val) {
     $("#display").append("<div id=\"term"+index+"\"><p><a href=\"https://en.wikipedia.org/?curid="+val.pageid+"\" target=\"_blank\">"+val.title+"</a></p><p>"+val.extract+"</p></div>");
     $('#term'+index).hide();  
       
     //Random Color&slide script by Felnyr

      for(var i=0;i<5;i++){
      $("#term"+i).css("background-color", "#"+Math.floor(Math.random()*10)+Math.floor(Math.random()*10)+Math.floor(Math.random()*10));
      $("#term"+i).css("border-radius","6px");
      $("#term"+i).show(200*i+300);  
      }//end script
       
    }) //end ajax for random         
    },
    error:function(errorRand){
     alert("Cannot load articles. Try again");
    }
  });

  
});//btn rand end  
});//doc ready end 


            
          
!
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.

Console