-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetaseries.user.js
4987 lines (4939 loc) · 259 KB
/
betaseries.user.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
// ==UserScript==
// @name us_betaseries
// @namespace https://github.com/Azema/betaseries
// @version 1.5.167
// @description Ajoute quelques améliorations au site BetaSeries
// @author Azema
// @homepage https://github.com/Azema/betaseries
// @supportURL https://github.com/Azema/betaseries/issues
// @match https://www.betaseries.com/serie/*
// @match https://www.betaseries.com/series/*
// @match https://www.betaseries.com/episode/*
// @match https://www.betaseries.com/film/*
// @match https://www.betaseries.com/films/*
// @match https://www.betaseries.com/membre/*
// @exclude https://www.betaseries.com/membre/*/badges
// @match https://www.betaseries.com/api/*
// @match https://www.betaseries.com/article/*
// @icon https://www.betaseries.com/images/site/favicon-32x32.png
// @require https://cdnjs.cloudflare.com/ajax/libs/humanize-duration/3.27.0/humanize-duration.min.js#sha512-C6XM91cD52KknT8jaQF1P2PrIRTrbMzq6hzFkc22Pionu774sZwVPJInNxfHNwPvPne3AMtnRWKunr9+/gQR5g==
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_notification
// ==/UserScript==
'use strict';
/* eslint-disable */
if (!window) {
const { UsBetaSeries, EventTypes, HTTP_VERBS, NetworkState, isNull } = require('./types/Base');
const { CacheUS, DataTypesCache } = require('./types/Cache');
const { Character, Person, PersonMedias, PersonMedia } = require('./types/Character');
const { CommentBS } = require('./types/Comment');
const { CommentsBS } = require('./types/Comments');
const { Debug } = require('./types/Debug');
const { Episode } = require('./types/Episode');
const { Media, MediaBase, MediaType } = require('./types/Media');
const { NotificationBS, NotificationList } = require('./types/Notification');
const { Show, PlatformList } = require('./types/Show');
const { Movie, MovieStatus } = require('./types/Movie');
const { Member } = require('./types/Member');
const { UpdateAuto } = require('./types/UpdateAuto');
}
/* eslint-enable */
/**
* @typedef { import('./types/Base').UsBetaSeries } UsBetaSeries
* @typedef { import('./types/Base').EventTypes } EventTypes
* @typedef { import('./types/Base').HTTP_VERBS } HTTP_VERBS
* @typedef { import('./types/Base').NetworkState } NetworkState
* @typedef { import('./types/Cache').CacheUS } CacheUS
* @typedef { import('./types/Cache').DataTypesCache } DataTypesCache
* @typedef { import('./types/Character').Character } Character
* @typedef { import('./types/Character').Person } Person
* @typedef { import('./types/Character').personMedia } personMedia
* @typedef { import('./types/Comment').CommentBS } CommentBS
* @typedef { import('./types/Comments').CommentsBS } CommentsBS
* @typedef { import('./types/Debug').Debug } Debug
* @typedef { import('./types/Episode').Episode } Episode
* @typedef { import('./types/Media').Media } Media
* @typedef { import('./types/Media').MediaBase } MediaBase
* @typedef { import('./types/Media').MediaType } MediaType
* @typedef { import('./types/Notification').NotificationBS } NotificationBS
* @typedef { import('./types/Show').Show } Show
* @typedef { import('./types/Show').PlatformList } PlatformList
* @typedef { import('./types/Movie').Movie } Movie
* @typedef { import('./types/Movie').MovieStatus } MovieStatus
* @typedef { import('./types/Member').Member } Member
* @typedef { import('./types/UpdateAuto').UpdateAuto } UpdateAuto
*/
/* eslint-disable no-undef */
/* globals
betaseries_api_user_token: true, betaseries_user_id: false, trans: false,
deleteFilterOthersCountries: false, generate_route: false,
CONSTANTE_SORT: false, CONSTANTE_FILTER: false, hideButtonReset: false, newApiParameter: false, renderjson: false, humanizeDuration: false, A11yDialog: false, markAllNotificationsAsSeen: false,
viewMoreFriends: false, PopupAlert: false, faceboxDisplay: false
*/
/************************************************************************************************/
/* PARAMETRES A MODIFIER */
/************************************************************************************************/
/* Ajouter ici votre clé d'API BetaSeries (Demande de clé API: https://www.betaseries.com/api/) */
const betaseries_api_user_key = '';
/* Ajouter ici votre clé d'API V3 à themoviedb */
const themoviedb_api_user_key = '';
/* Ajouter ici l'URL de base de votre serveur distribuant les CSS, IMG et JS */
const serverOauthUrl = 'https://azema.github.io/betaseries-oauth';
const serverBaseUrl = 'https://azema.github.io/betaseries-oauth';
/* SRI du fichier app-bundle.js */
const sriBundle = 'sha384-83JhbfJwL91GVal9VqyYXQ/zcdkYyBY82ClbB7qQneelN03Ia7132uqlJK+C3dD0';
/************************************************************************************************/
// @ts-check
let resources = {};
/**
* Fonction de chargement dynamique de feuilles de style CSS
* @param {string} href Le source de la feuille de style
* @param {HTMLLinkElement} before Link de référence pour le placement
* @param {Attr} media Le type de média à utiliser pour la feuille de style
* @param {Object} attributes Les attributs à appliquer à l'élément Link
* @param {Function} callback Fonction de callback après chargement de la feuille de style
* @param {Function} onerror Fonction de callback en cas d'erreur
* @returns {HTMLLinkElement}
*/
const loadCSS = function( href, before, media, attributes = {}, callback, onerror ) {
// Arguments explained:
// `href` [REQUIRED] is the URL for your CSS file.
// `before` [OPTIONAL] is the element the script should use as a reference for injecting our stylesheet <link> before
// By default, loadCSS attempts to inject the link after the last stylesheet or script in the DOM. However, you might desire a more specific location in your document.
// `media` [OPTIONAL] is the media type or query of the stylesheet. By default it will be 'all'
// `attributes` [OPTIONAL] is the Object of attribute name/attribute value pairs to set on the stylesheet's DOM Element.
const doc = window.document;
const ss = doc.createElement( "link" );
let ref;
if( before ){
ref = before;
} else {
const refs = ( doc.body || doc.getElementsByTagName( "head" )[ 0 ] ).childNodes;
ref = refs[refs.length - 1];
}
const sheets = doc.styleSheets;
// Set any of the provided attributes to the stylesheet DOM Element.
// temporarily set media to something inapplicable to ensure it'll fetch without blocking render
attributes = Object.assign({rel: 'stylesheet', href, media: 'only x'}, attributes);
for( let attributeName in attributes ){
if ( attributes[attributeName] !== undefined ){
ss.setAttribute( attributeName, attributes[attributeName] );
}
}
// wait until body is defined before injecting link. This ensures a non-blocking load in IE11.
function ready( cb ){
if( doc.body ){
return cb();
}
setTimeout(function(){
ready( cb );
});
}
// Inject link
// Note: the ternary preserves the existing behavior of "before" argument, but we could choose to change the argument to "after" in a later release and standardize on ref.nextSibling for all refs
// Note: `insertBefore` is used instead of `appendChild`, for safety re: http://www.paulirish.com/2011/surefire-dom-element-insertion/
ready( function() {
ref.parentNode.insertBefore( ss, ( before ? ref : ref.nextSibling ) );
});
// A method (exposed on return object for external use) that mimics onload by polling document.styleSheets until it includes the new sheet.
var onloadcssdefined = function( cb ){
const resolvedHref = ss.href;
let i = sheets.length;
while( i-- ){
if( sheets[ i ].href === resolvedHref ){
return cb();
}
}
setTimeout(function() {
onloadcssdefined( cb );
});
};
let called = false;
function newcb() {
if ( ss.addEventListener ) {
ss.removeEventListener( "load", newcb );
}
if ( !called && callback ) {
called = true;
callback.call( ss );
}
ss.media = media || "all";
}
// once loaded, set link's media back to `all` so that the stylesheet applies once it loads
if ( ss.addEventListener ) {
ss.addEventListener( "load", newcb);
if (onerror) { ss.addEventListener('error', onerror); }
}
ss.onloadcssdefined = onloadcssdefined;
onloadcssdefined( newcb );
return ss;
};
/**
* Fonction de chargement dynamique de scripts JS
* @param {string} src La source du script
* @param {Object} attributes Les attributs du script
* @param {Function} callback Fonction de callback après le chargement du script
* @param {Function} onerror Fonction de callback en cas d'erreur
* @returns {HTMLScriptElement} L'objet script
*/
const loadJS = function( src, attributes = {}, callback, onerror ) {
// Arguments explained:
// `href` [REQUIRED] is the URL for your CSS file.
// `before` [OPTIONAL] is the element the script should use as a reference for injecting our stylesheet <link> before
// By default, loadCSS attempts to inject the link after the last stylesheet or script in the DOM. However, you might desire a more specific location in your document.
// `media` [OPTIONAL] is the media type or query of the stylesheet. By default it will be 'all'
// `attributes` [OPTIONAL] is the Object of attribute name/attribute value pairs to set on the stylesheet's DOM Element.
const doc = window.document;
const ss = doc.createElement( "script" );
const refs = ( doc.body || doc.getElementsByTagName( "head" )[ 0 ] ).childNodes;
const ref = refs[ refs.length - 1];
attributes = Object.assign({type: "text/javascript"}, attributes);
// Set any of the provided attributes to the stylesheet DOM Element.
for ( let attributeName in attributes ) {
if ( attributes[attributeName] !== undefined ) {
ss.setAttribute( attributeName, attributes[attributeName] );
}
}
ss.src = src;
// wait until body is defined before injecting link. This ensures a non-blocking load in IE11.
function ready( cb ){
if( doc.body ){
return cb();
}
setTimeout(function(){
ready( cb );
});
}
// Inject link
// Note: the ternary preserves the existing behavior of "before" argument, but we could choose to change the argument to "after" in a later release and standardize on ref.nextSibling for all refs
// Note: `insertBefore` is used instead of `appendChild`, for safety re: http://www.paulirish.com/2011/surefire-dom-element-insertion/
ready( function() {
ref.parentNode.insertBefore( ss, ref.nextSibling );
});
let called = false;
function newcb() {
if ( ss.addEventListener ) {
ss.removeEventListener( "load", newcb );
if (onerror) ss.removeEventListener('error', onerror);
}
if ( !called && callback ) {
called = true;
callback.call( ss );
}
}
// once loaded, set link's media back to `all` so that the stylesheet applies once it loads
if ( ss.addEventListener ) {
ss.addEventListener( "load", newcb);
if (onerror) { ss.addEventListener('error', onerror); }
}
return ss;
};
/**
*
* @param {JQueryStatic} $ - Library JQuery
*/
const launchScript = function($) {
UsBetaSeries.setDebug.enable('userscript userscript:socket -userscript:load BS BS:API');
const debug = false,
origin = window.location.origin,
url = window.location.pathname,
domain = window.location.hostname.substring(window.location.hostname.indexOf('.')+1),
regDomain = new RegExp(domain, 'i'),
regexUser = new RegExp('^/membre/[A-Za-z0-9]*$'),
noop = function () {},
/** @type {Debug} */
logger = new UsBetaSeries.setDebug('userscript'),
log = logger.fnLog,
// URI des images et description des classifications TV et films
ratings = {
'D-10': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Moins10.svg/30px-Moins10.svg.png',
title: "Déconseillé au moins de 10 ans"
},
'D-12': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Moins12.svg/30px-Moins12.svg.png',
title: 'Déconseillé au moins de 12 ans'
},
'D-16': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Moins16.svg/30px-Moins16.svg.png',
title: 'Déconseillé au moins de 16 ans'
},
'D-18': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2d/Moins18.svg/30px-Moins18.svg.png',
title: 'Ce programme est uniquement réservé aux adultes'
},
'TV-Y': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/25/TV-Y_icon.svg/50px-TV-Y_icon.svg.png',
title: 'Ce programme est évalué comme étant approprié aux enfants'
},
'TV-Y7': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/TV-Y7_icon.svg/50px-TV-Y7_icon.svg.png',
title: 'Ce programme est désigné pour les enfants âgés de 7 ans et plus'
},
'TV-G': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/TV-G_icon.svg/50px-TV-G_icon.svg.png',
title: 'La plupart des parents peuvent considérer ce programme comme approprié pour les enfants'
},
'TV-PG': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/TV-PG_icon.svg/50px-TV-PG_icon.svg.png',
title: 'Ce programme contient des éléments que les parents peuvent considérer inappropriés pour les enfants'
},
'TV-14': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/TV-14_icon.svg/50px-TV-14_icon.svg.png',
title: 'Ce programme est déconseillé aux enfants de moins de 14 ans'
},
'TV-MA': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/34/TV-MA_icon.svg/50px-TV-MA_icon.svg.png',
title: 'Ce programme est uniquement réservé aux adultes'
},
'G': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/RATED_G.svg/30px-RATED_G.svg.png',
title: 'Tous publics'
},
'PG': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/RATED_PG.svg/54px-RATED_PG.svg.png',
title: 'Accord parental souhaitable'
},
'PG-13': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c0/RATED_PG-13.svg/95px-RATED_PG-13.svg.png',
title: 'Accord parental recommandé, film déconseillé aux moins de 13 ans'
},
'R': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/7e/RATED_R.svg/40px-RATED_R.svg.png',
title: 'Les enfants de moins de 17 ans doivent être accompagnés d\'un adulte'
},
'NC-17': {
img: 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Nc-17.svg/85px-Nc-17.svg.png',
title: 'Interdit aux enfants de 17 ans et moins'
}
},
templatePopover = `
<div class="popover" role="tooltip">
<div class="arrow"></div>
<h3 class="popover-header"></h3>
<div class="popover-body"></div>
</div>`,
optionsLazyload = {
root: null,
rootMargin: "50px 0px",
threshold: 0.01,
selector: '.js-lazy-image'
};
// Objet contenant les scripts et feuilles de style utilisées par le userscript
let scriptsAndStyles = {
"renderjson": {
type: 'script',
id: 'renderjson',
link: `${serverBaseUrl}/js/renderjson.min.js`,
integrity: 'sha384-/mHGJ/3gaDqVJCEeed/Uh1fJVO01E+CLBZrFqjv1REaFAZxEBvGMHQyBmwln/uhx',
called: false,
loaded: false
},
"popover": {
type: 'style',
id: 'csspopover',
link: `${serverBaseUrl}/css/popover.min.css`,
integrity: 'sha384-yebLb3hn+3mwaxg0KwLhE2YYLEKsMRsxRvUPyBOF6gzkzLEOWEeD9ELZeDACSwO7',
media: 'all',
called: false,
loaded: false
},
"bootstrap": {
type: 'script',
id: 'jsbootstrap',
link: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js',
integrity: 'sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl',
called: false,
loaded: false
},
"tablecss": {
type: 'style',
id: 'tablecss',
link: `${serverBaseUrl}/css/table.min.css`,
integrity: 'sha384-tRMvWzqbXtOp2OM+OPoYpWVxHw8eXcFKgzi4q9m6i0rvWTU33pdb8Bx33wBWjlo9',
media: 'all',
called: false,
loaded: false
},
"stylehome": {
type: 'style',
id: 'stylehome',
link: `${serverBaseUrl}/css/style.min.css`,
integrity: 'sha384-Cekddv8gf4cq4AusXXtPX3r9DlcjafJgbufsVTp6JWWlh8r1Jq11d0DKiB53wlIc',
media: 'all',
called: false,
loaded: false
},
"awesome": {
type: 'style',
id: 'awesome',
link: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css',
integrity: 'sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw==',
media: 'all',
called: false,
loaded: false
},
"awesome6": {
type: 'script',
id: 'awesome6',
link: `${serverBaseUrl}/js/font-awesome-6.1.min.js`,
integrity: 'sha384-RRYsVjoikrI5QSLEcefbI8XvMN2J/m8V0n1AAg8T9Y6xICVEsdJdeN6OavRJFMgZ',
called: false,
loaded: false
},
"comments": {
type: 'style',
id: 'commentstyle',
link: `${serverBaseUrl}/css/comments.min.css`,
integrity: 'sha384-37/ghsJZTBvNPxUAy6GMPGxa3BKjrZ2ykMb7gUpkkVvoZwAsm4WhigKhMyYCN+Ft',
media: 'all',
called: false,
loaded: false
},
"textcomplete": {
type: 'script',
id: 'jstextcomplete',
link: `${serverBaseUrl}/js/jquery.textcomplete.min.js`,
integrity: 'sha384-kf6mqav/ZhBkPgNGorOiE7+/0GmfN9NDz0ov5G3fy6PuV/wqAggrTaWkTVfPM79L',
called: false,
loaded: false
},
"lazyload": {
type: 'script',
id: 'lazyload',
link: `${serverBaseUrl}/js/lazyload.min.js`,
integrity: 'sha384-ZjtdUVt9uqIO0cVuZ4zQ5r/1QqXlGIct+PFRAMtAlSz3F4apy925Pn5Tm3hnczMg',
called: false,
loaded: false
},
"jqueryuijs": {
type: 'script',
id: 'jqueryui-js',
link: 'https://code.jquery.com/ui/1.13.1/jquery-ui.js',
integrity: 'sha384-KUSBBRKMO05pX3xNidXAX5N1p4iNwntmhHY4iugl7mINOyOXFL4KZWceJtMj7M0A',
called: false,
loaded: false
},
"jqueryuicss": {
type: 'style',
id: 'jqueryui-css',
link: 'https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css',
integrity: 'sha384-Wh/opNnCPQdVc7YXIh18hoqN6NYg40GBaO/GwQSwrIbAIo8uCeYri2DX2IisvVP6',
called: false,
loaded: false
},
"searchFriend": {
type: 'script',
id: 'searchFriendJs',
link: '/js/search-friends.js',
called: false,
loaded: false
},
"socket": {
type: 'script',
id: 'socketjs',
link: 'https://cdn.socket.io/4.5.1/socket.io.min.js',
integrity: 'sha384-dZoVd6Ro98cGu3vTPJeEj0bVrpH2p/SgENb5iMjpBTSMobGNb6Fg+M5CJ2RHq+H2',
called: false,
loaded: false
}
};
// let indexCallLoad = 0;
let timer,
/** @type {Member} */
currentUser,
/**@type {Member} */
user,
fnLazy,
state = {};
const system = {
/**
* Initialisation du script
*/
init: function() {
return new Promise((res) => {
const $head = $('head');
$head.append(`<link rel="dns-prefetch" href="${new URL(serverOauthUrl).origin}">`);
$head.append(`<link rel="dns-prefetch" href="${new URL(serverBaseUrl).origin}">`);
$head.append(`<link rel="preconnect" href="${new URL(serverBaseUrl).origin}" crossorigin>`);
$head.append(`<link rel="dns-prefetch" href="${new URL(UsBetaSeries.api.url).origin}">`);
$head.append(`<link rel="preconnect" href="${new URL(UsBetaSeries.api.url).origin}" crossorigin>`);
system.updateResources();
/*
CHARGEMENT LIBRARY SearchFriend pour la recommandation à un ami
*/
if (typeof SearchFriend === 'undefined') {
system.addScriptAndLink(['searchFriend']);
}
/*
* AJOUT DU LOADER
*/
$('#popup-bg').after('<div id="loader-bg"><i class="fa-solid fa-sync fa-spin fa-4x"></i><span class="sr-only">Loading...</span></div>');
// Ajout des feuilles de styles pour le userscript
system.addScriptAndLink(['awesome6', 'stylehome']);
if (UsBetaSeries.userIdentified()) {
Member.fetch().then(member => {
/** @type {Member} */
user = unsafeWindow.user = member;
UsBetaSeries.member = member;
res(member);
// On affiche la version du script
if (typeof GM_info !== 'undefined') {
log('%cUserScript BetaSeries%c: v%s - %cMembre%c: %s', 'color:#e7711b', 'color:inherit', GM_info.script.version, 'color:#00979c', 'color:inherit', user.login);
} else {
log('%cUserScript BetaSeries%c - %cMembre%c: %s', 'color:#e7711b', 'color:inherit', 'color:#00979c', 'color:inherit', user.login);
}
if (jQuery('.menu-icon--bell').length > 0) {
jQuery('.menu-icon--bell').replaceWith(`<span class="menu-icon menu-icon-bell fa-solid fa-bell"></span>`);
}
// On désactive les fonctions de notifications originales
unsafeWindow.notificationChecker = () => {};
unsafeWindow.growlNotificationChecker = () => {};
$('.js-iconNotifications').off('click').on('click', (e) => {
e.stopPropagation();
$("body").toggleClass("menu-open").toggleClass("menu-open--notifications");
const $growl = $("#growl");
if ($growl.hasClass("visible")) {
$growl.removeClass("visible");
localStorage.removeItem("seen-growl-notifications");
if (member.notifications.seen) {
markAllNotificationsAsSeen();
member.notifications.markAllAsSeen();
}
} else {
member.renderNotifications();
}
$(".notification--standalone").remove();
});
$(".js-close-elements").off('click').on("click", () => {
// close notifications
$('#growl').removeClass('visible');
$("body").toggleClass("menu-open").toggleClass("menu-open--notifications");
if (user.notifications.seen) {
markAllNotificationsAsSeen();
user.notifications.markAllAsSeen();
}
});
});
} else {
if (typeof GM_info !== 'undefined') {
// log('GM_info', GM_info);
// On affiche la version du script
log('%cUserScript BetaSeries%c: v%s - %cMembre%c: Guest', 'color:#e7711b', 'color:inherit', GM_info.script.version, 'color:#00979c', 'color:inherit');
}
}
system.checkApiVersion();
/*
* BANDEAU DE NAVIGATION DU SITE WEB
*/
(function navigation() {
/** @type {jQuery<HTMLElement>} */
const $nav = $('nav#top'); // Jquery<HTMLElement> Bandeau de navigation
let forceNotScrolled = false; // Permet de forcer ou non la taille initiale du bandeau
/*
* Permet de diminuer ou remettre à la normale, le bandeau de navigation durant le scrolling
*/
const boundHandleScroll = function() {
$nav.toggleClass('scrolled', (window.visualViewport.pageTop > 40 && !forceNotScrolled));
};
boundHandleScroll('call initial');
window.addEventListener("scroll", boundHandleScroll);
$('#reactjs-header-search .menu-item > button').on('click', () => {
/*
* Force la taille du bandeau de navigation à sa taille initiale,
* lors d'une recherche de média
*/
forceNotScrolled = true;
$nav.removeClass('scrolled');
$nav.addClass('search');
system.waitDomPresent('#reactjs-header-search .menu-item form', () => {
$('#reactjs-header-search .menu-item form button:last-child').on('click', () => {
$nav.removeClass('search');
forceNotScrolled = false;
boundHandleScroll();
});
});
});
})();
/*
LAZYLOAD
*/
system.addScriptAndLink('lazyload', () => {
fnLazy = function() {
$(optionsLazyload.selector).lazyload(optionsLazyload);
};
});
/**
* FORMULAIRE DE RECHERCHE DE MEDIAS
*
* Permet d'ajouter des améliorations au menu de recherche du site
*/
(function headerSearch() {
let timer = false, leftTime = Date.now(), beObs = false;
const updateResults = () => {
const $containerResults = $('.ComponentHeaderSearchContainer');
if ($containerResults.length <= 0) { log('updateResults ComponentHeaderSearchContainer not found'); return; }
log('headerSearch updateResults');
const updateTitle = (i, e) => {
log('headerSearch updateTitle', i);
if (system.isTruncated(e)) {
$(e).parents('a').attr('title', $(e).text());
}
};
const updateImg = (i, elt) => {
log('headerSearch updateImg[%d]', i);
const $elt = $(elt);
const $col = $elt.parents('.col-md-4').first();
// log('col', $col);
if ($col.hasClass('show_searchResult')) {
// Show
const slug = $elt.attr('href').split('/').pop();
Show.fetchByUrl(slug).then((show) => {
/**
* @typedef {Show} show
*/
if (show.in_account && show.user.status > 0) {
log('show[%s]: found and viewed', slug);
$('.mainLink', $elt)
.css('textDecoration', 'line-throught')
.css('color', 'red');
}
})
} else if ($col.hasClass('movie_searchResult')) {
// Movie
const title = $('.mainLink', $elt).text().trim();
Movie.search(title).then(movie => {
/**
* @typedef {Movie} movie
*/
if (movie.in_account && movie.user.status > 0) {
$('.mainLink', $elt)
.css('textDecoration', 'line-throught')
.css('color', 'red');
}
})
}
};
$('.col-md-4', $containerResults).each((i, elt) => {
log('headerSearch updateResults col[%d] found', i);
const $elt = $(elt);
$('.mainLink', $elt).each(updateTitle);
$('a.js-searchResult', $elt).each(updateImg);
});
}
// On observe l'espace lié à la recherche de séries ou de films, en haut de page.
// Afin de modifier quelque peu le résultat, pour pouvoir lire l'intégralité du titre
const observer = new MutationObserver(mutationsList => {
for (let mutation of mutationsList) {
log('Observer HeaderSearch mutation', mutation);
if (mutation.type == 'childList' && mutation.addedNodes.length === 1) {
const $target = $(mutation.target);
if (!beObs && $target.hasClass('b_e')) {
observer.observe(mutation.target, { childList: true, subtree: true });
beObs = true;
}
/** @type {JQuery<HTMLElement>} */
const $node = $(mutation.addedNodes[0]);
/* if ($node.hasClass('js-searchResult')) {
if (timer && (Date.now() - leftTime) < 2000) clearTimeout(timer);
timer = setTimeout(updateResults, 2000);
} */
if (mutation.addedNodes[0].nodeName.toLowerCase() === 'form') {
$('input', $node).on('keyup', (e) => {
const target = $(e.currentTarget);
log('HeaderSearch input value', e.currentTarget.value);
if (target && /^imdb:\s*tt\d+/i.test(target.val())) {
e.stopPropagation();
const imdb_id = target.val().match(/^imdb:\s*(tt\d+)/i)[1].trim();
log('HeaderSearch imdb_id: ', imdb_id);
Show.fetchByImdb(imdb_id, true).then(show => {
let template = `
<div class="col-md-4 kz_k1 show_searchResult">
<div class="ComponentHeaderSearchTitle kz_il">Séries</div>
<div style="max-height: 580px; overflow-y: hidden;">
<a href="${show.resource_url}"
class="js-searchResult kv_kx">
<div class="media">
<div class="media-left">
<img class="greyBorder"
src="${show.images.poster}"
width="27" height="40" alt="Affiche de ${show.title}">
</div>
<div class="media-body media-body--ellipsis">
<div class="mainLink" style="margin-top: 1px;">${show.title}</div>
<div class="mainTime" style="margin-top: 2px; display: flex;">
<div>${show.creation}</div>
</div>
</div>
</div>
</a>
</div>
</div>
`;
$('.ComponentHeaderSearchContainer .row').empty().prepend(template);
});
Movie.fetchByImdb(imdb_id, true).then(movie => {
let template = `
<div class="col-md-4 kz_k1 movie_searchResult">
<div class="ComponentHeaderSearchTitle kz_il">Films</div>
<div style="max-height: 580px; overflow-y: hidden;">
<a href="${movie.resource_url}"
class="js-searchResult kv_kx">
<div class="media">
<div class="media-left">
<img class="greyBorder"
src="${movie.poster}"
width="27" height="40" alt="Affiche de ${movie.title}">
</div>
<div class="media-body media-body--ellipsis">
<div class="mainLink" style="margin-top: 1px;">${movie.title}</div>
<div class="mainTime" style="margin-top: 2px; display: flex;">
<div>${movie.creation}</div>
</div>
</div>
</div>
</a>
</div>
</div>
`;
$('.ComponentHeaderSearchContainer .row').empty().prepend(template);
});
}
else if (target && /^tvdb:\s*\d+/i.test(target.val())) {
e.stopPropagation();
const tvdb_id = target.val().match(/^tvdb:\s*(\d+)/i)[1].trim();
log('HeaderSearch tvdb_id: ', tvdb_id);
Show.fetchByTvdb(tvdb_id).then(show => {
let template = `
<div class="col-md-4 kz_k1 show_searchResult">
<div class="ComponentHeaderSearchTitle kz_il">Séries</div>
<div style="max-height: 580px; overflow-y: hidden;">
<a href="${show.resource_url}"
class="js-searchResult kv_kx">
<div class="media">
<div class="media-left">
<img class="greyBorder"
src="${show.images.poster}"
width="27" height="40" alt="Affiche de ${show.title}">
</div>
<div class="media-body media-body--ellipsis">
<div class="mainLink" style="margin-top: 1px;">${show.title}</div>
<div class="mainTime" style="margin-top: 2px; display: flex;">
<div>${show.creation}</div>
</div>
</div>
</div>
</a>
</div>
</div>
`;
$('.ComponentHeaderSearchContainer .row').empty().prepend(template);
});
}
else if (target && /^tmdb:\s*\d+/i.test(target.val())) {
e.stopPropagation();
const tmdb_id = target.val().match(/^tmdb:\s*(\d+)/i)[1].trim();
log('HeaderSearch tmdb_id: ', tmdb_id);
Movie.fetchByTmdb(tmdb_id, true).then(movie => {
let template = `
<div class="col-md-4 kz_k1 movie_searchResult">
<div class="ComponentHeaderSearchTitle kz_il">Films</div>
<div style="max-height: 580px; overflow-y: hidden;">
<a href="${movie.resource_url}"
class="js-searchResult kv_kx">
<div class="media">
<div class="media-left">
<img class="greyBorder"
src="${movie.poster}"
width="27" height="40" alt="Affiche de ${movie.title}">
</div>
<div class="media-body media-body--ellipsis">
<div class="mainLink" style="margin-top: 1px;">${movie.title}</div>
<div class="mainTime" style="margin-top: 2px; display: flex;">
<div>${movie.creation}</div>
</div>
</div>
</div>
</a>
</div>
</div>
`;
$('.ComponentHeaderSearchContainer .row').empty().prepend(template);
});
}
});
}
}
}
});
observer.observe(document.getElementById('reactjs-header-search'), { childList: true, subtree: true });
})();
});
},
/**
* Met à jour les attributs integrity des ressources CSS et JS
* Et ajoute le numéro de version du build aux URLs
* @returns {void}
*/
updateResources: function() {
if (Object.keys(resources) <= 0) {
return;
}
const version = resources.version;
// log('updateResources', resources);
for (const resKey in resources.resources) {
// log('updateResources key: %s', resKey);
if (!scriptsAndStyles[resKey]) {
continue;
}
const res = resources.resources[resKey];
const key = Object.keys(res).shift();
// log('updateResources subkey: %s - res: %s', key, res);
if (key && scriptsAndStyles[resKey].integrity) {
scriptsAndStyles[resKey].integrity = res[key];
}
scriptsAndStyles[resKey].link += '?v=' + version;
}
},
/**
* Patiente en attendant que la fonction de check soit OK
* @param {Function} check - La fonction de vérification de fin d'attente
* @param {Function} cb - La fonction de callback
* @param {number} timeout - Le nombre de secondes avant d'arrêter l'attente
* @param {number} interval - La valeur de l'intervalle entre chaque vérification en ms
*/
waitPresent: function(check, cb, timeout = 2, interval = 50) {
let loopMax = (timeout * 1000) / interval;
let timer = setInterval(() => {
if (--loopMax <= 0) {
if (debug) console.warn('waitPresent timeout');
clearInterval(timer);
return cb('error');
}
if (!check()) return;
clearInterval(timer);
return cb();
}, interval);
},
/**
* Patiente le temps du chargement du DOM, en attente d'une noeud identifié par le selector
* @param {string} selector - Le selecteur jQuery
* @param {Function} cb - La fonction de callback
* @param {number} timeout - Le nombre de secondes avant d'arrêter l'attente
* @param {number} interval - La valeur de l'intervalle entre chaque vérification en ms
*/
waitDomPresent: function(selector, cb, timeout = 2, interval = 50) {
const check = function() {
return $(selector).length > 0;
}
system.waitPresent(check, (err) => {
if (err) {
console.warn('Timeout waitDomPresent: %s', selector);
return;
}
cb();
}, timeout, interval);
},
/**
* Verifie si l'élément est tronqué, généralement, du texte
* @params {Object} Objet DOMElement
* @return {boolean}
*/
isTruncated: function(el) {
return el.scrollWidth > el.clientWidth;
},
/**
* Identifie, stocke et retourne le theme CSS utilisé (light or dark)
* stocké dans window.theme
* @returns {void}
*/
checkThemeStyle: function() {
if (window.theme !== undefined) {
return window.theme;
}
window.theme = 'light';
const stylesheets = $('link[rel="stylesheet"]');
for (let s = 0; s < stylesheets.length; s++) {
if (/dark.css/.test(stylesheets[s].href)) {
window.theme = 'dark';
}
}
return window.theme;
},
/**
* Cette fonction vérifie la dernière version de l'API
*/
checkApiVersion: function() {
fetch(location.origin + '/api/versions').then((resp) => {
if (!resp.ok) {
return '';
}
return resp.text();
}).then(html => {
if (html && html.length > 0) {
// Convert the HTML string into a document object
const parser = new DOMParser(),
doc = parser.parseFromString(html, 'text/html');
// $('.maincontent > ul > li > strong').last().text().trim().split(' ')[1]
const latest = doc.querySelector('.maincontent > ul > li:last-child > strong').textContent.split(' ')[1].trim(),
lastF = parseFloat(latest);
if (!Number.isNaN(lastF) && lastF > parseFloat(UsBetaSeries.api.versions.last)) {
window.alert("L'API possède une nouvelle version: " + latest);
}
log("%cAPI BetaSeries%c: v%s", 'color:#e7711b', 'color:inherit', latest);
}
});
},
/**
* Permet d'afficher les messages d'erreur liés au script
*
* @param {String} title Le titre du message
* @param {String} text Le texte du message
* @return {void}
*/
notification: function(title, text) {
// GM_notification(details, ondone), GM_notification(text, title, image, onclick)
let notifContainer = $('.userscript-notifications');
// On ajoute notre zone de notifications
if ($('.userscript-notifications').length <= 0) {
$('#fb-root').after('<div class="userscript-notifications"><h3><span class="title"></span><i class="fa-solid fa-xmark" aria-hidden="true"></i></h3><p class="text"></p></div>');
notifContainer = $('.userscript-notifications');
$('.userscript-notifications .fa-xmark').on('click', () => {
$('.userscript-notifications').slideUp();
});
}
notifContainer.hide();
$('.userscript-notifications .title').html(title);
$('.userscript-notifications .text').html(text);
notifContainer.slideDown()/* .delay(5000).slideUp() */;
console.warn(text);
console.trace('Notification');
},
/**
* addScriptAndLink - Permet d'ajouter un script ou un link sur la page Web
*
* @param {String|String[]} name Le ou les identifiants des éléments à charger
* @param {function} [onloadFn] - Fonction de callback appelée après le chargement des scripts
* @return {void}
*/
addScriptAndLink: function(name, onloadFn = noop) {
const logLoad = logger.extend('load').fnDebug;
// console.log('addScriptAndLink logLoad', logLoad);
if (name instanceof Array) {
logLoad('addScriptAndLink array.length = %d', name.length);
if (name.length > 1) {
const elt = name.shift();
system.addScriptAndLink(elt, () => system.addScriptAndLink(name, onloadFn) );
return;
} else if (name.length === 1) {
name = name.shift();
} else {
return;
}
}
// index = index || ++indexCallLoad;
logLoad('addScriptAndLink: %s', name);
// On vérifie que le nom est connu
if (!scriptsAndStyles || !(name in scriptsAndStyles)) {
throw new Error(`${name} ne fait pas partit des données de scripts ou de styles`);
}
const loadScript = function(data, cb) {
const loadErrorScript = function(oError) {
logLoad('loadErrorScript error', oError);
console.error("The script " + oError.target.src + " didn't load correctly.");
}
const onloadFn = function() {
logLoad('script(%s) chargé, on renvoie le callback', name);
data.loaded = true;
cb();
};
loadJS(data.link, {
integrity: data.integrity,
id: data.id,
crossOrigin: 'anonymous',
referrerPolicy: 'no-referrer'
}, onloadFn, loadErrorScript);
};
const loadStyle = function(data, cb) {
const loadErrorStyle = function(oError) {
logLoad('loadErrorStyle error', oError);
console.error("The style " + oError.target.href + " didn't load correctly.");
}
onloadFn = function() {
logLoad('style(%s) chargé, on renvoie le callback', name);
data.loaded = true;
cb();
};
loadCSS( data.link, null, data.media, {
integrity: data.integrity,
id: data.id,
crossOrigin: 'anonymous',
referrerPolicy: 'no-referrer'
}, onloadFn, loadErrorStyle );
};
const data = scriptsAndStyles[name];
if (Array.isArray(data)) {
const nbData = data.length;
let nbLoaded = 0;
const callback = () => {
if (++nbLoaded === nbData) onloadFn();
};
for (let d = 0; d < nbData; d++) {
data[d].called = true;
if (data[d].type === 'script') loadScript(data[d], callback);
else if (data[d].type === 'style') loadStyle(data[d], callback);
}
}