View difference between Paste ID: QSRrs6vQ and ax63LLTW
SHOW: | | - or go back to the newest paste.
1
// ==PREPROCESSOR==
2
// @name "Youtube Radio"
3
// @author "Mire777"
4
// @feature "v1.4"
5
// @feature "watch-metadb"
6
// ==/PREPROCESSOR==
7
8
//Properties
9
YT_PL = window.GetProperty("YT  Playlist", "0");
10
YT_AUTO = window.GetProperty("YT  Auto", "0");
11
YT_TRACK = window.GetProperty("YT Track", "");
12
STATION = window.GetProperty("YT  Station", "");
13
SIM_ART = window.GetProperty("YT Similar", "");
14
YT_URL = window.GetProperty("YT URL", "");
15
art = window.GetProperty("YT   Artist Variety (1-20)", "20");
16
sng = window.GetProperty("YT   Song  Hotness (1-20)", "20");
17
tag = window.GetProperty("YT   Tag  Hotness (1-100)", "27");
18
pls = window.GetProperty("FB Playlist", "YT Radio");
19
20
var MF_GRAYED = 0x00000001;
21
var MF_STRING = 0x00000000;
22
var IDC_ARROW = 32512;
23
var IDC_HAND = 32649;
24
25
function RGB(r, g, b) {
26
return (0xff000000 | (r << 16) | (g << 8) | (b));
27
}
28
29
function RGBA(r, g, b, a) {
30
return ((a << 24) | (r << 16) | (g << 8) | (b));
31
}
32
33
function on_colors_changed() {
34
p.colors_changed();
35
}
36
37
function on_selection_changed() {
38
p.item_focus_change();
39
}
40
41
function on_playlist_switch() {
42
set_focus0(); //Check Playlist
43
}
44
45
function on_playback_new_track() {
46
p.item_focus_change();
47
LOAD_ART();
48
}
49
50
function on_playback_dynamic_info_track() {
51
p.item_focus_change();
52
}
53
54
function on_playback_stop() {
55
p.item_focus_change();
56
}
57
58
function on_item_focus_change() {
59
p.item_focus_change();
60
}
61
62
function on_mouse_leave() {
63
}
64
65
function on_mouse_rbtn_up(x, y) {
66
p.rbtn_up(x, y);
67
return true;
68
}
69
70
//Playlist
71
function GetPlaylistID(Playlist_Name)
72
{
73
for (var i = 0; i < fb.PlaylistCount; i++)
74
{
75
if (fb.GetPlaylistName(i) == Playlist_Name)
76
{
77
return i;
78
}
79
}
80
81
//Create playlist if it doesn't exist
82
fb.CreatePlaylist(fb.PlaylistCount, Playlist_Name);
83
return i;
84
}
85
86
//Playlist(Check)
87
function GetPlaylistID0(Playlist_Name)
88
{
89
for (var i = 0; i < fb.PlaylistCount; i++)
90
if (fb.GetPlaylistName(i) == Playlist_Name)
91
{
92
return i;
93
}
94
}
95
96
//Focus on playlist(Check)
97
function set_focus0()
98
{   
99
if (pls>"")
100
{
101
var PL_NM = (GetPlaylistID0(pls + " ["+ STATION +"]"));
102
if (fb.ActivePlaylist == PL_NM) {YT_PL = 1; window.SetProperty("YT  Playlist", "1");}
103
else
104
{YT_PL = 0; window.SetProperty("YT  Playlist", "0");}
105
}
106
}
107
108
//Focus on playlist(YT Radio)
109
function set_focus()
110
{   
111
if (pls>"")
112
fb.ActivePlaylist = (GetPlaylistID(pls + " ["+ STATION +"]"));
113
}
114
115
//Focus on playlist(Same Video)
116
function set_focus2()
117
{   
118
if (pls>"")
119
fb.ActivePlaylist = (GetPlaylistID(pls + " [Same Video]"));
120
}
121
122
//Focus on playlist(Search Videos)
123
function set_focus3()
124
{   
125
if (pls>"")
126
fb.ActivePlaylist = (GetPlaylistID(pls + " [Search Videos]"));
127
}
128
129
//Focus on playlist(Popular Tracks)
130
function set_focus4()
131
{   
132
if (pls>"")
133
fb.ActivePlaylist = (GetPlaylistID(pls + " [Tracks: "+ p.artist +"]"));
134
}
135
136
//Panel
137
     function panel(name, features) {
138
      this.item_focus_change = function() {
139
        if (!this.metadb_func) return;
140
        switch(this.selection_mode) {
141
        case 0:
142
        this.metadb = fb.GetSelection();
143
        break;
144
        case 1:
145
        this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
146
        break;
147
        case 2:
148
        this.metadb = fb.GetFocusItem();
149
        break;
150
		}
151
		if (this.metadb) on_metadb_changed();
152
	}
153
154
//Metadb
155
this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
156
157
//Size	
158
    this.size = function() {
159
    this.w = window.Width;
160
    this.h = window.Height;
161
}
162
163
//Move	
164
    this.move = function(x, y) {
165
    this.mx = x;
166
    this.my = y;
167
}
168
169
//Menu	
170
    this.rbtn_up = function(x, y) {
171
    var _menu = window.CreatePopupMenu();
172
    var idx;
173
    switch(true) {
174
            case typeof th == "object":
175
            case typeof im == "object":
176
177
on_item_focus_change()            
178
if (pls>"")
179
{					
180
if(YT_AUTO==1) _menu.AppendMenuItem(MF_STRING, 1902, "Youtube Radio");
181
if(YT_AUTO==0) _menu.AppendMenuItem(MF_STRING, 1903, "Youtube Radio");
182
_menu.CheckMenuItem(1902, YT_AUTO?1:0);
183
184
_menu.AppendMenuSeparator();
185
{
186
if(YT_PL==1 && YT_AUTO==1 && STATION>"") {_menu.AppendMenuItem(MF_STRING, 22, "Get Next Video");}
187
else
188
{_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Get Next Video");}
189
190
_menu.AppendMenuItem(MF_STRING, 401, "Search Videos");
191
192
_menu.AppendMenuSeparator();
193
194
_menu.AppendMenuItem(MF_STRING, 1914, "Start Radio Station");
195
196
p.artist = p.eval("%artist%");
197
if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Same Artist Station");}
198
else
199
{_menu.AppendMenuItem(MF_STRING, 1915, "Same Artist Station");}
200
201
_menu.AppendMenuSeparator();
202
203
p.artist = p.eval("%artist%");
204
if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Open Same Video");}
205
else
206
{_menu.AppendMenuItem(MF_STRING, 403, "Open Same Video");}
207
208
/*p.artist = p.eval("%artist%");
209
if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Find in Browser");}
210
else
211
{_menu.AppendMenuItem(MF_STRING, 404, "Find in Browser");}*/
212
213
p.artist = p.eval("%artist%");
214
if (p.artist == "" || p.artist == "?") {_menu.AppendMenuItem(MF_STRING| MF_GRAYED, 2000, "Popular Tracks...");}
215
else
216
{_menu.AppendMenuItem(MF_STRING, 1916, "Popular Tracks...");}
217
218
_menu.AppendMenuSeparator();
219
220
_menu.AppendMenuItem(MF_STRING, 9, "Properties...");
221
}				
222
}
223
} 
224
if (pls=="") {_menu.AppendMenuItem(MF_STRING, 9, "Please Set: (FB Playlist)");}
225
if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
226
		
227
        idx = _menu.TrackPopupMenu(x, y);
228
        switch(idx) {
229
           
230
           case 9:
231
				window.ShowProperties();
232
				break;
233
                
234
           case 10:
235
				window.ShowConfigure();
236
				break;
237
                
238
           case 22:
239
                set_focus(); //Focus on playlist
240
				LOAD_ART();
241
				break;
242
                
243
           case 401:
244
                set_focus3(); //Focus on playlist
245
				fb.RunMainMenuCommand("View/Youtube Source");
246
				break;
247
                
248
           case 403:
249
                this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
250
                set_focus2(); //Focus on playlist
251
                LOAD_SAME();
252
				break;
253
			
254
           case 404:
255
                p.artist = p.eval("%artist% %title%");
256
                p.browser("http://www.youtube.com/results?search_query=" + encodeURIComponent(p.artist));
257
                break;
258
           
259
           case 1902:
260
                YT_AUTO = 0;
261
                window.SetProperty("YT  Auto", "0");
262
                break;
263
       
264
           case 1903:
265
                YT_AUTO = 1;
266
                window.SetProperty("YT  Auto", "1");
267
                break; 
268
           
269
           case 1914:
270
                var Start;
271
                Start = this.InputBox("Type Artist to Start Station\n\n( *genre - will play genre station)", "Youtube Radio", "");
272
                if (Start=="")
273
                {
274
                }
275
                else
276
                {
277
                YT_PL = 1;
278
                window.SetProperty("YT  Playlist", "1");
279
                YT_AUTO = "1"
280
                window.SetProperty("YT  Auto", "1");
281
                STATION = Start;
282
                window.SetProperty("YT  Station", Start);
283
                set_focus(); //Focus on playlist
284
                LOAD_ART();
285
                }
286
                break;
287
            
288
           case 1915:
289
                this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
290
                p.artist = p.eval("%artist%");
291
                if (p.artist == "" || p.artist == "?") return;
292
                STATION = p.artist;
293
                window.SetProperty("YT  Station", p.artist);
294
                YT_PL = 1;
295
                window.SetProperty("YT  Playlist", "1");
296
                YT_AUTO = "1"
297
                window.SetProperty("YT  Auto", "1");
298
                set_focus(); //Focus on playlist
299
                LOAD_ART();
300
                break;
301
        
302
           case 1916:
303
                set_focus4(); //focus on playlist
304
                POP_TRACKS();
305
                break;
306
                
307
               }
308
		        _menu.Dispose();
309
	         }
310
311
//Features init
312
    this.features_init = function() {
313
    for (i = 0; i < this.features.length; i++) {
314
    switch(this.features[i]) {
315
    case "metadb":
316
    this.selection_mode = 1;
317
    break;
318
    case "remap":
319
    this.artist_tf = ("%artist%");
320
    break;
321
			}
322
		}
323
	}
324
	
325
    this.check_feature = function(f) {
326
    for (i = 0; i < this.features.length; i++) {
327
    if (this.features[i] == f) return true;
328
    }
329
    return false;
330
    }
331
332
//Eval
333
	this.eval = function(tf) {
334
    if (!this.metadb || tf == "") return "";
335
    if (fb.IsPlaying && this.metadb.RawPath.indexOf("file://") != 0) {
336
    return fb.TitleFormat(tf).Eval();
337
    } else {
338
    return fb.TitleFormat(tf).EvalWithMetadb(this.metadb);
339
    }
340
	}
341
	
342
//Console Msg
343
    this.console = function(message) {
344
    this.name = "Youtube Radio"	
345
    fb.trace(this.name + ": " + message);
346
    }
347
	
348
//Trim
349
    String.prototype.trim = function() {
350
    return this.replace(/^\s+|\s+$/g, "");
351
    }    
352
353
//Input Box    
354
	this.InputBox = function(prompt, title, value) {
355
    prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
356
    title = title.replace(/"/g, '" + Chr(34) + "');
357
    value = value.replace(/"/g, '" + Chr(34) + "');
358
    var temp_value = this.vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")');
359
    if (typeof temp_value == "undefined") return value;
360
    if (temp_value.length == 254) this.MsgBox("Your entry was too long and will be truncated.\n\nSee the WSH panel mod script discussion thread on hydrogenaudio forums for help.", 0, "Youtube Radio");
361
    return temp_value.trim();
362
	}
363
364
//Msg Box	
365
	this.MsgBox = function(prompt, buttons, title) {
366
    prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
367
    title = title.replace(/"/g, '" + Chr(34) + "');
368
    return this.vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")');
369
	}
370
371
//Browser	
372
	this.browser = function(command) {
373
    if (!this.run(command)) this.MsgBox("Unable to launch your default browser.", 0, "Youtube Radio");
374
	}
375
376
//Run Command	
377
	this.run = function(command) {
378
    try {
379
    this.WshShell.Run(command);
380
    return true;
381
    } catch(e) {
382
    return false;
383
    }
384
	}
385
	
386
//futures	
387
    this.metadb_func = typeof on_metadb_changed == "function";
388
	this.features = features;
389
	this.dui = window.InstanceType;
390
	this.metadb = fb.GetFocusItem();
391
	this.WshShell = new ActiveXObject("WScript.Shell");
392
	this.fso = new ActiveXObject("Scripting.FileSystemObject");
393
	this.vb = new ActiveXObject("ScriptControl");
394
	this.vb.Language = "VBScript";
395
	this.artist_tf = "%artist%";
396
	this.features_init();
397
    this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
398
    if (fb.GetFocusItem())
399
    {this.artist = fb.TitleFormat(this.artist_tf).EvalWithMetadb(this.metadb);}
400
401
}
402
403
//YT NAMES-------------------------------------------------
404
405
//Clean Art Name
406
CLEAN_ART_NAME = function (t)
407
{   try
408
    {
409
    return t.replace(/about:\//,"").replace("music/","").replace("/_/"," - ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/","").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'");
410
    } catch (e) {}
411
}
412
413
//Clean Track Name
414
CLEAN_TRACK_NAME = function (t)
415
{   try
416
    {
417
    return t.replace(/about:\//,"").trim().split(" (")[0].replace(" (","").split(" [")[0].replace(" [","").split(" {")[0].replace(" {","").split(", ")[0].replace(", ","").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace("%27","'").replace(" 01-","").replace(" 02-","").replace(" 03-","").replace(" 04-","").replace(" 05-","").replace(" 06-","").replace(" 07-","").replace(" 08-","").replace(" 09-","").replace("09  ","").replace("08  ","").replace("07  ","").replace("06  ","").replace("05  ","").replace("04  ","").replace("03  ","").replace("02  ","").replace("01  ","").replace("00  ","").replace("01 ","").replace("02 ","").replace("03 ","").replace("04 ","").replace("05 ","").replace("06 ","").replace("07 ","").replace("08 ","").replace("09 ","").replace("00 ","").replace(".mp","").replace(" - Remastered ","").replace(" - Remastered","").replace("- "," ").replace(decodeURIComponent(SIM_ART) + " -"," ").replace(decodeURIComponent(SIM_ART) + " - "," ").replace(" - Live ","").replace(" - Live","").replace(" Pt.1","").replace(" - Demo;2 Digital Remaster 66  ","").replace(" - Demo;2 Digital Remaster","").replace(" - Demo;","").replace(" - Demo","").replace("Digital Remaster","").replace("Original-  ","").replace("Original- ","").replace("Original-","").replace(" - Vocal Version","").replace(" Mega-Mix","").replace("Mega-Mix","").replace(" - Original Mix","").replace(" Pop Radio Edit","").replace(" Radio Edit","").replace(" - Single Version","").replace(" - Edited Version","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace("- ","").replace(" - Extended Version","").replace(" -Remaster","").replace("`","'").replace(". "," ").replace(" Version","").replace(" edit","").replace(" - Edit","").replace("  Simple Mix","").replace("  Almighty Mix","").replace(" - Vocal","").replace(" Vocal","").replace("  Remix","").replace("  Extended Version","").replace(" - Explicit Version","").replace("- Explicit Version","").replace(" Explicit Version","").replace("Explicit Version","").replace(" Anthology", "").replace("The " + decodeURIComponent(SIM_ART), " ").replace(" - Survival Remix","").replace(" Radio Mix","").replace(" Survival Remix","").replace("Survival Remix","").replace(decodeURIComponent(SIM_ART) + "-"," ").replace(decodeURIComponent(SIM_ART)," ").replace(" Club Mix","").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("_"," ").replace("  wwwi.info","").replace(" Edit","").replace("live","").replace("Single","").replace("vk.com/xclusives zone ","").replace("  Acoustic","").replace("Remix","").replace("Part&","").replace("  +","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" % ","").replace(" Live;0 2","").replace("  Live;0 2","").replace("Live;0 2","").replace(' /"/"',"").replace(" -0","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("%","").replace("  Alternate Mix","").replace("Live","").replace(" Alternate Mix","").replace("Alternate Mix","").replace("-0","").replace("  remastered","").replace(" // СЛУШАЮТ:","").replace("www.KLAUSOM.lt","").replace("-;-Bit Digital Remaster","").replace(" :","").replace("-1  Remaster","").replace("  Genuine Album","").replace("  www.rsmp.com","").replace(" www.rsmp.com","").replace("www.rsmp.com","").replace("Instrumental","").replace(" Instrumental","").replace("www.SongsLover.pk","").replace(" Genuine Album","").replace("Album","").replace("Remaster","").replace("Lyrics","").replace("w/lyrics","").replace(" -","").replace("  Radio","").replace("0%","").replace("remaster","").replace(" Lyrics","").split(" | '' |")[0].replace(" | '' |","").split(" |")[0].replace(" |","").split("|")[0].replace("|","").split("| On:")[0].replace("| On:","").split(" feat")[0].replace(" feat","").split(" ft.")[0].replace(" ft.","").split(" Feat.")[0].replace(" Feat","").split("Greatest Hits Megamix")[0].replace("Greatest Hits Megamix","").split("Lyrics")[0].replace("Lyrics","").split("Lyric")[0].replace("Lyric","").split("www.")[0].replace("www.","").split(";Feat")[0].replace(";Feat","").trim();
418
    } catch (e) {}
419
}
420
421
//Clean Genre Name
422
CLEAN_GENRE_NAME = function (t)
423
{   try
424
    {
425
    return t.replace(/about:\//,"").replace("music/","").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("free-music-downloads","").replace("/+similar?page=2","").replace("/+events","").replace("/+wiki","").replace("-+","").replace("/+albums","").replace("/+tags","").replace("/+images","").replace("/journal","").replace("/charts","").replace("/images","").replace("/listeners","").replace("/similar?page=17","").replace("/news","").replace("/groups","").replace("/albums","").replace("/videos","").replace("/tracks","").replace("/similar","").replace("/tags","").replace("noredirect/","").replace("listeners/+tracks","").replace("videos/+tracks","").replace("/+videos/","").replace("?page=1","").replace("?page=8","").replace("?page=5","").replace("?page=7","").replace("?page=9","").replace("?page=8","").replace(" wiki/edit","").replace("/ similar","").replace("?page=","'").replace("/ charts","'").replace("-","").replace("%2F%E3%82%A4%E3%83%95%E3%83%BB%E3%83%8E%E3%83%83%E3%83%88%E3%83%BB%E3%83%95%E3%82%A9%E3%83%BE3%83%BB%E3%83%A6%E3%83%BC","").replace("Ajoutez ce titre sur Deezer exclusivement sur www.hotmixradio.fr","").replace("www.Hituri.net","").replace("%E3%81%97%E3%82%83%E3%81%AB%E3%82%80%E3%81%AB%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF","").replace("%B81%E3%82%B7%E3%82%A7%E3%82%A4%E3%82%AF%EF%B81","").replace("%E4%BD%95%E3%82%88%E3%82%8A%E3%82%82%E5%83%95%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E4%BD%95%E3%82%88%E3%82%8A","").replace("%E3%82%82%E5%90%9B%E3%82%89%E3%81%97%E3%81%8F","").replace("%D0%91%D1%8D0%B5%D1%82 %D0%BF%D0%BE %D0%B3%D0%BB%D0%B0%D0%B7%D0%B0%D0%BC","").replace("%E3%83%9E%E3%82%A4%E3%83%BB%E3%83%9E3%83%87%E3%82%A3","").replace("%D0%9B%D0%B5%D1%82%D0%B5%D1%82%D1%8C","").replace("%2F%2F %D0%A1%D0%9B%D0%A3%D0%A8%D0%90%D0%AE%D0%A2","").replace("%D0%9F%D0%BE%D0%BF-%D0%A5%D0%B8%D1%82","").replace("/","").split("tag")[0].split("hype")[0].split("events")[0];
426
    } catch (e) {}
427
}
428
429
//*********************YT RADIO START**********************
430
431
//SIMILAR--------------------------------------------------
432
this.LOAD_ART = function()
433
{     if (YT_AUTO=="1")
434
      if (YT_PL=="1")
435
    
436
    { var randomnumber=Math.floor(Math.random()*art)
437
      var a=randomnumber;
438
        if (STATION == "" || STATION == "?") return;
439
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
440
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(STATION) + "/+similar"+ "?page=" + a, true);
441
		this.xmlhttp.send();
442
		this.xmlhttp.onreadystatechange = function() {
443
        if (this.xmlhttp.readyState == 4) {
444
        if (this.xmlhttp.status == 200) {
445
        var text = this.xmlhttp.responsetext;
446
        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
447
        this.doc.open();
448
        var div = this.doc.createElement("div");
449
        div.innerHTML = text;
450
        var data = div.getElementsByTagName("a");
451
        var urls = [];
452
453
for (i = 0; i < data.length; i++) {
454
if (data[i].href.indexOf("about:/music/") == 0) urls.push(CLEAN_ART_NAME(data[i].href));   
455
}
456
457
//select random URL
458
var randomnumber = Math.floor(Math.random()*(20-50)+50);
459
do{
460
randomnumber = Math.floor(Math.random()*(20-50)+50);
461
} while(randomnumber%2!=1);
462
i=randomnumber;
463
464
{
465
466
//Start with urls[i]
467
if (urls[i] > "") 
468
{
469
//p.console("" + urls[i]);
470
SIM_ART = window.SetProperty("YT Similar", urls[i]);
471
SIM_ART = urls[i];
472
window.SetProperty("YT Similar", urls[i]);
473
}
474
else
475
{
476
SIM_ART = window.SetProperty("YT Similar", "");
477
SIM_ART = "";
478
window.SetProperty("YT Similar", "");
479
}                   
480
}
481
            
482
        this.doc.close();
483
        if (STATION.indexOf("*")== 0) {LOAD_GENRE();}
484
        else
485
        if (SIM_ART == "" || SIM_ART == "?") {LOAD_ART();}
486
        else
487
        LOAD_TRACK();
488
        } else {
489
        if (STATION.indexOf("*")== 0) {LOAD_GENRE();}
490
        else
491
        if (this.xmlhttp.status == 404) {p.console("HTTP error: " + this.xmlhttp.status); LOAD_ART();}
492
                }
493
			}
494
		}
495
	}                             
496
}
497
498
//TRACK----------------------------------------------------
499
this.LOAD_TRACK = function()
500
{
501
     
502
    {var randomnumber=Math.floor(Math.random()*sng)
503
     var a=randomnumber;
504
        if (SIM_ART == "" || SIM_ART == "?") return;
505
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
506
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(SIM_ART) + "/+tracks" + "?page=" + a, true);
507
		this.xmlhttp.send();
508
		this.xmlhttp.onreadystatechange = function() {
509
        if (this.xmlhttp.readyState == 4) {
510
        if (this.xmlhttp.status == 200) {
511
        var text = this.xmlhttp.responsetext;
512
        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
513
        this.doc.open();
514
        var div = this.doc.createElement("tr");
515
        div.innerHTML = text;
516
        var data = div.getElementsByTagName("td");
517
        var urls = [];
518
519
for (i = 0; i < data.length; i++) {
520
if (data[i].title) urls.push(CLEAN_TRACK_NAME(data[i].title));
521
}
522
523
//select random URL
524
var randomnumber = Math.floor(Math.random()*Math.max(urls.length));
525
i=randomnumber;
526
527
{
528
529
//Start with urls[i]
530
if (urls[i] > "") 
531
{
532
p.console("" + SIM_ART + " - " + urls[i]);
533
534
YT_TRACK = window.SetProperty("YT Track", urls[i]);
535
YT_TRACK = urls[i];
536
window.SetProperty("YT Track", urls[i]);
537
}
538
else
539
{
540
YT_TRACK = window.SetProperty("YT Track", "");
541
YT_TRACK = "";
542
window.SetProperty("YT Track", "");
543
}
544
}
545
546
        this.doc.close();
547
        if (YT_TRACK == "" || YT_TRACK == "?") {LOAD_ART();}
548
        else
549
        set_focus(); //focus on playlist
550
        do_youtube_search1(decodeURIComponent(SIM_ART), decodeURIComponent(YT_TRACK));
551
        } else {
552
        p.console("HTTP error: " + this.xmlhttp.status);
553
        if (STATION.indexOf("*")== 0) {LOAD_GENRE();}
554
        else
555
        if (this.xmlhttp.status == 404) {LOAD_ART();}
556
                }
557
			}
558
		}
559
	}
560
}
561
562
//POPULAR TRACKS----------------------------------------------------
563
this.POP_TRACKS = function()
564
{       p.artist = p.eval("%artist%");
565
566
    {   if (p.artist == "" || p.artist == "?") return;
567
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
568
		this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(p.artist) + "/+tracks" + "?page=1", true);
569
		this.xmlhttp.send();
570
		this.xmlhttp.onreadystatechange = function() {
571
        if (this.xmlhttp.readyState == 4) {
572
        if (this.xmlhttp.status == 200) {
573
        var text = this.xmlhttp.responsetext;
574
        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
575
        this.doc.open();
576
        var div = this.doc.createElement("tr");
577
        div.innerHTML = text;
578
        var data = div.getElementsByTagName("td");
579
        var urls = [];
580
    
581
for (i = 0; i < data.length; i++) {
582
if (data[i].title) urls.push(CLEAN_TRACK_NAME(data[i].title));
583
}
584
585
//Select urls[i]
586
for (i = 0; i < urls.length; i++)
587
588
{
589
//Start with urls[i]
590
if (urls[i] > "") 
591
do_youtube_search1(decodeURIComponent(p.artist), urls[i]);
592
}
593
        this.doc.close();
594
        } else {
595
        p.console("HTTP error: " + this.xmlhttp.status);
596
                }
597
			}
598
		}
599
	}
600
}
601
602
//SAME VIDEO-----------------------------------------------
603
this.LOAD_SAME = function()
604
    {
605
      var artist0 = p.eval("%artist%");
606
      var title0 = p.eval("%title%");
607
      if(artist0 > "?" && title0 > "?") {set_focus2(); do_youtube_search1(decodeURIComponent(artist0), decodeURIComponent(title0));}
608
}
609
610
//GENRE----------------------------------------------------
611
this.LOAD_GENRE = function()
612
{     if (STATION.indexOf("*")== 0)
613
   
614
    { var randomnumber=Math.floor(Math.random()*tag)
615
      var a=randomnumber;
616
        if (STATION == "" || STATION == "?") return;
617
		if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
618
		this.xmlhttp.open("GET", "http://www.last.fm/music/+tag/" + encodeURIComponent(STATION).replace("*","") + "?page=" + a, true);
619
		this.xmlhttp.send();
620
		this.xmlhttp.onreadystatechange = function() {
621
        if (this.xmlhttp.readyState == 4) {
622
        if (this.xmlhttp.status == 200) {
623
        var text = this.xmlhttp.responsetext;
624
        if (!this.doc) this.doc = new ActiveXObject("htmlfile");
625
        this.doc.open();
626
        var div = this.doc.createElement("li");
627
        div.innerHTML = text;
628
        var data = div.getElementsByTagName("a");
629
        var urls = [];
630
    
631
for (i = 0; i < data.length; i++) {
632
    if (data[i].className.indexOf("name") == 0)
633
    if (data[i].href.indexOf("about:/music/") == 0) urls.push(CLEAN_GENRE_NAME(data[i].href));
634
}
635
636
//select random URL
637
var randomnumber = Math.floor(Math.random()*(0-9)+9);
638
do{
639
randomnumber = Math.floor(Math.random()*(0-9)+9);
640
} while(randomnumber%2!=0);
641
642
i=randomnumber;
643
644
{
645
646
//Start with urls[i]
647
if (urls[i] > "") 
648
{
649
//p.console("" + urls[i]);
650
SIM_ART = window.SetProperty("YT Similar", urls[i]);
651
SIM_ART = urls[i];
652
window.SetProperty("YT Similar", urls[i]);
653
}
654
else
655
{
656
SIM_ART = window.SetProperty("YT Similar", "");
657
SIM_ART = "";
658
window.SetProperty("YT Similar", "");
659
}
660
}
661
        this.doc.close();
662
        if (SIM_ART == "" || SIM_ART == "?") {LOAD_GENRE();}
663
        else
664
        LOAD_TRACK();
665
        } else {
666
        p.console("HTTP error: " + this.xmlhttp.status);
667
        if (this.xmlhttp.status == 404) {LOAD_GENRE();}
668
                }
669
			}
670
		}
671
	}
672
}
673
674
//LOAD YOUTUBE VIDEO---------------------------------------
675
strip_title = function (t1, t2)
676
{
677
    try
678
    {
679
        if (t1 == t2)
680
        return t1;
681
        if (t1.match(RegExp(t2 + "( and | & )", "i")))
682
        return t1;
683
        var a = "(by the |by: |by |of |the |feat. |ft. |)";
684
        var b = "( feat.| ft.|)";
685
        var t3 = "";
686
        if (!t2.match(/^the /i))
687
        {
688
        t3 = t1.replace(RegExp("[^a-z\\d_)\\]\"]*(" + a + t2 + b + ")[^a-z\\d_(\\[\"]*","gi")," - ").replace(/^[^a-z()\[\]\d\"]*|[^a-z()\[\]\d\"]*$/gi, "");
689
        }
690
        else
691
        {
692
        var t4 = t2.replace(/^the /i, "")
693
        t3 = t1.replace(RegExp("[^a-z\\d_)\\]\"]*(" + a + t4 + b + ")[^a-z\\d_(\\[\"]*","gi")," - ").replace(/^[^a-z()\[\]\d\"]*|[^a-z()\[\]\d\"]*$/gi, "");
694
        }
695
        return t3.match(/\S/) ? t3 : t1;
696
    }
697
    catch (e)
698
    {
699
    return t1;
700
    }
701
}
702
703
convert = function(min)
704
{
705
    var parts = min.split(':'),
706
    minutes = +parts[0],
707
    seconds = +parts[1];
708
    return minutes * 60 + seconds;
709
}
710
711
strip = function (t)
712
{
713
    try
714
    {
715
    t = t.replace(/[\.,\!\?\:;'"\-_]/g,"").toLowerCase();
716
    return t;
717
    } catch (e)
718
    {}
719
}
720
721
clean = function (t)
722
{
723
    try
724
    {
725
    return t.replace(/'/g, "’").toLowerCase();
726
    } catch (e) {}
727
}
728
729
youtube_search = function (state_change_callback, p_on_search_finished_callback)
730
{
731
        this.xmlhttp = null;
732
        this.http_callback_funct = null;
733
        this.ready_state_change_callback = state_change_callback;
734
        this.search_done = false;
735
        this.on_search_finished_callback = p_on_search_finished_callback;
736
        this.yt_link;
737
        this.search_artist;
738
        this.search_title;
739
        this.metadata;
740
741
    this.on_state_change = function ()
742
    {
743
    if (this.xmlhttp != null && this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200 && this.http_callback_funct != null)
744
    this.http_callback_funct();
745
    }
746
747
    this.StartSearch = function (p_artist, p_title, p_extra_metadata)
748
    {
749
        this.search_artist = p_artist;
750
        this.search_title = p_title;
751
        this.metadata = p_extra_metadata;
752
        this.http_callback_funct = null;
753
        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
754
755-
        var URL = "http://www.youtube.com/results?search_query=" + encodeURIComponent(p_artist + " " + p_title) + "&lclk=video&filters=video";
755+
        var URL = "http://www.youtube.com/results?search_query=" + encodeURIComponent(p_artist + " " + p_title);
756
757
        this.http_callback_funct = this.AnalyseSearch;
758
        this.xmlhttp.open("GET", URL);
759
        this.xmlhttp.onreadystatechange = this.ready_state_change_callback;
760
        this.xmlhttp.send();
761
    }
762
763
    this.AnalyseSearch = function ()
764
    {
765
        var text = this.xmlhttp.responsetext;
766
        var doc = new ActiveXObject("htmlfile");
767
        doc.open();
768
        var div = doc.createElement("div");
769
        div.innerHTML = text;
770
        var data = div.getElementsByTagName("a");
771
        var url = "";
772
        var first_match;
773
774
        re_test:
775
776
        for (var i = 0; i < data.length; i++)
777
        {
778
        if (data[i].href.indexOf("about:/watch?v=") == 0)
779
           {
780
                i++; //link
781
782
//check if track exist?                
783
//if((data[i].title.toLowerCase()).indexOf(decodeURIComponent(SIM_ART.toLowerCase()).split(" ")[0]) > 0)
784
//if((data[i].title.toLowerCase()).indexOf(decodeURIComponent(YT_TRACK.toLowerCase()).split(" ")[0]) > 0)
785
//if((data[i].title.toLowerCase()).indexOf(decodeURIComponent(YT_TRACK.toLowerCase()).split(" ")[1]) > 0)
786
//if((data[i].title.toLowerCase()).indexOf(decodeURIComponent(YT_TRACK.toLowerCase()).split(" ")[2]) > 0)
787
788
            //Find Title
789
            {
790
            var st = text.indexOf( data[i].href.replace("about:/watch?", "") );
791
            var str = "dir=\"ltr\">";
792
            st = text.indexOf(str, st) + str.length;
793
            var et = text.indexOf("</a>", st);
794
            var youtube_title = text.substr(st, et - st);
795
            var Y_Title = youtube_title.replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&").replace("&#39;", "'").replace("&quot;", "''").replace("&amp;", "&");
796
            //p.console("Title: " + Y_Title);
797
            }
798
                
799
            //Find minutes
800
            var s = text.indexOf( data[i].href.replace("about:/watch?", "") );
801
            var str = "<span class=\"video-time\">";
802
            s = text.indexOf(str, s) + str.length;
803
            var e = text.indexOf("</span>", s);
804
            var length = text.substr(s, e - s);
805
            length = convert(length);
806
            length = length ? length : "";
807
            if (!first_match)
808
809
            {                   
810
            // title stripped of artist name if same as search_artist
811
            var stripped_title = strip_title(Y_Title, this.search_artist); 
812
            first_match = "3dydfy://www.youtube.com/watch?" + (this.metadata ? this.metadata + "&" : "") + "fb2k_title=" + encodeURIComponent(stripped_title) + "&3dydfy_alt_length=" + encodeURIComponent(length) + "&fb2k_artist=" + encodeURIComponent(this.search_artist) + "&" + data[i].href.replace("about:/watch?", "");
813
            }
814
            //3dydfy
815
            if (!this.IsGoodMatch(Y_Title))
816
            continue;
817
818
            url = "3dydfy://www.youtube.com/watch?" + (this.metadata ? this.metadata + "&" : "") + "fb2k_title=" + encodeURIComponent(this.search_title) + "&3dydfy_alt_length=" + encodeURIComponent(length) + "&fb2k_artist=" + encodeURIComponent(this.search_artist) + "&" + data[i].href.replace("about:/watch?", "");
819
            break;
820
            }
821
        }
822
823
        if (!url.length)
824
        url = first_match;
825
826
        this.yt_link = url;
827
828
        doc.close();
829
830
        this.on_search_finished_callback(url, this.search_artist, this.search_title);
831
        }
832
833
        this.IsGoodMatch = function (video_name)
834
        {
835
        var clean_vid_name = clean(strip(video_name));
836
        var clean_artist = clean(strip(this.search_artist));
837
        var clean_title = clean(strip(this.search_title));
838
839
        if (clean_vid_name.indexOf(clean_artist) != -1 && clean_vid_name.indexOf(clean_title) != -1 && clean_vid_name.indexOf("full album") == -1)
840
        {
841
            //p.console("GOOD MATCH");
842
            return true;
843
        }
844
        else
845
        {
846
            //p.console("BAD MATCH");
847
            return false;
848
        }
849
    }
850
851
}
852
853
//Call Search
854
do_youtube_search1 = function (p_artist, p_title)
855
    {
856
    var yt_search1 = new youtube_search(function ()
857
    {
858
    yt_search1.on_state_change();
859
    }, on_youtube_search1_done);
860
    yt_search1.StartSearch(p_artist, p_title);
861
    }
862
863
on_youtube_search1_done = function (link, p_artist, p_title)
864
{
865
var url2="";
866
url2 = link;
867
if (!url2)
868
{p.console("Track Or Artist - Not Exist!"); LOAD_ART();} 
869
870
if (link && link.length)
871
{
872
            
873
p.console("" + "\"" + link + "\"");
874
YT_URL = window.SetProperty("YT URL", link);
875
var tmppath = p.fso.GetFolder(fb.FoobarPath).ShortPath;
876
var str = tmppath + "\\foobar2000.exe /add ";
877
var go = str + link;
878
p.run(go);
879
}
880
    }
881
//**************************(END)**************************
882
this.artist = "";
883
884
//Set Panels
885
function pan1() { }
886
function pan2(x, y, w, h) { }
887
//---------------------------------------------------------
888
889
//Begin--->
890
var p = new panel("Youtube Radio", ["remap", "metadb"]);
891
var im = new pan2(0, 0, 0, 0);
892
var th = new pan1();
893
894
on_item_focus_change();
895
{
896
}
897
898
function on_metadb_changed() {
899
}
900
901
//Buttons---------------------------------------------------
902
903
var Buttons;
904
905
var g_tooltip = window.CreateTooltip();
906
var g_down = false;
907
908
var btn_down = null;
909
var cur_btn = null;
910
911
ButtonStates = {
912
	normal: 0,
913
	hover: 1,
914
	down: 2
915
}
916
917
function Button(x, y, w, h, img_src, func, tiptext)  {
918
	this.left = x;
919
	this.top = y;
920
	this.w = w;
921
	this.h = h;
922
	this.right = x + w;
923
	this.bottom = y + h;
924
	this.func = func;
925
	this.tiptext = tiptext;
926
	this.state = ButtonStates.normal;
927
	this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
928
	this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
929
	this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
930
	this.img = this.img_normal;
931
	
932
	this.alterImage = function(img_src) {
933
    this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
934
    this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
935
    this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
936
		
937
    this.changeState(this.state);
938
	}
939
	
940
	this.traceMouse = function (x, y) {
941
    var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
942
    if (b)
943
    g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
944
    else
945
    this.changeState(ButtonStates.normal);
946
    return b;
947
	}
948
	
949
	
950
	this.changeState = function (newstate) {
951
    if (newstate != this.state)
952
    window.RepaintRect(this.left, this.top, this.w, this.h);
953
    this.state = newstate;
954
    switch (this.state)
955
    {
956
    case ButtonStates.normal:
957
    this.img = this.img_normal;
958
    break;
959
			
960
    case ButtonStates.hover:
961
    this.img = this.img_hover;
962
    break;
963
			
964
    case ButtonStates.down:
965
    this.img = this.img_down;
966
    break;
967
			
968
    default:
969
    this.img = null;
970
		}
971
	}
972
	
973
	this.draw = function (gr) {
974
    this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
975
	}
976
	
977
	this.onClick = function () {
978
    this.func && this.func(x,y);
979
	}
980
	
981
	this.onMouseIn = function() {
982
    g_tooltip.Text = this.tiptext;
983
    g_tooltip.Activate();
984
	}
985
	
986
	this.onMouseOut = function() {
987
    g_tooltip.Deactivate();
988
	}
989
}
990
991
function buttonsDraw(gr) {
992
	for (i in Buttons) {
993
    Buttons[i].draw(gr);
994
	}
995
}
996
997
function buttonsTraceMouse(x, y) {
998
	var btn = null;
999
	for (i in Buttons) {
1000
    if (Buttons[i].traceMouse(x, y) && !btn)
1001
    btn = Buttons[i];
1002
	}
1003
1004
	return btn;
1005
}
1006
1007
function on_mouse_move(x, y) {
1008
	var btn = buttonsTraceMouse(x, y);
1009
	
1010
	if (btn != cur_btn) {
1011
    cur_btn && cur_btn.onMouseOut();
1012
    btn && btn.onMouseIn();
1013
	}
1014
	
1015
	cur_btn = btn;
1016
}
1017
1018
function on_mouse_lbtn_down(x, y) {
1019
	g_down = true;
1020
	btn_down = cur_btn;
1021
1022
	if (cur_btn) {
1023
    cur_btn.changeState(ButtonStates.down);
1024
	}
1025
}
1026
1027
function on_mouse_lbtn_up(x, y) {
1028
	if (cur_btn) {
1029
    cur_btn.changeState(ButtonStates.hover);
1030
    if( btn_down == cur_btn )
1031
    cur_btn.onClick(x, y);
1032
	}
1033
	g_down = false;
1034
}
1035
1036
function on_mouse_leave() {
1037
	if (cur_btn) {
1038
    cur_btn.changeState(ButtonStates.normal);
1039
	}
1040
}
1041
1042
function on_size() {
1043
	ww = window.Width;
1044
	wh = window.Height;
1045
    window.Repaint();
1046
}
1047
1048
//Background
1049
this.dui = window.InstanceType;
1050
function on_paint(gr) {
1051
	
1052
    if (this.dui) {
1053
    col = window.GetColorDUI(1);
1054
    gr.FillSolidRect(0, 0, ww, wh, col);
1055
    } 
1056
    else
1057
    {
1058
    col = window.GetColorCUI(3);    
1059
    }
1060
1061
	buttonsDraw(gr);
1062
	
1063
}
1064
1065
function RGB(r,g,b) {
1066
return (0xff000000|(r<<16)|(g<<8)|(b)); 
1067
}
1068
1069
function on_colors_changed() {
1070
window.Repaint();
1071
}
1072
1073
//Init Buttons--------------------------------------------
1074
1075
//Custom colour
1076
var custom = RGB(255,255,255);
1077
1078
//Button width
1079
var bw = 24;
1080
1081
//Button height
1082
var bh = 20;
1083
1084
//Button position
1085
var top_margin = -1;
1086
var left_margin = 0;
1087
1088
var image_path0 = window.GetProperty("Button Path", fb.ProfilePath + "image");
1089
var image_path = (image_path0 + "\\");
1090
1091-
//These 2 lines of code lock the panel size.
1091+
//These 2 lines of code lock the panel size
1092
//window.MinWidth = window.MaxWidth = 24;
1093
//window.MinHeight = window.MaxHeight = 20;
1094
1095
1096
Buttons = {
1097
	but1: new Button(left_margin,top_margin,bw,bh, {normal: image_path + "youtube0.png", hover: image_path + "youtube1.png"}, function(){
1098
    p.rbtn_up(24, 17);
1099
    }, "Youtube")
1100
	
1101
}
1102
1103
function on_mouse_rbtn_up(x, y) {
1104
return true;
1105
}