Repository navigation
Expand file tree
/
Copy pathfullpage.js
More file actions
372 lines (344 loc) · 11.8 KB
/
Copy pathfullpage.js
File metadata and controls
372 lines (344 loc) · 11.8 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*!
* HTML5/JS web player Differently imported
* https://chrome.google.com/webstore/detail/differently-imported-for/bnihjdccalbcoienhgcjjlilfdhacdkf
*
* phil / @ / pbarton / .co / .uk
* Copyright 2014, Phil Barton
*
This library is free to use, and always will be however the source is the property of the original developer.
You may make any modifications to the source for your own personal use, but you may not release or offer a
modified copy of this software under any terms of any licence. Modified source code must not be made public.
Any modifications that may be seen as useful or an improvement may be sent to the author for review.
Any inclusion will be made with full credit however inclusion is solely at the discretion of the author.
Who knows, enough mods offered and I can throw a plugin library together. Feel free to code Mlkdrop for me! :)
(Fork Milkshake on Github)
Any components listed specifically as being under the terms of a different License will fall under the
terms of that Licence and no other. These components will be clearly commented within the source code along
with any acknowledgements to original authors.
This library is distributed and free to be modified with the ideal that openness and honesty with code
is the key to security and trust, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
More importantly I hope you enjoy using the App.
* Date: 3rd March 2015. 16.33 GMT
*/
var frameLength = 5; //ms to display
var bg = chrome.extension.getBackgroundPage();
showControl = false;
doShowC = false;
function showCont(){
clearTimeout(showControl);
$( "#controls" ).css({"opacity": 1});
showControl = setTimeout(function(){
$( "#controls" ).fadeTo( "fast" , 0);
},1000);
}
$(document).ready(function() {
showCont();
$('#controls').mouseout(function(){
showCont();
});
$('#controlP').mouseout(function(){
showCont();
});
$('#channel').mouseout(function(){
showCont();
});
$('#vol').mouseout(function(){
showCont();
});
$('#controls').mouseover(function(){
showCont();
});
$('#controlP').mouseover(function(){
showCont();
});
$('#channel').mouseover(function(){
showCont();
});
$('#vol').mouseover(function(){
showCont();
});
$('#controls').mousemove(function(){
showCont();
});
$('#controlP').mousemove(function(){
showCont();
});
$('#channel').mousemove(function(){
showCont();
});
$('#vol').mousemove(function(){
showCont();
});
document.getElementById("lC").addEventListener('change', function() { // onClick for link to display key box
$.cookie("diChPt", $("#lC option:selected").text(), {
expires: 365
});
$.cookie("diChImage", $("#lC option:selected").attr("data-image"), {
expires: 365
});
$.cookie("diChan", $(this).val(), {
expires: 365
}); // Store key for next time.
if (bg.playing) {
clearInterval(disTimer);
setTimeout(function() {
disTimer = setInterval(function() {
getTn();
}, 500);
}, 750);
doPlay();
}
});
if ($.cookie('diKeys') != null) {
$('#newtop').css("display", "none");
$('#top').css("display", "block");
$('#lK').val($.cookie("diKeys"));
$('#lC').val($.cookie("diChan"));
$('#server').val($.cookie("Diserver"));
$('#vol').val( $.cookie("diVol"));
hQ = $.cookie("dihQ");
$('#hQ').val($.cookie("diHq"));
}
document.getElementById("stBut").addEventListener('click', function() { // On Stop Click
$('#plBut').css("background-color", "#222");
$('#stBut').css("background-color", "#000");
chrome.runtime.sendMessage({
play: "0"
}); //Send method play:0 == Stop.
$("#track").text("Stopped");
$.cookie("diChTn", "Stopped", {
expires: 365
});
});
document.getElementById("plBut").addEventListener('click', function() { // on Play click
doPlay();
});
ws = 0;
$(document).keyup(function(e) {
if (e.keyCode == 27) {
doScreenBig(1);
} // esc
});
$(document).dblclick(function() {
doScreenBig(0);
});
document.getElementById("full_screen").addEventListener('click', function() {
doScreenBig(0);
});
document.getElementById("setCBut").addEventListener('click', function() {
if (meltme) {
meltme = false;
} else {
meltme = true;
}
});
function doScreenBig(trigger) {
chrome.windows.getCurrent(function(win) {
chrome.windows.get(win.id, function(chromeWindow) {
if (chromeWindow.state === "fullscreen") {
chrome.windows.update(win.id, {
state: "maximized"
});
} else {
if (trigger != 1) {
chrome.windows.update(win.id, {
state: "fullscreen"
});
}
}
});
});
}
$("#track").html($.cookie("diChTn"));
disTimer = setInterval(function() {
getTn();
}, 1000);
function getTn() {
if(!$('#vol').mousedown()){
$('#vol').val($.cookie("diVol"));
}
chrome.runtime.sendMessage({
play: "3"
});
if(bg.playing){
$("#track").html($.cookie("diChTn") +"<br />" +"<span class='imgBox'>"+$.cookie("diChPic")+"</span>");
}
else{
$("#track").html($.cookie("diChTn") )
}
$('#lC').val($.cookie("diChan"));
//Label some variables
}
});
$(document).ready(function(e) {
$("#vol").on("input change", function() {
$.cookie("diVol", ($('#vol').val()),
{
expires: 365
});
chrome.runtime.sendMessage({
play: "2", //Send method play:2 == Change player parameter
vol: ($('#vol').val())
}); // player.js receives message and volume. does the doo.
// Store volume for next time.
});
analyse_this();
});
function doPlay() {
var checkKey = $.ajax({
type: "get",
url: 'http://listen.di.fm/public3/favorites?' + $('#lK').val(),
statusCode: {
200: function() {
$('#plBut').css("background-color", "#000");
$('#stBut').css("background-color", "#222");
$.cookie("diHq", $('#hQ').val(), {
expires: 365
}); // Store key for next time.
$.cookie("diKeys", $('#lK').val(), {
expires: 365
}); // Store key for next time.
$.cookie("diChan", $('#lC').val(), {
expires: 365
}); // Store key for next time.
$.cookie("premium", "1", {
expires: 365
}); // Store key for next time.
volm = $.cookie("diVol"); // Store key for next time.
chrome.runtime.sendMessage({
key: $('#lK').val(), //Send key to background player
channel: $('#lC').val(), //with channel selection
vol: volm,
server: $('#server').val(),
play: "1"
}); //and method play:1 == Play.
},
403: function() {
$('#plBut').css("background-color", "#000");
$('#stBut').css("background-color", "#222");
$.cookie("diHq", "0", {
expires: 365
}); // Store key for next time.
$.cookie("diKeys", "", {
expires: 365
}); // Store key for next time.
$.cookie("premium", "0", {
expires: 365
}); // Store key for next time.
$.cookie("diChan", $('#lC').val(), {
expires: 365
}); // Store for next time.
volm = $.cookie("diVol"); // Store key for next time.
chrome.runtime.sendMessage({
key: $('#lK').val(), //Send key to background player
channel: $('#lC').val(), //with channel selection
vol: volm,
server: $('#server').val(),
play: "1"
}); //and method play:1 == Play.
}
}
});
}
var z = 0;
var zz = 0;
var j;
var colorshift;
var changes;
var meltme = true;
var thisline;
var bufferLength=2048;
var timeDomain = new Uint8Array(2048);
var freqDomain = new Uint8Array(2048);
var canvasX = 0;
var canvasY = 0;
var drawContext;
var canvas;
function analyse_this() {
canvas = document.getElementById("visualise_screen");
drawContext = canvas.getContext("2d");
go();
}
function go(){
requestAnimationFrame(go);
drawContext.save();
drawContext.clearRect(0, 0, canvasX, canvasY);
canvasX = drawContext.canvas.width = window.innerWidth;
canvasY = drawContext.canvas.height = window.innerHeight;
fakebufferlength = bufferLength - 150; //mp3 has dead frequencies where codec cuts off.
binX = canvasX / (fakebufferlength / 2);
bg.analyser.getByteFrequencyData(freqDomain);
numBins = canvasX / binX
for (i = 0; i < numBins; i++) {
colorshift = 360 / numBins;
value = freqDomain[i];
percent = value / 400; // smaller is taller
height = (canvasY * percent);
offset = canvasY - height;
thisbar = ""
if (meltme) {
thisbar = "hsl(" + (colorshift * i) + ", " + 85 + "%, " + 37 + "%)";
drawContext.fillStyle = thisbar;
} else {
scalec = (50 / (canvasX / binX) * i) + 50;
drawContext.fillStyle = "hsla(0, 0%, " + scalec + "%, 1)";
}
drawContext.fillRect(binX * i, offset, binX, height);
}
thisbar = ""
if (meltme) {
for (j = 0; j < 6; j++) {
thisbar = "hsl(" + (colorshift * i) + ", " + 85 + "%, " + 37 + "%)";
}
drawContext.fillStyle = thisbar;
} else {
scalec = (50 / (canvasX / binX) * i) + 50;
drawContext.fillStyle = "hsla(0, 0%, " + scalec + "%, 1)";
}
//--------------------------------------------------------------------
bg.analyser.getByteTimeDomainData(timeDomain);
drawContext.lineWidth = 2;
if (meltme) {
var change = Math.floor(Math.random() * 100);
if (change < 5) {
thisline = "hsl(" + Math.floor(Math.random() * 360) + ", " + 75 + "%, " + 75 + "%)";
}
} else {
thisline = "#000";
}
drawContext.strokeStyle = thisline;
drawContext.beginPath();
sliceWidth = (canvasX / bufferLength) + 0.008;
x = 0;
for (i = 0; i < bufferLength; i++) {
v = (timeDomain[i] / 128.0);
y = (v * (canvasY / 2 - ((canvasX / 100) * 10)));
if (i == 0) {
drawContext.moveTo(x, y);
} else {
drawContext.lineTo(x, y);
}
x += sliceWidth;
}
drawContext.lineTo(canvas.width, canvas.height / 2);
drawContext.stroke();
if (meltme) {
z++;
if (z > 360) {
z = 0;
zz++;
}
if (zz > 10) {
zz = 3;
}
$('body').css({
'background-color': "hsl(" + (z) + ", " + 75 + "%, " + zz + "%)"
});
} else {
$('body').css({
'background-color': "#555"
});
}
drawContext.restore();
}