<commit_before>if(typeof(String.prototype.trim) === "undefined")
{
    String.prototype.trim = function() 
    {
        return String(this).replace(/^\s+|\s+$/g, '');
    };
}

var Ster24 = window.Ster24 || {
  data: {},
  queue: [],
  player: undefined,
  startup: true,
};

function onYouTubePlayerReady(playerId) {
  console.log('youtube player ready!');
  Ster24.data.player = document.getElementById("myytplayer");
  Ster24.data.player.addEventListener("onStateChange", "onytplayerStateChange");
  Ster24.data.player.playVideo();
}

function onytplayerStateChange(newState) {
  // This event fires whenever the player's state changes. The value that the API passes to your event listener function will specify an integer that corresponds to the new player state. Possible values are:
  // -1 (unstarted)
  // 0 (ended)
  // 1 (playing)
  // 2 (paused)
  // 3 (buffering)
  // 5 (video cued).
  console.log("Player's new state: " + newState);
  if ((newState == -1) || (newState == 5)) {
    Ster24.data.player.playVideo();
  }
  
  if (newState == 0) {
    Ster24.process_queue();
  }
}

Ster24.init = function() {
  console.log('ster24 inited!');
  Ster24.fetch_new_ad();
};

Ster24.fetch_new_ad = function() {
  if (Ster24.queue.length <= 10) {
    $.get('/random', function (data) {
      var product = data.advertiserdescr.trim();
      console.log('got a new ad: ' + product);
      //console.dir(data);
      Ster24.search_youtube(product + ' reclame');
    }, 'json');
  }
};

Ster24.search_youtube = function(terms) {
  $.get(
    'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + terms.replace(/\s+/g, '+').toLowerCase() + '&videoDuration=short&videoEmbeddable=true&type=video&key=<KEY>',
    function (data) {
      console.log('got youtube data!:');
      console.dir(data);
      if (data.items.length > 0) {
        var youtubeID = data.items[0].id.videoId;
        if (Ster24.queue.indexOf(youtubeID) < 0) {
          Ster24.queue.push(youtubeID);
          if (Ster24.startup) {
            Ster24.startup = false;
            Ster24.process_queue();
          }
        }
      } else {
        console.log('no youtube video found for : ' + terms.replace(/\s+/g, '+'));
      }
      Ster24.fetch_new_ad();
    }, 'json');
};

Ster24.process_queue = function() {
  if (Ster24.queue.length <= 0) {
    // load new video in background
    return;
  }

  if (typeof(Ster24.data.player) == 'undefined') {
    var youtubeID = Ster24.queue.pop();
    console.log('Embedding youtube video ' + youtubeID);
    var params = { allowScriptAccess: "always" };
        var atts = { id: "myytplayer" };
        swfobject.embedSWF("http://www.youtube.com/v/" + youtubeID + "?enablejsapi=1&playerapiid=ytplayer&version=3",
                           "ytapiplayer", "425", "356", "8", null, null, params, atts);    
  } else {
    var youtubeID = Ster24.queue.pop();<commit_msg>Allow youtube video to go full screen.<commit_after>if(typeof(String.prototype.trim) === "undefined")
{
    String.prototype.trim = function() 
    {
        return String(this).replace(/^\s+|\s+$/g, '');
    };
}

var Ster24 = window.Ster24 || {
  data: {},
  queue: [],
  player: undefined,
  startup: true,
};

function onYouTubePlayerReady(playerId) {
  console.log('youtube player ready!');
  Ster24.data.player = document.getElementById("myytplayer");
  Ster24.data.player.addEventListener("onStateChange", "onytplayerStateChange");
  Ster24.data.player.playVideo();
}

function onytplayerStateChange(newState) {
  // This event fires whenever the player's state changes. The value that the API passes to your event listener function will specify an integer that corresponds to the new player state. Possible values are:
  // -1 (unstarted)
  // 0 (ended)
  // 1 (playing)
  // 2 (paused)
  // 3 (buffering)
  // 5 (video cued).
  console.log("Player's new state: " + newState);
  if ((newState == -1) || (newState == 5)) {
    Ster24.data.player.playVideo();
  }
  
  if (newState == 0) {
    Ster24.process_queue();
  }
}

Ster24.init = function() {
  console.log('ster24 inited!');
  Ster24.fetch_new_ad();
};

Ster24.fetch_new_ad = function() {
  if (Ster24.queue.length <= 10) {
    $.get('/random', function (data) {
      var product = data.advertiserdescr.trim();
      console.log('got a new ad: ' + product);
      //console.dir(data);
      Ster24.search_youtube(product + ' reclame');
    }, 'json');
  }
};

Ster24.search_youtube = function(terms) {
  $.get(
    'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + terms.replace(/\s+/g, '+').toLowerCase() + '&videoDuration=short&videoEmbeddable=true&type=video&key=<KEY>',
    function (data) {
      console.log('got youtube data!:');
      console.dir(data);
      if (data.items.length > 0) {
        var youtubeID = data.items[0].id.videoId;
        if (Ster24.queue.indexOf(youtubeID) < 0) {
          Ster24.queue.push(youtubeID);
          if (Ster24.startup) {
            Ster24.startup = false;
            Ster24.process_queue();
          }
        }
      } else {
        console.log('no youtube video found for : ' + terms.replace(/\s+/g, '+'));
      }
      Ster24.fetch_new_ad();
    }, 'json');
};

Ster24.process_queue = function() {
  if (Ster24.queue.length <= 0) {
    // load new video in background
    return;
  }

  if (typeof(Ster24.data.player) == 'undefined') {
    var youtubeID = Ster24.queue.pop();
    console.log('Embedding youtube video ' + youtubeID);
    var params = { allowScriptAccess: "always", allowFullScreen: "true" };
        var atts = { id: "myytplayer" };
        swfobject.embedSWF("http://www.youtube.com/v/" + youtubeID + "?enablejsapi=1&playerapiid=ytplayer&version=3",
                           "ytapiplayer", "425", "356", "8", null, null, params, atts);    
  } else {
    var youtubeID = Ster24.queue.pop();
{'fraction_non_alphanumeric': 0.16849127608621278, 'fraction_numerical': 0.02565856996236743, 'mean_word_length': 2.950675675675676, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '3923487', 'n_tokens_mistral': 2090, 'n_tokens_neox': 1967, 'n_words': 393}