Wikipedia Viewer

Developer
Size
4,426 Kb
Views
4,048

How do I make an wikipedia viewer?

A Wikipedia viewer built for freeCodeCamp. Uses the MediaWiki API.. What is a wikipedia viewer? How do you make a wikipedia viewer? This script and codes were developed by Zac Clemans on 14 January 2023, Saturday.

Wikipedia Viewer Previews

Wikipedia Viewer - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Wikipedia Viewer</title> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,700,900' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="header" class="container-fluid"> <h1>QWiki: Wikipedia FAST!</h1>
</div>
<div id="divider" class="container-fluid">
</div>
<div id="main" class="container"> <div class="row special" id="search-container"> <div class="col-sm-8"><input id="search-bar" type="text" value="Search Wikipedia"></div> <div class="col-sm-2" id="search-button"><i class="glyphicon glyphicon-search"></i></div> <div class="col-sm-2" id="random-button"><i class="glyphicon glyphicon-question-sign"></i></div> </div> <div class="col-sm-8" id="suggest-holder"> <ul> </ul> </div>
</div>
<div id="footer"> <h5 id="name">Created by: Zac Clemans</h5> <h5 id="credit">Powered by: MediaWiki API</h5>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Wikipedia Viewer - Script Codes CSS Codes

body { font-family: Open-Sans; color: #36332e; background: #f0f0f0;
}
a { text-decoration: none; color: #36332e;
}
a:hover { text-decoration: none; color: #e69a4e;
}
#header { font-family: Playfair; background: #f8b504;
}
#header h1 { font-weight: 900;
}
#divider { height: 10px; margin-bottom: 40px; background: #36332e; box-shadow: 5px 5px 5px #a4a4a4;
}
#main { position: relative;
}
#main #search-container { font-size: 20px;
}
#main #search-container #search-bar { width: 100%; height: 40px; padding-left: 10px; border: none; border-radius: 5px;
}
#main #search-container #search-button, #main #search-container #random-button { text-align: center; line-height: 40px; height: 40px; border: 1px solid #36332e; border-radius: 5px; background: #f8b504;
}
#main #search-container #search-button:hover, #main #search-container #random-button:hover { cursor: pointer;
}
#main #search-container #search-button:active, #main #search-container #random-button:active { color: white; background: #36332e;
}
#suggest-holder { position: absolute; display: none; width: 66.6%; margin-top: -1px; margin-left: -15px; background: white; /*border: 2px solid rgb(197, 218, 237);*/ z-index: 1;
}
#suggest-holder ul { list-style: none; margin: 0; padding: 0;
}
#suggest-holder ul li { padding: 5px;
}
#suggest-holder ul li:hover, #suggest-holder ul li.active { cursor: pointer; background: rgba(150, 150, 150, 0.2);
}
.article-container { margin-bottom: 10px; border: 2px solid #383d40; border-radius: 10px; background: white;
}
.article-container h3, .article-container p { margin-left: 20px;
}
div.special > div[class*="col-"] { padding: 0;
}
#footer { position: fixed; bottom: 0; left: 0; right: 0; background: #f8b504;
}
#footer #name { float: left; font-weight: 700; padding-left: 20px;
}
#footer #credit { float: right; font-weight: 700; padding-right: 20px;
}

Wikipedia Viewer - Script Codes JS Codes

var $searchBar = $("#search-bar");
var $searchBtn = $("#search-button");
var $suggestHolder = $("#suggest-holder");
var index = -1;
var keySelection = false;
$searchBtn.on('click', function(){ $suggestHolder.slideUp(); $suggestHolder.css('border', ''); var query = $searchBar.val(); $.ajax({ url: "https://www.wikipedia.org/w/api.php", data: { action: "query", list: "search", format: "json", srsearch: query, srlimit: "25" }, dataType: "jsonp", success: function(data){ appendArticles(data.query.search); }, type: "GET" });
});
$searchBar.on('focus', function(){ $(this).select();
});
$searchBar.on('keyup', function(e){ if (e.which == 13){ // Enter key if ($("#suggest-holder li").hasClass('active')){ $searchBar.val($("#suggest-holder li.active").text()); $searchBtn.click(); } $searchBtn.click(); } else if (e.which == 27){ // Esc key $suggestHolder.slideUp(); } else if (e.which == 40){ // Down key index++; if (index > $("#suggest-holder li").length - 1){ index = $("#suggest-holder li").length - 1; } keySelection = true; } else if (e.which == 38){ // Up key index--; if (index < 0){ index = 0; } keySelection = true; } else{ index = -1; $suggestHolder.slideDown(); $("#suggest-holder ul").empty(); if ($searchBar.val().length > 1){ var query = $("#search-bar").val(); $.ajax({ url: "https://www.wikipedia.org/w/api.php", data: { action: "opensearch", format: "json", search: query }, dataType: "jsonp", success: function(data){ data[1].forEach(function(suggestion, index){ $("#suggest-holder ul").append("<li>" + suggestion + "</li>"); }); }, type: "GET" }); } } if (keySelection){ $("#suggest-holder li.active").removeClass('active'); $("#suggest-holder li").eq(index).addClass('active'); }
});
$("ul").on('click', 'li', function(){ $searchBar.val($(this).text()); $searchBtn.click();
});
$("#random-button").on('click', function(){ window.open("https://en.wikipedia.org/wiki/Special:Random")
});
$searchBar.on('focusout', function(){ $suggestHolder.slideUp(); $suggestHolder.css('border', ''); $("#suggest-holder li.active").removeClass('active');
});
function appendArticles(articleList){ $(".article-container").remove(); articleList.forEach(function(article, index){ $("#main") .append("<a href='https://en.wikipedia.org/wiki/" + article.title + "' target='_blank'>" + "<div class='article-container'>" + "<h3>" + article.title + "</h3>" + "<p>" + article.snippet + "</p>" + "</div>" + "</a>"); }); $(".article-container:first").css('margin-top', '40px') $(".article-container:last").css('margin-bottom', '60px')
}
Wikipedia Viewer - Script Codes
Wikipedia Viewer - Script Codes
Home Page Home
Developer Zac Clemans
Username thalpha
Uploaded January 14, 2023
Rating 3
Size 4,426 Kb
Views 4,048
Do you need developer help for Wikipedia Viewer?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Zac Clemans (thalpha) Script Codes
Create amazing web content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!