Aichatbot12321 commited on
Commit
82ea5ea
·
verified ·
1 Parent(s): 60c86bf

Update youtube.html

Browse files
Files changed (1) hide show
  1. youtube.html +49 -24
youtube.html CHANGED
@@ -700,54 +700,79 @@ document.addEventListener('visibilitychange', () => {
700
  }
701
  });
702
 
703
- // --- CORE PLAYER ENGINE (UPDATED WITH DELAY HACK) ---
704
 
705
  function startMultiplePlayback(idArray) {
706
- document.getElementById('player-overlay').style.display = 'block';
 
707
  rebuildPlayerDOM();
708
 
709
- // 1. Force fullscreen and orientation lock FIRST
710
- if (document.documentElement.requestFullscreen) { document.documentElement.requestFullscreen().catch(e=>{}); }
711
- if (screen.orientation && screen.orientation.lock) { screen.orientation.lock('landscape').catch(e=>{}); }
712
 
713
- // 2. Wait 300ms for that specific device to finish rotating BEFORE spawning the iframe
 
 
 
 
 
 
 
 
 
 
 
714
  setTimeout(() => {
715
  ytPlayer = new YT.Player('player-target', {
716
- playerVars: { autoplay: 1, rel: 0, modestbranding: 1 },
 
717
  events: { 'onReady': (e) => { e.target.loadPlaylist(idArray); }, 'onStateChange': handleIframeStateChange }
718
  });
719
- }, 300);
720
  }
721
 
722
  function playVid(safeData) {
723
  const data = JSON.parse(decodeURIComponent(safeData));
724
  currentVideoData = data;
725
- document.getElementById('player-overlay').style.display = 'block';
 
 
726
  rebuildPlayerDOM();
727
 
728
- // 1. Force fullscreen and orientation lock FIRST
729
- if (document.documentElement.requestFullscreen) { document.documentElement.requestFullscreen().catch(e=>{}); }
730
- if (screen.orientation && screen.orientation.lock) { screen.orientation.lock('landscape').catch(e=>{}); }
 
 
 
 
 
 
731
 
732
- // 2. Wait 300ms for the DOM to settle and the screen to rotate
 
 
 
 
733
  setTimeout(() => {
734
  const startSec = data.timeWatched ? Math.floor(data.timeWatched) : 0;
735
- lastSavedTime = -1; // Reset memory logic on new video
 
 
 
 
 
736
 
737
  if (data.type === 'playlist' && data.id) {
738
- ytPlayer = new YT.Player('player-target', {
739
- playerVars: { listType: 'playlist', list: data.id, rel: 0, modestbranding: 1 },
740
- events: { 'onReady': (e) => { e.target.playVideo(); }, 'onStateChange': handleIframeStateChange }
741
- });
742
  } else {
743
- ytPlayer = new YT.Player('player-target', {
744
- videoId: data.id,
745
- playerVars: { start: startSec, autoplay: 1, rel: 0, modestbranding: 1 },
746
- events: { 'onReady': (e) => { e.target.playVideo(); }, 'onStateChange': handleIframeStateChange }
747
- });
748
  }
 
 
749
  startSavingHistory();
750
- }, 300);
751
  }
752
 
753
  async function handleIframeStateChange(event) {
 
700
  }
701
  });
702
 
703
+ // --- CORE PLAYER ENGINE (THE FULLSCREEN OVERLAY HACK) ---
704
 
705
  function startMultiplePlayback(idArray) {
706
+ const overlay = document.getElementById('player-overlay');
707
+ overlay.style.display = 'block';
708
  rebuildPlayerDOM();
709
 
710
+ // 1. Force the page to scroll to the absolute top so the browser doesn't offset the video
711
+ window.scrollTo(0, 0);
 
712
 
713
+ // 2. Fullscreen the OVERLAY specifically, NOT the document
714
+ if (overlay.requestFullscreen) {
715
+ overlay.requestFullscreen().catch(e=>{});
716
+ } else if (overlay.webkitRequestFullscreen) { /* Safari catch */
717
+ overlay.webkitRequestFullscreen();
718
+ }
719
+
720
+ if (screen.orientation && screen.orientation.lock) {
721
+ screen.orientation.lock('landscape').catch(e=>{});
722
+ }
723
+
724
+ // 3. Give the device 500ms to finish its rotation animation before spawning the iframe
725
  setTimeout(() => {
726
  ytPlayer = new YT.Player('player-target', {
727
+ // Added playsinline: 1 to stop iOS from hijacking the player
728
+ playerVars: { autoplay: 1, rel: 0, modestbranding: 1, playsinline: 1 },
729
  events: { 'onReady': (e) => { e.target.loadPlaylist(idArray); }, 'onStateChange': handleIframeStateChange }
730
  });
731
+ }, 500);
732
  }
733
 
734
  function playVid(safeData) {
735
  const data = JSON.parse(decodeURIComponent(safeData));
736
  currentVideoData = data;
737
+
738
+ const overlay = document.getElementById('player-overlay');
739
+ overlay.style.display = 'block';
740
  rebuildPlayerDOM();
741
 
742
+ // 1. Scroll to top
743
+ window.scrollTo(0, 0);
744
+
745
+ // 2. Fullscreen the OVERLAY specifically
746
+ if (overlay.requestFullscreen) {
747
+ overlay.requestFullscreen().catch(e=>{});
748
+ } else if (overlay.webkitRequestFullscreen) {
749
+ overlay.webkitRequestFullscreen();
750
+ }
751
 
752
+ if (screen.orientation && screen.orientation.lock) {
753
+ screen.orientation.lock('landscape').catch(e=>{});
754
+ }
755
+
756
+ // 3. Wait for the device to settle
757
  setTimeout(() => {
758
  const startSec = data.timeWatched ? Math.floor(data.timeWatched) : 0;
759
+ lastSavedTime = -1;
760
+
761
+ let playerOptions = {
762
+ playerVars: { start: startSec, autoplay: 1, rel: 0, modestbranding: 1, playsinline: 1 },
763
+ events: { 'onReady': (e) => { e.target.playVideo(); }, 'onStateChange': handleIframeStateChange }
764
+ };
765
 
766
  if (data.type === 'playlist' && data.id) {
767
+ playerOptions.playerVars.listType = 'playlist';
768
+ playerOptions.playerVars.list = data.id;
 
 
769
  } else {
770
+ playerOptions.videoId = data.id;
 
 
 
 
771
  }
772
+
773
+ ytPlayer = new YT.Player('player-target', playerOptions);
774
  startSavingHistory();
775
+ }, 500);
776
  }
777
 
778
  async function handleIframeStateChange(event) {