Commit 62b130a 1 parent b3dff35 commit 62b130a Copy full SHA for 62b130a
File tree 4 files changed +27
-8
lines changed
4 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,13 @@ $(function() {
2
2
3
3
var studyRegex = / l i c h e s s \. o r g \/ s t u d y \/ (?: e m b e d \/ ) ? ( \w { 8 } ) \/ ( \w { 8 } ) ( # \d + ) ? \b / ;
4
4
var gameRegex = / l i c h e s s \. o r g \/ (?: e m b e d \/ ) ? ( \w { 8 } ) (?: (?: \/ ( w h i t e | b l a c k ) ) | \w { 4 } | ) ( # \d + ) ? \b / ;
5
- var youtubeRegex = / (?: h t t p s ? : \/ \/ ) ? (?: w w w \. ) ? (?: y o u t u b e \. c o m | y o u t u \. b e ) \/ (?: w a t c h ) ? (?: \? v = ) ? ( [ ^ " & ? \/ ] { 11 } ) (?: [ ^ \s ] * ) / i;
6
5
var notGames = [ 'training' , 'analysis' , 'insights' , 'practice' ] ;
7
6
8
7
var parseLink = function ( a ) {
9
- var matches = a . href . match ( youtubeRegex ) ;
10
- if ( matches ) return {
8
+ var yt = lichess . toYouTubeEmbedUrl ( a . href ) ;
9
+ if ( yt ) return {
11
10
type : 'youtube' ,
12
- src : 'https://www.youtube.com/embed/' + matches [ 1 ]
11
+ src : yt
13
12
} ;
14
13
var matches = a . href . match ( studyRegex ) ;
15
14
if ( matches && matches [ 2 ] && a . text . match ( studyRegex ) ) return {
Original file line number Diff line number Diff line change @@ -380,6 +380,23 @@ lichess.escapeHtml = function(html) {
380
380
div . appendChild ( document . createTextNode ( html ) ) ;
381
381
return div . innerHTML ;
382
382
} ;
383
+ lichess . toYouTubeEmbedUrl = function ( url ) {
384
+ var m = url . match ( / (?: h t t p s ? : \/ \/ ) ? (?: w w w \. ) ? (?: y o u t u b e \. c o m | y o u t u \. b e ) \/ (?: w a t c h ) ? (?: \? v = ) ? ( [ ^ " & ? \/ ] { 11 } ) (?: \? | & | ) ( \S * ) / i) ;
385
+ if ( ! m ) return ;
386
+ var start = 1 ;
387
+ m [ 2 ] . split ( '&' ) . forEach ( function ( p ) {
388
+ var s = p . split ( '=' ) ;
389
+ if ( s [ 0 ] === 't' || s [ 0 ] === 'start' ) {
390
+ if ( s [ 1 ] . match ( / ^ \d + $ / ) ) start = parseInt ( s [ 1 ] ) ;
391
+ else {
392
+ var n = s [ 1 ] . match ( / (?: ( \d + ) h ) ? (?: ( \d + ) m ) ? (?: ( \d + ) s ) ? / ) ;
393
+ start = ( parseInt ( n [ 1 ] ) || 0 ) * 3600 + ( parseInt ( n [ 2 ] ) || 0 ) * 60 + ( parseInt ( n [ 3 ] ) || 0 ) ;
394
+ }
395
+ }
396
+ } ) ;
397
+ var params = 'modestbranding=1&rel=0&controls=2&iv_load_policy=3&start=' + start ;
398
+ return 'https://www.youtube.com/embed/' + m [ 1 ] + '?' + params ;
399
+ } ;
383
400
$ . spreadNumber = function ( el , nbSteps , getDuration , previous ) {
384
401
var previous = previous ,
385
402
displayed ;
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ div.underboard .notif.error {
123
123
margin-bottom : 10px ;
124
124
}
125
125
.study_comments .text {
126
+ width : 100% ;
126
127
overflow : hidden;
127
128
word-wrap : break-word;
128
129
}
Original file line number Diff line number Diff line change @@ -15,11 +15,13 @@ function authorText(author) {
15
15
return author . name ;
16
16
}
17
17
18
- var commentYoutubeRegex = / (?: h t t p s ? : \/ \/ ) ? (?: w w w \. ) ? (?: y o u t u b e \. c o m | y o u t u \. b e ) \/ (?: w a t c h ) ? (?: \? v = ) ? ( [ ^ " & ? \/ ] { 11 } ) (?: [ ^ \s ] * ) / gi;
18
+ var commentYoutubeRegex = / (?: h t t p s ? : \/ \/ ) ? (?: w w w \. ) ? (?: y o u t u b e \. c o m | y o u t u \. b e ) \/ (?: w a t c h ) ? (?: \? v = ) ? (?: [ ^ " & ? \/ ] { 11 } ) \S * / gi;
19
19
20
20
function embedYoutube ( text ) {
21
- return m . trust ( lichess . escapeHtml ( text ) . replace ( commentYoutubeRegex , function ( m , id ) {
22
- return '<iframe width="100%" height="300" src="https://www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe>' ;
21
+ return m . trust ( lichess . escapeHtml ( text ) . replace ( commentYoutubeRegex , function ( found ) {
22
+ var url = lichess . toYouTubeEmbedUrl ( found ) ;
23
+ if ( ! url ) return found ;
24
+ return '<iframe width="100%" height="300" src="' + url + '" frameborder=0 allowfullscreen></iframe>' ;
23
25
} ) ) ;
24
26
}
25
27
@@ -54,7 +56,7 @@ module.exports = {
54
56
m ( 'span.node' , nodeFullName ( node ) )
55
57
] : null ,
56
58
': ' ,
57
- m ( 'span .text' , embedYoutube ( comment . text ) )
59
+ m ( 'div .text' , embedYoutube ( comment . text ) )
58
60
] ) ;
59
61
} ) ) ;
60
62
}
You can’t perform that action at this time.
0 commit comments