// ==UserScript== // @name video auto size (kissanime) // @description resize the video to pixel format size // @namespace gnblizz // @homepageURL https://greasyfork.org/en/scripts/25492-video-auto-size-kissanime // @include http://kissanime.io/* // @include https://kissanime.io/* // @include http://kissanime.ru/* // @exclude http://kissanime.ru/xyz/check.aspx // @include https://openload.co/embed/* // @include https://www.rapidvideo.com/* // @version 1.05 // @grant none // @compatible firefox // @compatible chrome // @downloadURL none // ==/UserScript== //console.log('loaded video auto size at:', location.hostname); var video = fn('VIDEO'), container, isTop=window.self==window.top; switch(location.hostname) { case 'kissanime.ru': if(!isTop) break; if(video) { //console.log('static video'); RunIfVideoReady(setSizeNow); } else { container = fn('?#divContentVideo>iframe'); if(container) { //console.log('video in iframe'); window.addEventListener('message', receiveMessage, false); var div = nn('DIV', 0, container.parentNode.parentNode.parentNode), resolutions = '1200x800/800x600/640x480'.split('/'); while(resolutions.length) { nn('BUTTON', { type: 'button', TEXT: resolutions.shift() }, div).onclick = SetResolution; } nn('STYLE', { TEXT: '#adsIfrme button{margin: 2px 10px; background-color: #393939; color: #ccc; border: 1px solid #666666;}' }, div); } else { var h = setInterval(function() { video = fn('VIDEO'); if(video) { //console.log('delayed video'); clearInterval(h); RunIfVideoReady(setSizeNow); } }, 500); } } break; case 'kissanime.io': if(!isTop) break; setTimeout(function() { var myPlayer = videojs('player_html5' + (player_reload || '')); myPlayer.ready(function () { video = fn('VIDEO'); RunIfVideoReady(function(){ var w = video.videoWidth, h = video.videoHeight, i = 'px!important'; showVideoSizeInfo(video); SetStyle( 'video',{objectPosition:'center top'}, 'div#container',{width:(w+40)+i}, 'div#player_html5,div#player_container',{width:(w)+i,height:(h+39)+i}, 'div#centerDivVideo',{maxWidth:'unset'}, 'iframe#videoAd,a.closeVideoAd{display:none!important;}').id = 'autosizestyle'; }); }); }, 3000); break; case 'openload.co': if(isTop) break; RunIfVideoReady(function() { video.style.objectPosition = 'center top'; showVideoSizeInfo(video); if(!document.referrer || document.referrer.startsWith('http://kissanime.ru/')) window.top.postMessage('videoformat'+ [video.videoWidth, video.videoHeight].join('x'), 'http://kissanime.ru'); }); setTimeout(function() { window.popAdsLoaded = 1; fn('#videooverlay').click(); }, 1000);// this should deal with setTimeout(function() { fn('.vjs-poster').click(); window.BetterJsPop.destroy(); }, 2000); // the click thieves. break; case 'www.rapidvideo.com': if(isTop) break; RunIfVideoReady(function() { SetStyle('video', {objectPosition: 'center top', objectFit: 'none !important', backgroundColor: '#111111'}); showVideoSizeInfo(video); if(!document.referrer || document.referrer.startsWith('http://kissanime.ru/')) window.top.postMessage('videoformat'+ [video.videoWidth, video.videoHeight].join('x'), 'http://kissanime.ru'); }); break; } function RunIfVideoReady(cb) { if(!video) video = fn('VIDEO'); if(video.readyState) cb(); else video.onloadedmetadata = cb; } function SetResolution(event) { // button onclick handler window.top.postMessage('videoformat' + this.textContent, 'http://kissanime.ru'); } 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+)$/); if(m) { video = { videoWidth: parseInt(m[1]), videoHeight: parseInt(m[2])}; setSizeNow(event); } } } function setSizeNow(event) { //try{ var obj, videoWidth = video.videoWidth, videoHeight = video.videoHeight; //console.log('videoformat:', videoWidth, videoHeight); if(container) { video = container; video.style.width = '100%'; video.style.height = '100%'; } else { showVideoSizeInfo(video); video.style.objectPosition = 'center top'; } 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'); obj = document.querySelectorAll('.divCloseBut>a'); for(var i of obj) { i.click(); } //}catch(e){console.log(e);} } function showVideoSizeInfo(video) { var div = nn('DIV', { TEXT: video.videoWidth + 'x' + video.videoHeight, style:{ position: 'absolute', top: 1, left: 2, textShadow: '1px 1px black', fontSize: 'large', fontWeight: 'bold'}}, video.parentNode); console.info('video size', div.textContent); setTimeout(function() { rn(div); }, 10000); } // new node function nn(name, attributes, insertion) { var a = name.split('.'), i = a.shift().split('#'), node = document.createElement(i.shift()); if(i[0]) node.id = i[0]; if(a[0]) node.className = a.join(' '); if(attributes) { var names = Object.keys(attributes); for(name of names) { var value = attributes[name]; switch(name) { case 'TEXT': node.textContent = value; break; case 'HTML': node.innerHTML = value; break; case 'style': if(typeof value == 'object') value = ConvertCSS(value); default: node.setAttribute(name, value); } } } if(insertion) { if(insertion.appendChild) insertion.appendChild(node); else { i = Object.keys(insertion)[0]; if(i) { a = insertion[i]; switch(i) { case 'append': a.appendChild(node); break; case 'insert': a.insertBefore(node, a.firstChild); break; case 'before': a.parentNode.insertBefore(node, a); break; case 'after': a.parentNode.insertBefore(node, a.nextSibling); break; } }}} return node; } // find node function fn(name, parent) { if(!parent) parent = document; switch(name.charAt(0)) { case '#': return parent.getElementById(name.slice(1)); case '.': return parent.getElementsByClassName(name.slice(1))[0]; case '?': return parent.querySelector(name.slice(1)); } return parent.getElementsByTagName(name)[0]; } // remove node function rn(node) { if(typeof(node)=='string') node = fn(node); if(node) return node.parentNode.removeChild(node); } // CSS function SetStyle() { var i = 0, style = '', t; do { style += arguments[i++]; t = arguments[i++]; switch(typeof t) { case 'object': t = ConvertCSS(t); case 'string': style += '{' + t + '}\n'; } } while(i < arguments.length); return nn('STYLE', { TEXT: style }, document.head); } function ConvertCSS(def) { var names = Object.keys(def), style = '', name, value; for(name of names) { value = def[name]; if(typeof value == 'number' && name != 'zIndex') value += 'px'; style += name.replace(/([A-Z])/g, '-$1').toLowerCase().concat(': ', value, '; '); } return style.trimRight(); } // public domain by gnblizz // contact me with my username + '@web.de'