resize the video to pixel format size
当前为
// ==UserScript==
// @name video auto size
// @description resize the video to pixel format size
// @namespace gnblizz
// @include http://kissanime.io/*
// @include http://kissanime.ru/*
// @include https://openload.co/embed/*
// @version 1.03
// @grant none
// @compatible firefox
// ==/UserScript==
console.log('loaded video auto size at:', location.hostname);
var video = document.getElementsByTagName('VIDEO')[0], container;
switch(location.hostname) {
case 'kissanime.ru':
if(video) {
video.onloadedmetadata = setSizeNow;
} else {
container = document.querySelector('#divContentVideo>iframe');
if(container) {
window.addEventListener('message', receiveMessage, false);
var div = document.createElement('div'), resolutions = '1200x800/800x600/640x480'.split('/');
while(resolutions.length) {
var btn = document.createElement('button');
btn.type = 'button';
btn.textContent = resolutions.shift();
btn.onclick = SetResolution;
div.appendChild(btn);
}
btn = document.createElement('style');
btn.textContent = '#adsIfrme button{margin: 2px 10px; background-color: #393939; color: #ccc; border: 1px solid #666666;}';
div.appendChild(btn);
container.parentNode.parentNode.parentNode.appendChild(div);
}
}
break;
case 'kissanime.io':
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 });
}
break;
case 'openload.co':
video.onloadedmetadata = function(event) {
video.style.objectPosition = 'center top';
showVideoSizeInfo(video);
window.top.postMessage('videoformat'+ [video.videoWidth, video.videoHeight].join('x'), 'http://kissanime.ru');
};
break;
}
function receiveMessage(event) {
//console.log('received:', event.data);
if(typeof event.data == 'string') switch(event.data.slice(0,11)) {
case 'videoformat':
var m = event.data.match(/(\d+)x(\d+)$/);
video = { videoWidth: parseInt(m[1]), videoHeight: parseInt(m[2])};
setSizeNow(event);
}
}
function SetResolution(event) {
window.top.postMessage('videoformat' + this.textContent, 'http://kissanime.ru');
}
function setSizeNow(event) {
var obj, videoWidth = video.videoWidth, videoHeight = video.videoHeight;
if(container) {
video = container;
video.style.width = '100%';
video.style.height = '100%';
} else {
showVideoSizeInfo(video);
video.style.objectPosition = 'center top';
}
switch(location.hostname) {
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!';
//video.style.width = '100%'; video.style.height = '100%';
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');
obj = document.querySelectorAll('.divCloseBut>a');
for(var i of obj) { i.click(); }
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'