Greasy Fork is available in English.

video auto size

resize the video to pixel format size

Version vom 20.12.2016. Aktuellste Version

// ==UserScript==
// @name        video auto size
// @description resize the video to pixel format size
// @namespace   gnblizz
// @include     http://kissanime.io/*
// @include     http://kissanime.to/*
// @include     http://kissanime.ru/*
// @version     1.02
// @grant       none
// @compatible  firefox
// ==/UserScript==

var video = document.getElementsByTagName('VIDEO')[0];
if(video) {
  video.onloadedmetadata = setSizeNow;
} else if(location.hostname == 'kissanime.io') {
  var container = document.getElementById('movie-player');
  if(container) {
    var observer = new MutationObserver(function(mutations) {
      mutations.forEach(function(mutation) {
        if(mutation.addedNodes && mutation.addedNodes.length) {
          if(mutation.addedNodes[0].id == 'player_container') {
            observer.disconnect();
            video = document.getElementsByTagName('VIDEO')[0];
            video.onloadedmetadata = setSizeNow;
          }
        }
      });
    });
    observer.observe(container, { attributes: false, childList: true, characterData: false, subtree: false });
  }
}

function setSizeNow(event) {
  var obj, videoWidth = video.videoWidth, videoHeight = video.videoHeight;
  showVideoSizeInfo(video);
  video.style.objectPosition = 'center top';
  switch(location.hostname) {
  case 'kissanime.to':
  case 'kissanime.ru':
    obj = video.parentNode;
    var origWidth = parseInt(obj.style.width), origHeight = parseInt(obj.style.height);
    if(!origWidth) throw 'no width found!'; if(!origHeight) throw 'no height found!';
    var deltaWidth = videoWidth - origWidth, deltaHeight = videoHeight+30 - origHeight;
    do {
      var w = parseInt(obj.style.width), h = parseInt(obj.style.height);
      if(w) obj.style.width = (w + deltaWidth)+'px';
      if(h) obj.style.height = (h + deltaHeight)+'px';
      obj = obj.parentNode;
    } while(obj.id != 'containerRoot' && obj.tagName != 'BODY');
    break;
  case 'kissanime.io':
    obj = document.createElement('STYLE');
    obj.textContent = '#container{width:'+(videoWidth+40)+'px!important;}#player_container{width:'+(videoWidth)+'px!important;height:'+(videoHeight+39)+'px!important;}div#centerDivVideo{max-width:unset;}';
    document.body.appendChild(obj);
    break;
  }
}

function showVideoSizeInfo(video) {
  var div = document.createElement('DIV');
  div.textContent = video.videoWidth + 'x' + video.videoHeight;
  console.log('video size', div.textContent);
  div.style = 'position:absolute;top:1px;left:2px;text_shadow:1px 1px black;font-size:large;font-weight:bold;';
  video.parentNode.appendChild(div);
  setTimeout(function() { div.parentNode.removeChild(div); }, 10000);
}

// public domain by gnblizz
// contact me with my username + '@web.de'