-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
58 lines (44 loc) · 1.36 KB
/
search.js
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
// After the API loads, call a function to enable the search box.
function handleAPILoaded() {
$('#search-button').attr('disabled', false);
}
function search(WikiTitle) {
console.log('Search Started');
var title = WikiTitle;
console.log('Search Request');
request = gapi.client.youtube.search.list({
q: title,
part: 'id, snippet',
type: 'video',
order: 'relevance'
});
request.execute(function(response) {
// alert(JSON.stringify(response))
vidIDS = parseYoutubeSearchResults(response);
sendVidIDs(vidIDS);
});
}
function parseYoutubeSearchResults(res) {
vidIDs = [];
vid1ID = res['items'][0]['id']['videoId'];
results = res['items'];
for (var i = 0; i < results.length || i < 5 ; i++) {
id = results[i]['id']['videoId'];
vidIDs[i] = id;
}
// alert( JSON.stringify(vidIDs) );
return vidIDs;
}
function sendVidID(id) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {id: id, highway: 'sendVidID'}, function(response) {
});
});
}
function sendVidIDs(ids) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {ids: ids, highway: 'sendVidIDs'}, function(response) {
// alert(ids[0])
});
});
}