@@ -64,29 +64,50 @@ export const soundMode = {
6464export const MAIN_SCRIPT = (
6565 videoId ,
6666 playList ,
67- {
68- loop = false ,
69- controls = true ,
70- cc_lang_pref, // country code
71- showClosedCaptions,
72- color, // 'red' or 'white'
67+ initialPlayerParams ,
68+ allowWebViewZoom ,
69+ ) => {
70+ const {
7371 end,
74- preventFullScreen = false ,
72+ rel,
73+ color,
74+ start,
7575 playerLang,
76+ loop = false ,
77+ cc_lang_pref,
7678 iv_load_policy,
7779 modestbranding,
78- rel,
79- start,
80- } ,
81- allowWebViewZoom
82- ) => `<!DOCTYPE html>
80+ controls = true ,
81+ showClosedCaptions,
82+ preventFullScreen = false ,
83+ } = initialPlayerParams ;
84+
85+ // _s postfix to refer to "safe"
86+ const rel_s = rel ? 1 : 0 ;
87+ const loop_s = loop ? 1 : 0 ;
88+ const videoId_s = videoId || '' ;
89+ const controls_s = controls ? 1 : 0 ;
90+ const cc_lang_pref_s = cc_lang_pref || '' ;
91+ const modestbranding_s = modestbranding ? 1 : 0 ;
92+ const preventFullScreen_s = preventFullScreen ? 0 : 1 ;
93+ const showClosedCaptions_s = showClosedCaptions ? 1 : 0 ;
94+ const list = typeof playList === 'string' ? playList : '' ;
95+ const listType = typeof playList === 'string' ? 'playlist' : '' ;
96+
97+ // scale will either be "initial-scale=0.8"
98+ let scale = 'initial-scale=0.8' ;
99+ if ( allowWebViewZoom ) {
100+ // or "initial-scale=0.8, maximum-scale=0.8"
101+ scale += ', maximum-scale=0.8' ;
102+ }
103+
104+ return `
105+ <!DOCTYPE html>
83106<html>
84107 <head>
85108 <meta
86109 name="viewport"
87- content="width=device-width, initial-scale=0.8${
88- allowWebViewZoom ? '' : ', maximum-scale=0.8'
89- } "
110+ content="width=device-width, ${ scale } "
90111 >
91112 <style>
92113 body {
@@ -122,25 +143,25 @@ export const MAIN_SCRIPT = (
122143 var player;
123144 function onYouTubeIframeAPIReady() {
124145 player = new YT.Player('player', {
125- height: '1000',
126146 width: '1000',
127- videoId: '${ videoId || '' } ',
147+ height: '1000',
148+ videoId: '${ videoId_s } ',
128149 playerVars: {
150+ end: ${ end } ,
151+ rel: ${ rel_s } ,
129152 playsinline: 1,
130- loop: ${ loop ? 1 : 0 } ,
131- controls: ${ controls ? 1 : 0 } ,
132- cc_lang_pref: '${ cc_lang_pref || '' } ',
133- cc_load_policy: ${ showClosedCaptions ? 1 : 0 } ,
153+ loop: ${ loop_s } ,
134154 color: ${ color } ,
135- end : ${ end } ,
136- fs: ${ preventFullScreen ? 0 : 1 } ,
155+ start : ${ start } ,
156+ list: ' ${ list } ' ,
137157 hl: ${ playerLang } ,
158+ listType: '${ listType } ',
159+ controls: ${ controls_s } ,
160+ fs: ${ preventFullScreen_s } ,
161+ cc_lang_pref: '${ cc_lang_pref_s } ',
138162 iv_load_policy: ${ iv_load_policy } ,
139- modestbranding: ${ modestbranding ? 1 : 0 } ,
140- rel: ${ rel ? 1 : 0 } ,
141- start: ${ start } ,
142- listType: '${ typeof playList === 'string' ? 'playlist' : '' } ',
143- list: '${ typeof playList === 'string' ? playList : '' } ',
163+ modestbranding: ${ modestbranding_s } ,
164+ cc_load_policy: ${ showClosedCaptions_s } ,
144165 },
145166 events: {
146167 'onReady': onPlayerReady,
@@ -185,4 +206,6 @@ export const MAIN_SCRIPT = (
185206 document.addEventListener('webkitfullscreenchange', onFullScreenChange)
186207 </script>
187208 </body>
188- </html>` ;
209+ </html>
210+ ` ;
211+ } ;
0 commit comments