<commit_before><!DOCTYPE html>
<html>
<style type="text/css"> 
 #filecontents { 
  border:double; 
  overflow-y:scroll; 
  height:400px; 
} 
</style>
<script language="javascript">
  //global vars
  var playlist = [];
  var playlistIndex = -1;

  //initialize event handlers on window load
  window.onload = function () 
  { 
    //Check the support for the File API support 
    if (window.File && window.FileReader && window.FileList && window.Blob) 
    {
      var fileSelected = document.getElementById('txtfiletoread');
      fileSelected.addEventListener('change', function (e) 
      { 
        loadPlaylist( fileSelected.files[0] );
      }, false);

      var PISplayer = document.getElementById("PlayItSam");
      PISplayer.addEventListener("ended", function (e)
      {
        playlistIndex = playlistIndex % playlist.length +1; // go to next song when song ends
        playSong();
      }, false);
    } 
    else 
    { 
      alert("Files are not supported"); 
    } 
  }

  //randomly shuffle the playlist
  function randomizePlaylist()
  {
    var reordered = [];
    var numsongs = playlist.length;
    while( playlist.length > 0 )
    {
      num = Math.floor((Math.random() * playlist.length) + 1);
      reordered.push( playlist[num] );
      playlist.splice(num,1);
    }
    playlist = reordered;
  }

  //given a file (plain text in m3u format), load each line as a song file
  function loadPlaylist(file)
  {
    var fileReader = new FileReader(); 
    fileReader.onload = function (e) 
    { 
      var fileContents = document.getElementById('filecontents');
      var allSongs = fileReader.result;
      var eachLine = allSongs.match(/[^\r\n]+/g);
      for(index in eachLine)
      {
        var songname = new String(eachLine[index]);

        if( !songname.match(/^#/) ) //any non-comment line
        {
          playlist.push( songname );
        }
      }
      randomizePlaylist();
      playlistIndex = 0;
      playSong();
    } 
    fileReader.readAsText(file);
  }

  //load song from filename into PlayItSam player
  function loadAndPlaySong(filesong)
  {
    //alert("Playing " + filesong);
    var PISplayer = document.getElementById("PlayItSam");
    PISplayer.src=filesong;
    PISplayer.load();
    PISplayer.play();
  }

  //safely play the current song
  function playSong()
  {
    if( playlistIndex >=0  && playlistIndex < playlist.length )
      loadAndPlaySong(playlist[playlistIndex]);  
  }
</script>
<body>

  Please Select text file of which contents are to be read: 
  <input type="file" id="txtfiletoread" />
  <audio id="PlayItSam" autoplay="true" controls>
    <source id="audioSource" src="" type="audio/mpeg">
      Your browser does not support the audio element.
  </audio>

</body>
</html><commit_msg>Fix randomize infinite loop and remove visual audio controls<commit_after><!DOCTYPE html>
<html>
</style>
<script language="javascript">
  //global vars
  var playlist = [];
  var playlistIndex = -1;

  //initialize event handlers on window load
  window.onload = function () 
  { 
    //Check the support for the File API support 
    if (window.File && window.FileReader && window.FileList && window.Blob) 
    {
      var fileSelected = document.getElementById('txtfiletoread');
      fileSelected.addEventListener('change', function (e) 
      { 
        loadPlaylist( fileSelected.files[0] );
      }, false);

      var PISplayer = document.getElementById("PlayItSam");
      PISplayer.addEventListener("ended", function (e)
      {
        playlistIndex = playlistIndex % playlist.length +1; // go to next song when song ends
        playSong();
      }, false);
    } 
    else 
    { 
      alert("Files are not supported"); 
    } 
  }

  //randomly shuffle the playlist
  function randomizePlaylist()
  {
    var numsongs = playlist.length;
    for(var i = 0; i < numsongs; i++ )
    {
      var num = Math.floor((Math.random() * playlist.length));
      playlist.push( playlist.splice(num,1) ); //remove random item and move it to the end
    }
  }

  //given a file (plain text in m3u format), load each line as a song file
  function loadPlaylist(file)
  {
    var fileReader = new FileReader(); 
    fileReader.onload = function (e) 
    { 
      var allSongs = fileReader.result;
      var eachLine = allSongs.match(/[^\r\n]+/g);
      for(index in eachLine)
      {
        var songname = new String(eachLine[index]);

        if( !songname.match(/^#/) ) //any non-comment line
        {
          playlist.push( songname );
        }
      }
      randomizePlaylist();
      playlistIndex = 0;
      playSong();
    } 
    fileReader.readAsText(file);
  }

  //load song from filename into PlayItSam player
  function loadAndPlaySong(filesong)
  {
    //alert("Playing " + filesong);
    var PISplayer = document.getElementById("PlayItSam");
    PISplayer.src=filesong;
    PISplayer.load();
    PISplayer.play();
  }

  //safely play the current song
  function playSong()
  {
    if( playlistIndex >=0  && playlistIndex < playlist.length )
      loadAndPlaySong(playlist[playlistIndex]);  
  }
</script>
<body>

  Please Select text file of which contents are to be read: 
  <input type="file" id="txtfiletoread" />
  <audio id="PlayItSam" autoplay="true">
    <source id="audioSource" src="" type="audio/mpeg">
      Your browser does not support the audio element.
  </audio>

</body>
</html>
{'fraction_non_alphanumeric': 0.12506968964876417, 'fraction_numerical': 0.003716781267422412, 'mean_word_length': 2.68882796435915, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6365904', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1635, 'n_words': 430}