-
Notifications
You must be signed in to change notification settings - Fork 0
/
search2.html
69 lines (65 loc) · 2.76 KB
/
search2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html>
<head>
<title>Search Result</title>
</head>
<body>
<a href="home.html"><h1>Recommender system</h1></a>
<h1>Search Result</h1>
<p id="result-author">Author: J K Rowling</p>
<h3 id="result-title">Harry Potter and the Sorcerer's Stone</h3>
<p>40 likes</p>
<p>0 dislikes</p>
<p>Available</p>
<a href="share3.html"><button>Summary of Book</button></a>
<a href="Readlink.html"><button>Read</button></a>
<script>
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var resultTitleElement = document.getElementById('result-title');
var resultAuthorElement = document.getElementById('result-author');
var searchEngine = {
"Harry Potter": {title: "Harry Potter", author: "J. K. Rowling"},
"Warriors": {title: "Warriors", author: "Erin Hunter"},
"Percy Jackson": {title: "Percy Jackson", author: ""},
"Diary of a Wimpy Kid": {title: "Diary of a Wimpy Kid", author: ""},
"Floors": {title: "Floors", author: ""},
"Big Nate": {title: "Big Nate", author: ""},
"Geronimo Stilton": {title: "Geronimo Stilton", author: ""},
"Magic Tree House": {title: "Magic Tree House", author: ""},
"Nancy Drew": {title: "Nancy Drew", author: ""},
"Cam Janson": {title: "Cam Janson", author: ""},
"Hardy Boys": {title: "Hardy Boys", author: ""},
"Magic School Bus": {title: "Magic School Bus", author: ""},
"J.K.Rowling": {title: "Harry Potter", author: ""},
"Erin Hunter": {title: "Warriors", author: ""},
"Rick Riordian": {title: "Percy Jackson", author: ""},
"Jeff Kinney": {title: "Diary of a Wimpy Kid", author: ""},
"Patrick Carman": {title: "Floors", author: ""},
"Lincon Pierce": {title: "Big Nate", author: ""},
"Mary Pope Osborne": {title: "Magic Tree House", author: ""},
"Carolyn Keene": {title: "Cam Janson", author: ""},
"David A. Adler": {title: "Hardy Boys", author: ""},
"Franklin W. Dixon": {title: "Magic School Bus", author: ""},
};
var searchtitle = getParameterByName('title');
var searchauthor = getParameterByName('author');
var result = {title: searchtitle + " book 2", author: "I. M. Wordy"};
if (searchEngine[searchtitle]) {
result = searchEngine[searchtitle];
} else if (searchEngine[searchauthor]) {
result = searchEngine[searchauthor];
}
resultTitleElement.innerText = result.title;
resultAuthorElement.innerText = result.author;
</script>
</body>
</html>