-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
81 lines (76 loc) · 3.5 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
<!doctype html>
<html>
<head>
<link rel="stylesheet" type= "text/css" href = "main.css">
<link rel="shortcut icon" href='/img/favicon.ico' type="image/x-icon">
<link rel="icon" href="/img/favicon.ico" type="image/x-icon">
<title>VSync</title>
</head>
<body>
<div id='header'>
<h1>VSync</h1>
</div>
<div id = 'searchBar' >
<!--<div id="searchImageHolder">
<img id='searchImage' src = 'http://static1.squarespace.com/static/528e87f3e4b0ef5d1e49355e/t/5374ab4fe4b060b2a3d1a69c/1400154961532/search-icon-01.jpg'>
</div>-->
<input type='search' id='search' autocomplete="off" onfocus="if (this.value=='search') this.value = ''"></input>
</div>
<!--<div id = 'description'>
<p>Either enter a url, or search for a youtube video</p>
<p>Then invite friends to watch with you!</p>
</div>-->
<div id = 'popularVideos'>
</div>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="bower_components/hashids/lib/hashids.min.js"></script>
<script type="text/javascript">
$("#search").on("keydown",function search(e) {
// console.log('push;');
if(e.keyCode == 13) {
//parse input in the text bar
//if youtube url, parse for video id and open that room
//otherwise display search results
//add in auto search later
var input = ($("#search").val());
if (input == "" || !input.replace(/\s/g, '').length) {
//string was empty or just white space
return false;
}
// console.log(input);
function youtube_parser(url){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
if (match&&match[7].length==11){
return match[7];
}else{
return null;
}
}
videoId = youtube_parser(input);
var url;
if (videoId === null) {
//perform search
url = '/search.html?q=' + input;
// console.log(url);
// console.log(location.host);
finalUrl = 'http://' + location.host + url;
// console.log(finalUrl);
// window.location = finalUrl;
} else {
var hashids = new Hashids("ryan is a bitch", 9);
var roomHash = hashids.encode(Number(String(new Date().getTime()).substring(4)) + Math.floor((Math.random() * 10) + 1));
// var roomId = id;
var url = '/vroom.html?rId=' + roomHash + videoId;
// console.log(url);
// console.log(location.host);
finalUrl = 'http://' + location.host + url;
}
// console.log(finalUrl);
window.location = finalUrl;
// socket.emit('createRoom', videoId);
}
});
</script>
</body>
</html>