-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevf_default.js
1579 lines (1321 loc) · 62.8 KB
/
evf_default.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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Function to display log infos in the browser console */
function myconsole(){
if(evf_debug != true)return true;
myconsole.history = myconsole.history || [];
myconsole.history.push(arguments);
if( arguments[1] == true )
alert ( arguments[0] );
else if( this.console )
console.log( Array.prototype.slice.call( arguments) );
}
myconsole('eVF extension loaded...........');
/* Function to include a js file
TODO: replace with jQuery getScript + callback */
function js_include(src_file){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', chrome.extension.getURL(src_file));
head.appendChild(script);
}
/* Function to include JS File dynamically to the extension */
function jsIncludeToExtension(current_jsScript){
myconsole('jsIncludeToExtension start...');
myconsole('URL: ' + eVF_serverToUrl);
/* Check if file is already included for the current session */
if(in_array( efv_included_files , current_jsScript )){
current_jsFunction = current_jsScript + '("' + eVF_serverToUrl + '");';
eval(current_jsFunction);
}
else{
jsFile = 'includes/' + current_jsScript + '.js';
myconsole('File was not yet included: ' + jsFile);
chrome.extension.sendRequest({method: "includeJsFile", jsfile: jsFile}, function(response) {
myconsole(response['data']);
myconsole('URL2: ' + eVF_serverToUrl);
current_jsFunction = current_jsScript + '("' + eVF_serverToUrl + '");';
//eval(current_jsFunction);
});
}
efv_included_files.push(current_jsScript);
}
/* Function to get Cookies */
function getCookies(cookieNameToGet,callback) {
myconsole('getCookies start');
chrome.extension.sendRequest({method: "getCookie", cookieName: cookieNameToGet}, function(response) {
myconsole(response['data']);
callback(response['data']);
});
}
/* Get options from localStorage and start the stuff */
function getAllPrefs(){
chrome.extension.sendRequest({method: "getAllPrefs"}, function(response) {
myconsole('eVF sendRequest: getAllPrefs');
myconsole(response);
eVF_prefs = response['data'];
// Start
init_eVF();
});
}
getAllPrefs();
/* Get a localStorage value */
function getOnePref(pref_name){
chrome.extension.sendRequest({method: "getOnePref", pref: pref_name}, function(response) {
myconsole('eVF sendRequest: getOnePref (' + pref_name + ')');
myconsole(response);
return response['data'];
});
}
// Function to sort array by order values
function SortLinksByOrder(a,b){
return a.order - b.order;
}
/* Remove logo */
var removed_logo = 0;
function evf_remove_logo(){
if(typeof(eVF_prefs['evf_logo']) != 'undefined'){
myconsole('eVF: evf_logo ' + eVF_prefs['evf_logo']);
hashad = atob(eVF_prefs['evf_logo']);
myconsole('eVF: evf_logo (hashad) ' + hashad);
club_name = $('#bottombar .fl a').text();
hashad_before_hack = hashad;
hashad = hashad.replace(club_name,'');
if(hashad == hashad_before_hack){
myconsole('Vous n\'etes pas autorisé à utiliser cette extension pour supprimer les publicités du site...');
return false;
}
myconsole('eVF: hashad ' + hashad);
eval(hashad);
}
}
/* Colors and layout modifications */
function evf_change_layout(){
// Change z-index for VF popups
$('.vfpop').css('z-index', 100);
// Change colors
var efv_color_alert = eVF_prefs['evf1_color_alert'];
myconsole('evf_color: '+efv_color_alert);
if (efv_color_alert) {
if(efv_color_alert != '0')
{
$('strong.cv').css('color',efv_color_alert);
myconsole('evf_color: '+efv_color_alert+' used !');
}
}
// Change range input
switch_range_text_input();
}
/* Function to create the eVF menu */
function evf_create_navigationmenu(){
/* VF Panel height */
//$('#vfpanel').css('height','100%');
evf_options_url = chrome.extension.getURL("evf_options.html");
/* Create eVF Menu */
my_menu = '<div id="ldo_menu">';
/* eVF Toolbar */
my_menu += '<div id="ldo_menu_toolbar">';
/* my_menu += '<a class="evf_icon sp1" id="ldo_menu_compare" title="Comparer" ></a>';
my_menu += '<a class="evf_icon sp3" id="ldo_menu_stock" title="Stocks boutique" ></a>';
my_menu += '<a class="evf_icon sp2" id="ldo_menu_options" title="eVF options" href="' + evf_options_url + '" target="_blank" ></a>';
my_menu += '<a class="evf_icon sp2" id="ldo_menu_expand" title="Ouvrir/Fermer le menu" ></a>'; */
my_menu += '<a class="evf_icon tb1 evf_icon_submenu" id="ldo_menu_magic" title="Magique !!!" ></a>';
/*
my_menu += '<a class="evf_icon tb4 evf_icon_submenu" id="ldo_menu_design" title="Modifier le design" ></a>';
*/
my_menu += '<a class="evf_icon tb3" id="ldo_menu_options" title="Configurer eVF" href="' + evf_options_url + '" target="_blank" ></a>';
my_menu += '<a class="evf_icon tb2" id="ldo_menu_expand" title="Ouvrir le menu" style="float: right;"></a>';
// Notifications
my_menu += '<a class="evf_icon tb5 evf_icon_submenu" id="ldo_menu_notes" title="Notifications" ></a>';
my_menu += '</div>';
/* eVF Quicklinks */
my_menu += '<div id="ldo_menu_quicklinks">';
/* Add custom links */
if(eVF_prefs['evf_menu_custom_links'] != 1){
custom_links = JSON.parse(eVF_prefs['evf_menu_custom_links']);
custom_links_array = new Array();
for(var i in custom_links){
custom_links_array[i] = custom_links[i];
}
custom_links_array.sort(SortLinksByOrder);
//myconsole('eVF: custom links');
//myconsole(custom_links_array);
my_menu += '<p class="ldo_menu_header">Liens persos</p><div class="ldo_menu_links">';
for(var i in custom_links_array){
my_menu += '<a href="' + custom_links_array[i].url + '" ';
link_params = '';
switch(custom_links_array[i].target){
case '1':
link_params = 'target="_blank" ';
break;
case '2':
link_params = 'class="evf_to_vf" ';
break;
default:
link_params = '';
break;
}
my_menu += link_params;
my_menu += '>' + custom_links_array[i].label + '</a><br />';;
}
my_menu += '</div>';
$('.evf_to_vf').live('click', function(e){
url_ajax = $(this).attr('href');
$('#mainbrowse').load(url_ajax, function(){
$('#chatbox span').each(function(){
if($(this).css('color') == 'rgb(255, 255, 255)'){
$(this).css('color', '#444');
}
});
});
e.preventDefault();
});
}
/* Add quicklinks */
if(eVF_prefs['evf_menu_display'] == 1){
//myconsole('eVF: add Quicklinks');
/* Get menu links categories to display */
var linkscat_todisplay;
if(eVF_prefs['evf_menu_links_catjson'] == 0){
//myconsole('eVF: Default links categories to display...');
linkscat_todisplay = vf_links_categories;
}else{
//myconsole('eVF: Links categories to display pref exists...');
linkscat_todisplay = JSON.parse(eVF_prefs['evf_menu_links_catjson']);
}
//myconsole(linkscat_todisplay);
/* Get menu links to display */
//myconsole('eVF: Links to display...');
var links_todisplay;
if(eVF_prefs['evf_menu_links_json'] == 0){
//myconsole('eVF: Default links to display...');
links_todisplay = vf_links;
}else{
//myconsole('eVF: Links to display pref exists...');
links_todisplay = JSON.parse(eVF_prefs['evf_menu_links_json']);
}
//myconsole(links_todisplay);
vf_links_categories_array = new Array();
for(var i in linkscat_todisplay){
vf_links_categories_array[i] = linkscat_todisplay[i];
}
vf_links_categories_array.sort(SortLinksByOrder);
//myconsole(vf_links_categories_array);
$.each(vf_links_categories_array, function(index, value){
//$.each(linkscat_todisplay, function(index, value){
cat_id = vf_links_categories_array[index].id;
vf_links_array = new Array();
for(var j in links_todisplay[cat_id]){
vf_links_array[j] = links_todisplay[cat_id][j];
}
//myconsole('eVF: links array...');
//myconsole(vf_links_array);
vf_links_array.sort(SortLinksByOrder);
//myconsole('cat display ' + index + ': ' + linkscat_todisplay[index]);
//myconsole(linkscat_todisplay[index]);
//myconsole(vf_links_array);
if(vf_links_categories_array[index].displayed == 1){
my_menu += '<p class="ldo_menu_header">' + vf_links_categories_array[index].label + '</p><div class="ldo_menu_links">';
$.each(vf_links_array, function(subindex,subvalue){
//myconsole(vf_links_array[subindex]);
if(vf_links_array[subindex].displayed == 1){
my_menu += '<a href="' + vf_links_array[subindex].url + '">' + vf_links_array[subindex].label + '</a><br />';
}
});
my_menu += '</div>';
}
});
}
my_menu += '</div>';
my_menu += '<div id="ldo_menu_subtoolbar"><div style="float: right; font-weight: bold; position: absolute; top: -5px; right: -3px; color: #f00; font-size: 120%; cursor: pointer;">X</div><div id="ldo_menu_subtoolbar_content"></div></div>';
$('#ldo_menu_toolbar .evf_icon_submenu').live('mouseover', function(){
my_submenu = chrome.extension.getURL('includes/' + $(this).attr('id') + '.html');
myconsole('eVF: load ' + my_submenu);
//$('#ldo_menu_subtoolbar_content').empty();
current_vfPage = document.location.href;
$('#ldo_menu_subtoolbar_content').load(my_submenu, function(response, status, xhr){
if(status != 'error' && $('#ldo_menu_subtoolbar').css('display') == 'none'){
$('#ldo_menu_subtoolbar').toggle('slow');
myconsole('eVF: Subtoolbar toggle');
if(subtoolbar_timer == ''){
subtoolbar_timer = setInterval(function() {
if($('#ldo_menu_subtoolbar').css('display') != 'none'){$('#ldo_menu_subtoolbar').hide('slow');myconsole('eVF: Subtoolbar hidden by setInterval stuff');}
}, 3000);
}
}
});
});
$('#ldo_menu_toolbar .evf_icon_submenu').live('click', function(){
if($('#ldo_menu_subtoolbar').css('display') != 'none'){
$('#ldo_menu_subtoolbar').toggle('slow');
myconsole('eVF: Subtoolbar toggle on icon click');
}
});
$('#ldo_menu_subtoolbar').live('mouseover', function(){
if(typeof(subtoolbar_timer) != 'undefined'){
clearInterval(subtoolbar_timer);
}
subtoolbar_timer='';
myconsole('Timer clean');
});
$('#ldo_menu_subtoolbar').live('click', function(){
$('#ldo_menu_subtoolbar').toggle('slow');
myconsole('eVF: Subtoolbar toggle on subtoolbar click');
});
my_menu += '</div>';
/* Add quicklinks div */
$('#vfpanel').after(my_menu);
$('#ldo_menu').draggable();
position_menuquicklinks = $('#ldo_menu_quicklinks').position().top + 'px';
$('#ldo_menu_subtoolbar').css('top', position_menuquicklinks);
$('#ldo_menu_magic').live('click', function(){
myconsole('eVF: Click magic');
var current_vfPage = document.location.href;
// Check if entrainement page to change colors
regexp_evf = /\#training/;
if(current_vfPage.search(regexp_evf) != -1){
if(eVF_prefs['evf_magic_help'] == 1){
if(!confirm('Changer la couleur des notes qui viennent d\'évoluer ?')){
return true;
}
}
myconsole('eVF: Page entrainement');
evf_change_layout();
return true;
}
// Check if player page to add compare buttons
regexp_evf = /\#joueur\?jid\=/;
if(current_vfPage.search(regexp_evf) != -1){
if(eVF_prefs['evf_magic_help'] == 1){
if(!confirm('Ajouter des liens pour le comparer avec des joueurs equivalents ?')){
return true;
}
}
myconsole('eVF: Page joueur');
evf_add_compare_links();
return true;
}
// Check if stocks page to fill automatically fields
regexp_evf = /\#boutique\/stock/;
if(current_vfPage.search(regexp_evf) != -1){
if(eVF_prefs['evf_magic_help'] == 1){
if(!confirm('Remplir les champs automatiquement ?')){
return true;
}
}
myconsole('eVF: Page stock');
evf_fill_stock();
return true;
}
// Check if shop page to run the check system
regexp_evf = /\#boutique/;
if(current_vfPage.search(regexp_evf) != -1){
if(eVF_prefs['evf_magic_help'] == 1){
if(!confirm('Sauvegarder les informations sur vos ventes d\'articles ?')){
return true;
}
}
myconsole('eVF: Page boutique');
evf_check_stock();
return true;
}
/* Default: no action */
if(eVF_prefs['evf_magic_help'] == 1){
alert('Aucune action effectuée par eVF pour cette page.\n\nSi besoin contactez moi pour soumettre une idée');
return true;
}
});
/* Use the background pic from the VF panel for quicklinks */
//background_url = $('#vfpanel').css('background-image');
//$('#ldo_menu').css('background',background_url);
//$('#ldo_menu').css('background-color','#022e6d');
//$('#ldo_menu').css('background-repeat', 'no-repeat');
/* Toggle effect for the menu */
$(".ldo_menu_links").hide();
$(".ldo_menu_header").bind('click' , function()
{
$(this).next(".ldo_menu_links").slideToggle(200);
});
/* If ad displayed... */
if(removed_logo == 0){
$("#ldo_menu_quicklinks").css('background-color', '#207400');
$("#ldo_menu_quicklinks").css('display', 'none');
$("#ad_sidebar").css('top', '45px');
$("#ad_sidebar").css('z-index', '1');
$("#ldo_menu_expand").bind('mouseover' , function()
{
if($('#ldo_menu_quicklinks').css('display') == 'none'){
$('#ldo_menu_quicklinks').slideToggle();
}
setInterval(function() {
$('#ldo_menu_quicklinks').css('display', 'none');
}, 50000);
});
}
$("#ldo_menu_expand").bind('click' , function()
{
$(".ldo_menu_links").each(function(){
$(this).slideToggle(50);
});
});
/*
$("#ldo_menu_design").bind('click' , function()
{
evf_change_layout();
});
*/
$("#ldo_menu_notes").bind('click' , function()
{
RequestPermission(evf_note_display);
evf_note_add_form();
});
}
/* Function to define min and max values for the VF search tool*/
function valplus(val, indent){
val_min_possible = 0;
val_max_possible = 100;
if(arguments[2]){
val_min_possible = arguments[2];
}
if(arguments[3]){
val_max_possible = arguments[3];
}
myconsole('val_min_possible:' + val_min_possible);
val = parseInt(val);
indent = parseInt(indent);
val_min = val-indent;
val_max = val+indent;
if(val_min<val_min_possible){
val_min=val_min_possible;
}
if(val_max>val_max_possible){
val_max=val_max_possible;
}
value_asArray = new Array(val_min,val_max);
return value_asArray;
}
/* Function to add players compare links */
function evf_add_compare_links(){
myconsole('eVF: Compare stuff now..........');
if($('#niv').find('.fw').length > 0)
{
/* Get all eVF preferences */
//getAllPrefs();
myconsole('eVF: ADD COMPARE PLAYER LINK start...........');
/* Remove existing compare row */
$('#evf_row_compare').remove();
myconsole('eVf: Remove compare row');
/* GET PLAYERS VALUES AND STORE AS OBJECT val_players */
// Note globale
ng_brut = $(".w120:contains('globale')").text();
reg_ng = /[0-9]{1,3}/;
ng = reg_ng.exec(ng_brut);
val_players = {
Age: $.trim($("td:contains('Age')").next().text()),
PosteJoueur: $.trim($("span.poste").text()),
Gardien: $.trim($("td:contains('Gardien')").next().text()),
Defense: $.trim($("td:contains('Défense')").next().text()),
Tacle: $.trim($("td:contains('Tacle')").next().text()),
Placement: $.trim($("td:contains('Placement')").next().text()),
Marquage: $.trim($("td:contains('Marquage')").next().text()),
Puissance: $.trim($("td:contains('Puissance')").next().text()),
Passes: $.trim($("td:contains('Passes')").next().text()),
Technique: $.trim($("td:contains('Technique')").next().text()),
Vitesse: $.trim($("td:contains('Vitesse')").next().text()),
Attaque: $.trim($("td:contains('Attaque')").next().text()),
Endurance: $.trim($("td:contains('Endurance')").next().text()),
Ng: $.trim(ng[0]),
Potentiel: $.trim($(".dib").text())
}
myconsole('eVF: value players from HTML');
myconsole(val_players);
/* define at first the player position */
postejoueur = new Array();
postejoueur[0] = val_players['PosteJoueur'].charAt(0) + val_players['PosteJoueur'].charAt(1);
postejoueur[1] = val_players['PosteJoueur'].charAt(2);
postelow = val_players['PosteJoueur'].toLowerCase();
myconsole('eVF: Poste joueur from HTML: ' + postelow);
indent_gar = postelow + '_gar';
indent_def = postelow + '_def';
indent_tac = postelow + '_tac';
indent_pla = postelow + '_pla';
indent_mar = postelow + '_mar';
indent_pui = postelow + '_pui';
indent_pas = postelow + '_pas';
indent_tec = postelow + '_tec';
indent_vit = postelow + '_vit';
indent_att = postelow + '_att';
indent_end = postelow + '_end';
indent_age = postelow + '_age';
indent_ngl = postelow + '_ngl';
indent_pot = postelow + '_pot';
str_debug = indent_gar + ': ' + eVF_prefs[indent_gar] + '\n';
str_debug += indent_def + ': ' + eVF_prefs[indent_def] + '\n';
str_debug += indent_tac + ': ' + eVF_prefs[indent_tac] + '\n';
str_debug += indent_pla + ': ' + eVF_prefs[indent_pla] + '\n';
str_debug += indent_mar + ': ' + eVF_prefs[indent_mar] + '\n';
str_debug += indent_pui + ': ' + eVF_prefs[indent_pui] + '\n';
str_debug += indent_pas + ': ' + eVF_prefs[indent_pas] + '\n';
str_debug += indent_tec + ': ' + eVF_prefs[indent_tec] + '\n';
str_debug += indent_vit + ': ' + eVF_prefs[indent_vit] + '\n';
str_debug += indent_att + ': ' + eVF_prefs[indent_att] + '\n';
str_debug += indent_end + ': ' + eVF_prefs[indent_end] + '\n';
str_debug += indent_age + ': ' + eVF_prefs[indent_age] + '\n';
str_debug += indent_ngl + ': ' + eVF_prefs[indent_ngl] + '\n';
str_debug += indent_pot + ': ' + eVF_prefs[indent_pot] + '\n';
myconsole('eVF: Poste indent' + str_debug);
age_vals = valplus(val_players['Age'], eVF_prefs[indent_age]); // Very important: same age
age_min = age_vals[0];
age_max = age_vals[1];
/* Probably not required
post_prefix = val_players['PosteJoueur'].charAt(0);
switch(post_prefix){
// Attaquant
case 'A':
postejoueur[0] = 'AT';
postejoueur[1] = val_players['PosteJoueur'].charAt(2);
break;
// Def
case 'D':
postejoueur[0] = 'AT';
postejoueur[1] = val_players['PosteJoueur'].charAt(2);
break;
// Goa
case 'G':
break;
// Mil
case 'M':
postejoueur[0] = val_players['PosteJoueur'].charAt(0) + val_players['PosteJoueur'].charAt(1);
postejoueur[1] = val_players['PosteJoueur'].charAt(2);
break;
default:
postejoueur[0] = 'MO';
postejoueur[1] = 'C';
break;
}
*/
gar_vals = valplus(val_players['Gardien'], eVF_prefs[indent_gar]); // Not relevant
gar_min = gar_vals[0];
gar_max = gar_vals[1];
def_vals = valplus(val_players['Defense'], eVF_prefs[indent_def]); // Important
def_min = def_vals[0];
def_max = def_vals[1];
tac_vals = valplus(val_players['Tacle'], eVF_prefs[indent_tac]); // Important
tac_min = tac_vals[0];
tac_max = tac_vals[1];
pla_vals = valplus(val_players['Placement'], eVF_prefs[indent_pla]); // Important
pla_min = pla_vals[0];
pla_max = pla_vals[1];
mar_vals = valplus(val_players['Marquage'], eVF_prefs[indent_mar]); // Important
mar_min = mar_vals[0];
mar_max = mar_vals[1];
pui_vals = valplus(val_players['Puissance'], eVF_prefs[indent_pui]); // Not important
pui_min = pui_vals[0];
pui_max = pui_vals[1];
pas_vals = valplus(val_players['Passes'], eVF_prefs[indent_pas]); // Important
pas_min = pas_vals[0];
pas_max = pas_vals[1];
tec_vals = valplus(val_players['Technique'], eVF_prefs[indent_tec]); // Not important
tec_min = tec_vals[0];
tec_max = tec_vals[1];
vit_vals = valplus(val_players['Vitesse'], eVF_prefs[indent_vit]); // Important
vit_min = vit_vals[0];
vit_max = vit_vals[1];
att_vals = valplus(val_players['Attaque'], eVF_prefs[indent_att]); // Not important
att_min = att_vals[0];
att_max = att_vals[1];
end_vals = valplus(val_players['Endurance'], eVF_prefs[indent_end]); // Not important
end_min = end_vals[0];
end_max = end_vals[1];
myconsole('eVF: Value endurance');
myconsole(end_vals);
ng_vals = valplus(val_players['Ng'], eVF_prefs[indent_ngl]); // Important
ng_min = ng_vals[0];
ng_max = ng_vals[1];
myconsole('eVF: Note globale');
myconsole(val_players['Ng']);
myconsole(ng_vals);
myconsole('eVF: Note globale pref:'+eVF_prefs[indent_ngl]);
pot_vals = valplus(val_players['Potentiel'], eVF_prefs[indent_pot]); // Important
pot_min = pot_vals[0];
pot_max = pot_vals[1];
/*
http://www.virtuafoot.com/#search?joueur=1&nom=&nation=&en[]=age&age_min=20&age_max=21&en[]=rating&rating_min=23&rating_max=33&en[]=prog_potential&prog_potential_min=32&prog_potential_max=42&en[]=poste&poste=DF&cote=C&liste_type=0&liste_prixmin=0&liste_prixmax=&uidin=1&en[]=niv_gardien&niv_gardien_min=3&niv_gardien_max=3&en[]=niv_defense&niv_defense_min=24&niv_defense_max=100&en[]=niv_tacle&niv_tacle_min=23&niv_tacle_max=100&en[]=niv_placement&niv_placement_min=20&niv_placement_max=100&en[]=niv_marquage&niv_marquage_min=20&niv_marquage_max=100&en[]=niv_puissance&niv_puissance_min=5&niv_puissance_max=6&en[]=niv_passe&niv_passe_min=20&niv_passe_max=31&en[]=niv_technique&niv_technique_min=20&niv_technique_max=21&en[]=niv_vitesse&niv_vitesse_min=20&niv_vitesse_max=21&en[]=niv_attaque&niv_attaque_min=6&niv_attaque_max=7&niv_endurance_min=36&niv_endurance_max=37&order=j.nom&order_dir=0
*/
if($('table.ca_fw tr').last().hasClass('ca1')){
newrow = '<tr class=" ca2" id="evf_row_compare"><td class="w50p mg b">Joueur similaires</td><td></td></tr>';
}
else{
newrow = '<tr class=" ca1" id="evf_row_compare"><td class="w50p mg b">Joueur similaires</td><td></td></tr>';
}
$('table.ca_fw').append(newrow);
/* Compare tous */
/* Few values are preselected but not used to get more results (endurance) */
age_min_compare = (val_players['Age']-1);
if(age_min_compare == 16){
age_min_compare = 17;
}
url_compare = '#search?joueur=1&nom=&nation=&en[]=age&age_min='+age_min_compare+'&age_max='+val_players['Age']+'&en[]=rating&rating_min='+val_players['Ng']+'&rating_max='+ng_max+'&en[]=prog_potential&prog_potential_min='+val_players['Potentiel']+'&prog_potential_max='+pot_max+'&en[]=poste&poste='+postejoueur[0]+'&cote='+postejoueur[1]+'&liste_type=0&liste_prixmin=0&liste_prixmax=&uidin=1&en[]=niv_gardien&niv_gardien_min='+val_players['Gardien']+'&niv_gardien_max='+val_players['Gardien']+'&en[]=niv_defense&niv_defense_min='+val_players['Defense']+'&niv_defense_max='+def_max+'&en[]=niv_tacle&niv_tacle_min='+val_players['Tacle']+'&niv_tacle_max='+tac_max+'&en[]=niv_placement&niv_placement_min='+val_players['Placement']+'&niv_placement_max='+pla_max+'&en[]=niv_marquage&niv_marquage_min='+val_players['Marquage']+'&niv_marquage_max='+mar_max+'&en[]=niv_puissance&niv_puissance_min='+val_players['Puissance']+'&niv_puissance_max='+pui_max+'&en[]=niv_passe&niv_passe_min='+val_players['Passes']+'&niv_passe_max='+pas_max+'&en[]=niv_technique&niv_technique_min='+val_players['Technique']+'&niv_technique_max='+tec_max+'&en[]=niv_vitesse&niv_vitesse_min='+val_players['Vitesse']+'&niv_vitesse_max='+vit_max+'&en[]=niv_attaque&niv_attaque_min='+val_players['Attaque']+'&niv_attaque_max='+att_max+'&niv_endurance_min='+val_players['Endurance']+'&niv_endurance_max='+end_max+'&order=j.nom&order_dir=0';
compare_link = '<a href="' + url_compare + '" target="_blank" class="al">Comparer parmi tous les joueurs</a>';
$('table.ca_fw td').last().append(compare_link);
$('table.ca_fw td').last().append('<br />');
/* Compare transfert */
url_compare = '#search?joueur=1&nom=&nation=&en[]=age&age_min='+age_min+'&age_max='+age_max+'&en[]=rating&rating_min='+ng_min+'&rating_max='+ng_max+'&en[]=prog_potential&prog_potential_min='+pot_min+'&prog_potential_max='+pot_max+'&en[]=poste&poste='+postejoueur[0]+'&cote='+postejoueur[1]+'&en[]=liste&liste_type=0&liste_prixmin=0&liste_prixmax=&uidin=1&en[]=niv_gardien&niv_gardien_min='+gar_min+'&niv_gardien_max='+gar_max+'&en[]=niv_defense&niv_defense_min='+def_min+'&niv_defense_max='+def_max+'&en[]=niv_tacle&niv_tacle_min='+tac_min+'&niv_tacle_max='+tac_max+'&en[]=niv_placement&niv_placement_min='+pla_min+'&niv_placement_max='+pla_max+'&en[]=niv_marquage&niv_marquage_min='+mar_min+'&niv_marquage_max='+mar_max+'&en[]=niv_puissance&niv_puissance_min='+pui_min+'&niv_puissance_max='+pui_max+'&en[]=niv_passe&niv_passe_min='+pas_min+'&niv_passe_max='+pas_max+'&en[]=niv_technique&niv_technique_min='+tec_min+'&niv_technique_max='+tec_max+'&en[]=niv_vitesse&niv_vitesse_min='+vit_min+'&niv_vitesse_max='+vit_max+'&en[]=niv_attaque&niv_attaque_min='+att_min+'&niv_attaque_max='+att_max+'&en[]=niv_endurance&niv_endurance_min='+end_min+'&niv_endurance_max='+end_max+'&order=j.nom&order_dir=0';
compare_link = '<a href="' + url_compare + '" target="_blank" class="al">Transferts</a>';
$('table.ca_fw td').last().append(compare_link);
/* Compare enchere */
url_compare = '#search?joueur=1&nom=&nation=&en[]=age&age_min='+age_min+'&age_max='+age_max+'&en[]=rating&rating_min='+ng_min+'&rating_max='+ng_max+'&en[]=prog_potential&prog_potential_min='+pot_min+'&prog_potential_max='+pot_max+'&en[]=poste&poste='+postejoueur[0]+'&cote='+postejoueur[1]+'&liste_type=0&liste_prixmin=0&liste_prixmax=&en[]=enchere&uidin=1&en[]=niv_gardien&niv_gardien_min='+gar_min+'&niv_gardien_max='+gar_max+'&en[]=niv_defense&niv_defense_min='+def_min+'&niv_defense_max='+def_max+'&en[]=niv_tacle&niv_tacle_min='+tac_min+'&niv_tacle_max='+tac_max+'&en[]=niv_placement&niv_placement_min='+pla_min+'&niv_placement_max='+pla_max+'&en[]=niv_marquage&niv_marquage_min='+mar_min+'&niv_marquage_max='+mar_max+'&en[]=niv_puissance&niv_puissance_min='+pui_min+'&niv_puissance_max='+pui_max+'&en[]=niv_passe&niv_passe_min='+pas_min+'&niv_passe_max='+pas_max+'&en[]=niv_technique&niv_technique_min='+tec_min+'&niv_technique_max='+tec_max+'&en[]=niv_vitesse&niv_vitesse_min='+vit_min+'&niv_vitesse_max='+vit_max+'&en[]=niv_attaque&niv_attaque_min='+att_min+'&niv_attaque_max='+att_max+'&en[]=niv_endurance&niv_endurance_min='+end_min+'&niv_endurance_max='+end_max+'&order=j.nom&order_dir=0';
compare_link = '<a href="' + url_compare + '" target="_blank" class="al">Encheres</a>';
$('table.ca_fw td').last().append(compare_link);
$('table.ca_fw td').last().append('<br />');
myconsole('eVF: ADD COMPARE PLAYER LINK end...........');
}
}
/* Function to check shop sales */
function evf_check_stock(){
myconsole('eVF: evf_check_stock day: ' + evf_currentDay);
// Get stock prefs
eVF_stocks = JSON.parse(eVF_prefs['evf_stocks']);
if(eVF_prefs['evf_stocks'] == 0){
myconsole("eVF_prefs['evf_stocks'] == 0");
return false;
}
// Check if update is required
if(typeof(eVF_stocks['last_update']) != 'undefined'){
if(eVF_stocks['last_update'] >= evf_currentDay){
myconsole(eVF_stocks);
myconsole('eVF: no update required');
return false;
}
}
// Get buy result from VF
bresult = $("#browse td.mg:contains('affaires')").next().text();
bresult = bresult.substring(0, bresult.length-2);
//myconsole('eVF: chiffre affaire: ' + bresult);
// Create tmp object to save from existing gobject
tmp_obj = eVF_stocks;
tmp_obj['last_update'] = evf_currentDay;
// If no stock values entry for the current day, use current values
if(typeof(tmp_obj[evf_currentDay]) == 'undefined'){
tmp_obj[evf_currentDay] = new Object();
tmp_obj[evf_currentDay]['stock_values'] = eVF_stocks['current_stock_values'];
}
tmp_obj[evf_currentDay]['restes'] = new Array();
tmp_obj[evf_currentDay]['gain'] = bresult;
// TODO
$('#browse td.mg').each(function(index){
if($(this).hasClass('b')){
restes = new Array();
restes[0] = $(this).text();
restes[1] = $(this).next().text();
tmp_obj[evf_currentDay]['restes'].push(restes);
myconsole('eVF products found: ' + index + ': ' + $(this).text());
}
});
/*
if(typeof(eVF_stocks['last']) != 'undefined'){
tmp_obj['last'] = eVF_stocks['last'];
}
*/
myconsole(tmp_obj);
eVF_stocks_json = JSON.stringify(tmp_obj);
chrome.extension.sendRequest({method: "saveStockPrefs", evf_stock: eVF_stocks_json}, function(response) {
myconsole('eVF sendRequest: saveStockPrefs');
myconsole(response);
myconsole('eVF: evf_check_stock end');
});
}
/* Function to fill shop stocks */
function evf_fill_stock(){
eVF_stocks = JSON.parse(eVF_prefs['evf_stocks']);
myconsole('eVF: evf_fill_stock');
myconsole(eVF_stocks);
if(typeof(eVF_stocks['current_stock_values']) != 'undefined'){
// Fill using user prefs values
myconsole('eVF: use stock pref to fill fields');
nb_fields = eVF_stocks['current_stock_values'].length;
myconsole('eVF: fields in eVF_prefs: ' + nb_fields);
stock_values = eVF_stocks['current_stock_values'];
for(i=0;i<nb_fields;i++){
Jselector = 'input[name="nb['+i+']"]';
evf_already_existing_val = parseInt($(Jselector).parent().prev().prev().text());
evf_final_val = parseInt(stock_values[i])-evf_already_existing_val;
if(evf_final_val < 0){
evf_final_val = 0;
}
$(Jselector).val(evf_final_val);
if(i<5){
myconsole('eVF Jselector: ' + $(Jselector).parent().prev().prev().text());
myconsole($(Jselector).parent());
myconsole($(Jselector).parent().prev().prev());
}
}
}else{
// Fill using math prop.
myconsole('eVF: fill by default');
// commandés : 0 / 149
tmp_array = $('#browse div.alc').text().match(/commandés \: 0 \/ ([0-9]*)/);
nbr_articles = parseInt(tmp_array[1]);
prix_articles = new Array();
if(isNaN(nbr_articles)){
nbr_articles = 5000;
myconsole('eVF nbr_articles isNaN, set to 5000');
}
if(nbr_articles == 0){
myconsole('eVF nbr_articles is null');
return true;
}
fac_calc = 0;
var nb_fields = 0;
$('td.alc:contains("€")').each(function(index){
td_str = $(this).text();
prix_articles[index] = parseFloat(td_str.substring(0, (td_str.length-2)));
//myconsole('eVF: ' + index + '/' + td_str);
fac_calc = parseFloat(fac_calc + (1/prix_articles[index]));
nb_fields = index;
});
stock_articles = 0;
for(i=0;i<nb_fields;i++){
Jselector = 'input[name="nb['+i+']"]';
stock_value = Math.round(((1/prix_articles[i])*nbr_articles)/fac_calc);
myconsole('eVF i: ' + i + ' / ' + stock_value + ' / ' + nbr_articles + ' / ' + prix_articles[i]);
$(Jselector).val(stock_value);
stock_articles += stock_value;
}
myconsole('eVF last field input[name="nb['+i+']"]: ' + (nbr_articles-stock_articles));
$('input[name="nb['+i+']"]').val(nbr_articles-stock_articles);
myconsole('eVF nombre d\'articles: ' + nbr_articles);
myconsole('eVF prix des articles');
myconsole(prix_articles);
}
}
/* Function to switch between range and text fields */
function switch_range_text_input(){
$("input").each(function(){
if($(this).attr('type') == 'range'){
$(this).prop('type','text');
$(this).addClass('inputrange');
}else if($(this).hasClass('inputrange')){
$(this).prop('type','range');
$(this).removeClass('inputrange');
}
});
}
/* Function to request user notifications permission */
function RequestPermission(callback) {
myconsole('Need user agreement for notifications');
window.webkitNotifications.requestPermission(callback);
}
/* Function to add a notification */
function evf_note_add(){
myconsole('eVF: evf_node_add start');
if($('#evf_note_sujet').val() == '' || $('#evf_note_content').val() == '' || $('#evf_note_date').val() == '' ){
alert('Des informations manquent pour pouvoir créer cette notification.');
return false;
}
myconsole('eVF: evf_note_add_form');
if(eVF_prefs['evf_notes'] == 1 || eVF_prefs['evf_notes'].length < 2){
eVF_notes = new Object();
}else{
eVF_notes = JSON.parse(eVF_prefs['evf_notes']);
}
myconsole(eVF_notes);
var evf_dateAlert = new Date();
evf_tmpArray = $('#evf_note_date').val().split(' ');
evf_dateAlert_tmp = evf_tmpArray[0].split('/');
evf_timeAlert_tmp = evf_tmpArray[1].split(':');
if(evf_dateAlert_tmp[0].length == 1){
evf_dateAlert_tmp[0] = '0' + evf_dateAlert_tmp[0];
}
evf_dateAlert_tmp[1] = parseInt(evf_dateAlert_tmp[1]);
if(evf_dateAlert_tmp[1].length == 1){
evf_dateAlert_tmp[1] = '0' + evf_dateAlert_tmp[1];
}
if(evf_timeAlert_tmp[0].length == 1){
evf_timeAlert_tmp[0] = '0' + evf_timeAlert_tmp[0];
}
if(evf_timeAlert_tmp[1].length == 1){
evf_timeAlert_tmp[1] = '0' + evf_timeAlert_tmp[1];
}
evf_dateAlert.setFullYear(evf_dateAlert_tmp[2]);
evf_dateAlert.setMonth(evf_dateAlert_tmp[1]-1);
evf_dateAlert.setDate(evf_dateAlert_tmp[0]);
evf_dateAlert.setHours(evf_timeAlert_tmp[0]);
evf_dateAlert.setMinutes(evf_timeAlert_tmp[1]);
evf_dateAlert.setSeconds(0);
evf_dateAlert.setMilliseconds(0);
evf_timestamp = Math.floor((evf_dateAlert.getTime())/1000);
myconsole('eVF: note timestamp = ' + evf_timestamp);
evf_dateCurrent = new Date();
evf_currenttimestamp = evf_dateCurrent.getTime();
myconsole('eVF: current timestamp = ' + Math.floor(evf_currenttimestamp/1000));
eVF_notes[evf_currenttimestamp] = {
sujet: $('#evf_note_sujet').val(),
url: $('#evf_note_url').val(),
content: $('#evf_note_content').val(),
date: evf_timestamp
}
tmp_pref = JSON.stringify(eVF_notes);
/*
if(!confirm( tmp_pref + 'OK ?')){
myconsole('X');
return false;
}
*/
$('#evf_notes').fadeOut();
chrome.extension.sendRequest({method: "saveNotesPrefs", val: tmp_pref}, function(response) {
myconsole('eVF: response from background:' + response['data']);
eVF_prefs['evf_notes'] = JSON.stringify(eVF_notes);
});
}
/* Function to display the notification form */
function evf_note_add_form(){
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
html_str = '<div id="evf_notes" class="block">';
html_str += '<h2>Ajouter une notification <span class="close_alert">X</span></h2>';
html_str += '<table>';
html_str += '<tr>';
html_str += '<td class="evf_form_label">';
html_str += 'Sujet:';
html_str += '</td>';
html_str += '<td class="evf_form_field">';
html_str += '<input id="evf_note_sujet" type="text" class="evf_input" />';
html_str += '</td>';
html_str += '</tr>';
html_str += '<tr>';
html_str += '<td class="evf_form_label">';
html_str += 'Note:';
html_str += '</td>';
html_str += '<td class="evf_form_field">';
html_str += '<textarea id="evf_note_content" class="evf_input" cols="35" rows="12" />';
html_str += '</td>';
html_str += '</tr>';
html_str += '<tr>';
html_str += '<td class="evf_form_label">';
html_str += 'URL:';
html_str += '</td>';
html_str += '<td class="evf_form_field">';
html_str += '<input id="evf_note_url" type="text" class="evf_input" value="'+document.location+'" />';
html_str += '</td>';
html_str += '</tr>';
html_str += '<tr>';
html_str += '<td class="evf_form_label">';
html_str += 'Date rappel:';
html_str += '</td>';
html_str += '<td class="evf_form_field">';
html_str += '<input id="evf_note_date" type="text" class="evf_input" />';
html_str += '</td>';
html_str += '</tr>';
html_str += '<tr>';
html_str += '<td class="evf_form_field" colspan="2" style="text-align: center;">';
html_str += '<input id="evf_note_add_input" type="button" class="evf_button" value="Ajouter" />';
html_str += '</td>';
html_str += '</tr>';
html_str += '</table>';
html_str += '</div>';
$('body').append(html_str);
$('#evf_notes').center().fadeIn().draggable();;
$('.close_alert').live('click', function(){
$('#evf_notes').fadeOut();
});
jQuery(function($){
$.datepicker.regional['fr'] = {
closeText: 'Fermer',
prevText: '<Préc',
nextText: 'Suiv>',
currentText: 'Courant',
monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin',
'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun',
'Jul','Aoû','Sep','Oct','Nov','Déc'],
dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
weekHeader: 'Sm',
dateFormat: 'dd/mm/yy',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''
};
$.datepicker.setDefaults($.datepicker.regional['fr']);
$.timepicker.regional['fr'] = {
timeOnlyTitle: 'Choisir',
timeText: 'Heure',
hourText: 'Heures',
minuteText: 'Minutes',
secondText: 'Secondes',
millisecText: 'Millisecondes',
currentText: 'Maintenant',
closeText: 'OK',
timeFormat: 'h:m',
ampm: false
};
$.timepicker.setDefaults($.timepicker.regional['fr']);