<commit_before>var LEFT_COL_SIZE = 180;
var HEIGHT = 60;
var videosSelector = '.swfObject';
var placeEl = document.querySelector('.clearfix.nubContainer.rNubContainer');

var destineEl = document.querySelector('#youtubeVideos');
if (!destineEl) {
    destineEl = document.createElement('div');
    destineEl.setAttribute('id', 'youtubeVideos');
    destineEl.style.position = 'fixed';
    destineEl.style.bottom = '28px';
    destineEl.style.left = '0px';
    placeEl.appendChild(destineEl);
}

function squizeVideo(element) {
    // Resize elements to the destineEl size
    
    if (!element.dataOriginalWidth) {
        element.dataOriginalWidth = element.style.width;
    }
    element.style.width = LEFT_COL_SIZE + 'px';
    
    if (!element.dataOriginalHeight) {
        element.dataOriginalHeight = element.style.height;
    }
    element.style.height = HEIGHT + 'px';
    
    var iframe = element.querySelector('iframe');
    
    if (!iframe.dataOriginalWidth) {
        iframe.dataOriginalWidth = iframe.getAttribute('width');
    }
    iframe.setAttribute('width', LEFT_COL_SIZE);
    
    if (!iframe.dataOriginalHeight) {
        iframe.dataOriginalHeight = iframe.getAttribute('height');
    }
    iframe.setAttribute('height', HEIGHT);
}

function squizeResetVideo(element) {
    element.style.width = element.dataOriginalWidth + 'px';
    element.style.height = element.dataOriginalHeight + 'px';
    iframe = element.querySelector('iframe');
    iframe.setAttribute('width', iframe.dataOriginalWidth);
    iframe.setAttribute('height', iframe.dataOriginalHeight);
}

function onMouseEnter(event) {
    // mouseEnter handler, will resize to original size, and change zIndex;
    
    squizeResetVideo(this);
    this.style.position = 'relative';
    this.style.bottom = (parseInt(this.dataOriginalHeight) - 60) + 'px';
    
}

function onMouseLeave(event) {
    // mouseEnter handler, will resize to original size, and change zIndex;
    squizeVideo(this);
    
    this.style.position = 'initial';
    this.style.bottom = '0px';
}

setInterval(function () {
    var videos = document.querySelectorAll(videosSelector);
    Array.prototype.forEach.call(videos, function(element) {
        if (element.parentElement !== destineEl) {
            destineEl.insertBefore(element);
            
            squizeVideo(element);
            element.addEventListener('mouseenter', onMouseEnter);
            element.addEventListener('mouseleave', onMouseLeave);
        }
    });    
}, 1e3);
<commit_msg>Added support to viewport, so it only move the video if is out of viewport<commit_after>var LEFT_COL_SIZE = 180;
var HEIGHT = 60;
var videosSelector = '.swfObject';
var placeEl = document.querySelector('.clearfix.nubContainer.rNubContainer');

var destineEl = document.querySelector('#youtubeVideos');
if (!destineEl) {
    destineEl = document.createElement('div');
    destineEl.setAttribute('id', 'youtubeVideos');
    destineEl.style.position = 'fixed';
    destineEl.style.bottom = '28px';
    destineEl.style.left = '0px';
    placeEl.appendChild(destineEl);
}

function squizeVideo(element) {
    // Resize elements to the destineEl size
    
    if (!element.dataOriginalWidth) {
        element.dataOriginalWidth = element.style.width;
    }
    element.style.width = LEFT_COL_SIZE + 'px';
    
    if (!element.dataOriginalHeight) {
        element.dataOriginalHeight = element.style.height;
    }
    element.style.height = HEIGHT + 'px';
    
    if (!element.dataOriginalParent) {
        element.dataOriginalParent = element.parentElement;
    }
    
    var iframe = element.querySelector('iframe');
    
    if (!iframe.dataOriginalWidth) {
        iframe.dataOriginalWidth = iframe.getAttribute('width');
    }
    iframe.setAttribute('width', LEFT_COL_SIZE);
    
    if (!iframe.dataOriginalHeight) {
        iframe.dataOriginalHeight = iframe.getAttribute('height');
    }
    iframe.setAttribute('height', HEIGHT);
}

function squizeResetVideo(element) {
    element.style.width = element.dataOriginalWidth + 'px';
    element.style.height = element.dataOriginalHeight + 'px';
    iframe = element.querySelector('iframe');
    iframe.setAttribute('width', iframe.dataOriginalWidth);
    iframe.setAttribute('height', iframe.dataOriginalHeight);
}

function onMouseEnter(event) {
    // mouseEnter handler, will resize to original size, and change zIndex;
    
    squizeResetVideo(this);
    this.style.position = 'relative';
    this.style.bottom = (parseInt(this.dataOriginalHeight) - 60) + 'px';
    
}

function onMouseLeave(event) {
    // mouseEnter handler, will resize to original size, and change zIndex;
    squizeVideo(this);
    
    this.style.position = 'initial';
    this.style.bottom = '0px';
}

function isElementInViewport(el) {
    var rect = el.getBoundingClientRect();

    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
        rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
    );
}

setInterval(function () {
    var videos = document.querySelectorAll(videosSelector);
    Array.prototype.forEach.call(videos, function(element) {
        if (!isElementInViewport(element) && element.parentElement !== destineEl) {
            destineEl.insertBefore(element);
            
            squizeVideo(element);
            element.addEventListener('mouseenter', onMouseEnter);
            element.addEventListener('mouseleave', onMouseLeave);
        }
    });    
}, 1e3);

{'fraction_non_alphanumeric': 0.12651461154668567, 'fraction_numerical': 0.004989308624376337, 'mean_word_length': 3.4023529411764706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7405296', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1624, 'n_words': 301}