-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIfull.js
More file actions
146 lines (106 loc) · 3.66 KB
/
APIfull.js
File metadata and controls
146 lines (106 loc) · 3.66 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// Instagram API
//
function displayData(response) {
var arrphotos = [];
var arrphotoswhole = [];
for (var s = 0; s < 20; s++) {
arrphotoswhole.push(response['data'][s]);
}
arrphotoswhole.sort(function(a,b){
return b['likes']['count'] - a['likes']['count'];
});
for (var i = 0; i < 6; i++) {
arrphotos.push(arrphotoswhole[i]['images']['standard_resolution']['url']);
}
// document.getElementById("pic").setAttribute("src", imgArray[0]);
for (var j = 0; j < 6; j++) {
var oImg = document.createElement("img");
oImg.setAttribute('src', arrphotos[j]);
oImg.setAttribute('class', 'instaphotos');
oImg.setAttribute('configurable', true);
oImg.setAttribute('alt', 'na');
// document.body.appendChild(oImg);
document.getElementById('insta').appendChild(oImg);
// document.getElementById('instagramphotos').innerHTML = '<ol><li>'oImg'</li></ol>';
// document.getElementById('instagramphotos').appendChild(oImg);
}
}
var clicked = false;
function clickfunc(){
var str = document.getElementById('result').value;
var clientS = str.replace(/\s+/g, '');
clicked = true;
// create script element
if (clientS === ''){
clientS = 'foifighters';
}
var script = document.createElement('script');
// assing src with callback name
script.src = "https://api.instagram.com/v1/tags/" + clientS + "/media/recent?access_token=2208596365.1fb234f.2d3cc38a6e354a958800809ced644f50&count=33&callback=displayData";
// insert script to document and load content
document.body.appendChild(script);
//this removes img elements
var element = document.getElementsByClassName("instaphotos");
for (index = element.length - 1; index >= 0; index--) {
element[index].parentNode.removeChild(element[index]);
}
console.log(clientS);
return clientS;
}
//console.log(clickfunc());
document.getElementById("search").addEventListener("click", clickfunc);
//
// Soundcloud API
//
document.getElementById("search").addEventListener("click", soundfunc);
function soundfunc(){
// initialize client with app credentials */
SC.initialize({
/* client_id: '38fed2acd8bf8e0001c5a3dddad41c76',*/
client_id: '5c5a64cfdf37c482bb757df270d33c53',
redirect_uri: 'http://fcscripters.github.io/moodNews/callback.html'
});
var query = document.getElementById("result").value;
// var query = "oasis";
var trackID;
SC.get("/tracks", {
q: query,
// created_at: {'from': todayDate},
//limit: 7
}, function(tracks) {
tracks.sort(function(a,b){
return a.created_at < b.created_at;
});
//Adding track name and user URL to soundcloud div
trackID = tracks[0].id;
//console.log (trackID);
//these have been created using soundclouds API user guide lines
document.getElementById("track").innerHTML = "<a href=" +tracks[0].permalink_url+ ">" +tracks[0].title+"</a>";
document.getElementById("trackUser").innerHTML = tracks[0].user.username;
SC.stream("/tracks/"+ trackID, function(sound) {
document.getElementById('play').addEventListener("click", function(){
sound.play();
});
document.getElementById('stop').addEventListener("click", function(){
sound.stop();
});
document.getElementById('pause').addEventListener("click", function(){
sound.pause();
});
});
});
}
//this function hides/ shows the avaliable tests
function hide(){
var el = document.getElementById('hidetest');
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = 'block';
}
}
// document.getElementById('divbtn').addEventListener('click',function(e){
// document.getElementById('hidetest').style.display = 'block';
// });