video auto size (kissanime)

resize the video to pixel format size

  1. // ==UserScript==
  2. // @name video auto size (kissanime)
  3. // @description resize the video to pixel format size
  4. // @namespace gnblizz
  5. // @homepageURL https://greasyfork.org/en/scripts/25492-video-auto-size-kissanime
  6. // @include https://kissanime.ac/*
  7. // @include https://kissanime.ru/*
  8. // @exclude https://kissanime.ru/xyz/check.aspx
  9. // @include https://openload.co/embed/*
  10. // @include https://www.rapidvideo.com/*
  11. // @include https://streamango.com/embed/*
  12. // @version 1.07
  13. // @grant none
  14. // @compatible firefox
  15. // @compatible chrome
  16. // @run-at document-start
  17. // @icon data:image/gif;base64,R0lGODlhMAAwAKECAAAAAICAgP///////yH5BAEKAAMALAAAAAAwADAAAALQnI+py+0Po5y02ouz3rz7D4biBJTmiabqyrbuC8fyHAf2jedpzuOvAAwKh6mhUfg7Hks3gHLpehptwIBTioxig0zrdStIgrslMFA8pCKp1oAZjXW6w/Mt/Nl2t8HeFl7o5QZgBagEYyawNxhUl7h4dlelFlZG+QVY6aglmIjjuKd50xla9RKI0mSCqaPJSMM0aEK4mhfbpSnTabM4WXrShtpHI6gqKvmKnCwns0tm2lOsLP3aUy08aK0zvc3d7b09Ei4+Tl5ufo6err7O3n5QAAA7
  18. // ==/UserScript==
  19. "use strict";
  20.  
  21. var autodimmer = true;
  22.  
  23. var video, container, isTop = window.self==window.top, once;
  24.  
  25. function RunWhenVideoReady(cb) {
  26. if(!video) video = fn('VIDEO');
  27. if(video.readyState) cb(); else video.addEventListener('loadedmetadata', cb);
  28. video.addEventListener('ended', EndFullScreenMode, false);
  29. }
  30.  
  31. function SetResolution(event) { window.self.postMessage('videoformat' + this.textContent, 'http://kissanime.ru'); }
  32.  
  33. function showVideoSizeInfo() {
  34. rn(nn('DIV', { TEXT: video.videoWidth + 'x' + video.videoHeight, style:{ position: 'absolute', top: 1, left: 2, color: 'white', textShadow: '1px 1px black', fontSize: 'large', fontWeight: 'bold'}}, video.parentNode), 7);
  35. if(!isTop)
  36. window.top.postMessage('videoformat'.concat(video.videoWidth, 'x', video.videoHeight), 'https://kissanime.ru');
  37. if(autodimmer) {
  38. if(isTop) {
  39. var dim = fn('#allofthelights_bg1');
  40. if(!dim || dim.style.display != 'block')
  41. setTimeout(function() { fn('#switch').click() }, 100);
  42. } else video.addEventListener('ended', function(event) { window.top.postMessage('videoended', 'https://kissanime.ru'); }, false);
  43. }
  44. }
  45.  
  46. window.addEventListener('DOMContentLoaded', function(e) {
  47. video = fn('VIDEO');
  48. //console.info('Started VideoAutoSize at:', location.hostname);
  49. if(isTop) switch(location.hostname) {
  50. case 'kissanime.ru':
  51. if(location.pathname == '/Special/AreYouHuman2') {
  52. document.title = unescape(location.search).match(/\/[^?]+/)[0].replace(/\/Anime\//, '').replace(/\/|-/g, ' ');
  53. break;
  54. }
  55. if(video) {
  56. RunWhenVideoReady(setSizeNow);
  57. SetStyle('.vjs-playing.vjs-user-inactive{cursor:none}');
  58. } else {
  59. container = fn('?#divMyVideo>iframe');
  60. if(container) {
  61. window.addEventListener('message', receiveMessage, false);
  62. var div = nn('DIV#defaultvideosizes', 0, container.parentNode.parentNode.parentNode), resolutions = '1200x800/800x600/640x480'.split('/');
  63. while(resolutions.length) {
  64. nn('BUTTON', { type: 'button', TEXT: resolutions.shift() }, div).onclick = SetResolution;
  65. }
  66. SetStyle('iframe[id^=ads],#divFloatRight',{visibility:'hidden'}, '#adsIfrme button', {margin: '2px 10px', backgroundColor: '#393939', color: '#ccc', border: '1px solid #666666;'});
  67. } else {
  68. var h = setInterval(function() { //TODO: use observers
  69. video = fn('VIDEO');
  70. if(video) {
  71. clearInterval(h);
  72. RunWhenVideoReady(setSizeNow);
  73. }
  74. }, 500);
  75. }
  76. }
  77. break;
  78. case 'kissanime.ac': // .io
  79. setTimeout(function() {
  80. var myPlayer = videojs('player_html5' + (player_reload || ''));
  81. myPlayer.ready(function () {
  82. video = fn('VIDEO');
  83. RunWhenVideoReady(function(){
  84. var w = video.videoWidth, h = video.videoHeight, i = 'px!important';
  85. showVideoSizeInfo();
  86. SetStyle(
  87. 'video',{objectPosition:'center top'},
  88. 'div#container',{width:(w+40)+i},
  89. 'div#player_html5,div#player_container',{width:(w)+i,height:(h+30)+i},
  90. 'div#centerDivVideo',{maxWidth:'unset'},
  91. '.vjs-user-inactive',{cursor:'none'},
  92. '[style*="float"]{display:none!important;}').id = 'autosizestyle';
  93. video.scrollIntoView();
  94. i = fn('#AdtruePopupVideoClose');
  95. if(i) i.click();
  96. });
  97. });
  98. }, 3000);
  99. break;
  100. } else {
  101. switch(location.hostname) {
  102. case 'openload.co':
  103. RunWhenVideoReady(showVideoSizeInfo);
  104. setTimeout(function() { window.popAdsLoaded = 1; fn('#videooverlay').click(); }, 1000);
  105. setTimeout(function() { fn('.vjs-poster').click(); window.BetterJsPop.destroy(); }, 2000);
  106. break;
  107. case 'www.rapidvideo.com':
  108. setTimeout(function() {
  109. RunWhenVideoReady(showVideoSizeInfo);
  110. }, 3000);
  111. SetStyle('video', {objectFit: 'contain !important', backgroundColor: '#111111'}, '#spinner~*:not(style)', {display: 'none'});
  112. break;
  113. case 'streamango.com':
  114. RunWhenVideoReady(showVideoSizeInfo);
  115. SetStyle('.vjs-user-inactive.vjs-playing', {cursor: 'none'});
  116. break;
  117. }}
  118. });
  119.  
  120. function receiveMessage(event) {
  121. // console.log('VideoAutoSize received:', event.data);
  122. if(typeof event.data == 'string') switch(event.data.slice(0,11)) {
  123. case 'videoformat':
  124. var m = event.data.match(/(\d+)x(\d+)$/);
  125. video = { videoWidth: parseInt(m[1]), videoHeight: parseInt(m[2])};
  126. setSizeNow(event);
  127. if(event.source != window.self) rn('#defaultvideosizes');
  128. if(autodimmer) {
  129. var dim = fn('#allofthelights_bg1');
  130. if(!dim || dim.style.display != 'block') fn('#switch').click();
  131. }
  132. break;
  133. case 'videoended':
  134. if(autodimmer) {
  135. var dim = fn('#allofthelights_bg1');
  136. if(dim && dim.style.display == 'block') dim.click();
  137. }
  138. break;
  139. }
  140. }
  141.  
  142. function setSizeNow(event) {
  143. function parsePx(px){ if(/^\d+px$/.test(px)) return parseInt(px); }
  144. var obj, videoWidth = video.videoWidth, videoHeight = video.videoHeight;
  145. //
  146. console.log('VideoAutoSize video format:', [videoWidth,videoHeight].join('x'));
  147. if(container) video = container;
  148. else {
  149. showVideoSizeInfo(video);
  150. video.style.objectPosition = 'center top';
  151. }
  152. obj = video;
  153. var n, origWidth = parsePx(obj.style.width) || parsePx(obj.parentNode.style.width) || obj.clientWidth,
  154. origHeight = parsePx(obj.style.height) || parsePx(obj.parentNode.style.height) || obj.clientHeight;
  155. if(!origWidth) throw 'no width found!'; if(!origHeight) throw 'no height found!';
  156. var deltaWidth = videoWidth - origWidth, deltaHeight = videoHeight+30 - origHeight;
  157. do {
  158. n = parsePx(obj.style.width); if(n) obj.style.width = (n + deltaWidth)+ 'px';
  159. n = parsePx(obj.style.height); if(n) obj.style.height = (n + deltaHeight)+ 'px';
  160. obj = obj.parentNode;
  161. } while(obj.id != 'containerRoot' && obj.tagName != 'BODY');
  162. if(!once) {
  163. once = 1;
  164. obj = document.querySelectorAll('.divCloseBut>a');
  165. for(var i of obj) { i.click(); }
  166. if(!window.scrollY) video.scrollIntoView();
  167. }
  168. }
  169.  
  170. function FullScreenElement() {
  171. if(document.exitFullscreen) return document.fullscreenElement;
  172. if(document.mozCancelFullScreen) return document.mozFullScreenElement;
  173. if(document.webkitExitFullscreen) return document.webkitFullscreenElement;
  174. }
  175.  
  176. function EndFullScreenMode() {
  177. if(!FullScreenElement()) return false;
  178. (document.exitFullscreen||document.mozCancelFullScreen||document.webkitExitFullscreen).call(document);
  179. return true;
  180. }
  181.  
  182. // new node
  183. function nn(name, attributes, insertion) {
  184. var a = name.split('.'), i = a.shift().split('#'), node = document.createElement(i.shift());
  185. if(i[0]) node.id = i[0];
  186. if(a[0]) node.className = a.join(' ');
  187. if(attributes) {
  188. var names = Object.keys(attributes);
  189. for(name of names) {
  190. var value = attributes[name];
  191. switch(name) {
  192. case 'TEXT':
  193. node.textContent = value;
  194. break;
  195. case 'HTML':
  196. node.innerHTML = value;
  197. break;
  198. case 'style':
  199. if(typeof value == 'object')
  200. value = ConvertCSS(value);
  201. default:
  202. node.setAttribute(name, value);
  203. }
  204. }
  205. }
  206. if(insertion) {
  207. if(insertion.appendChild) insertion.appendChild(node);
  208. else {
  209. i = Object.keys(insertion)[0];
  210. if(i) {
  211. a = insertion[i];
  212. switch(i) {
  213. case 'append': a.appendChild(node); break;
  214. case 'insert': a.insertBefore(node, a.firstChild); break;
  215. case 'before': a.parentNode.insertBefore(node, a); break;
  216. case 'after': a.parentNode.insertBefore(node, a.nextSibling); break;
  217. }
  218. }}}
  219. return node;
  220. }
  221.  
  222. // find node
  223. function fn(name, parent) {
  224. if(!parent) parent = document;
  225. switch(name.charAt(0)) {
  226. case '#': return parent.getElementById(name.slice(1));
  227. case '.': return parent.getElementsByClassName(name.slice(1))[0];
  228. case '?': return parent.querySelector(name.slice(1));
  229. }
  230. return parent.getElementsByTagName(name)[0];
  231. }
  232.  
  233. // remove node
  234. function rn(node, delay, cb) {
  235. if(delay) {
  236. window.setTimeout(function() {
  237. if(!cb || !cb(node)) rn(node);
  238. }, 1000 * parseFloat(delay));
  239. return;
  240. }
  241. if(typeof(node)=='string') node = fn(node);
  242. if(node && node.parentNode) return node.parentNode.removeChild(node);
  243. }
  244.  
  245. // CSS
  246. function SetStyle() {
  247. var i = 0, style = '', t;
  248. do {
  249. style += arguments[i++];
  250. t = arguments[i++];
  251. switch(typeof t) {
  252. case 'object':
  253. t = ConvertCSS(t);
  254. case 'string':
  255. style += '{' + t + '}\n';
  256. }
  257. } while(i < arguments.length);
  258. return nn('STYLE', { TEXT: style }, document.head);
  259. }
  260.  
  261. function ConvertCSS(def) {
  262. var names = Object.keys(def), style = '', name, value;
  263. for(name of names) {
  264. value = def[name];
  265. if(typeof value == 'number' && name != 'zIndex') value += 'px';
  266. style += name.replace(/([A-Z])/g, '-$1').toLowerCase().concat(': ', value, '; ');
  267. }
  268. return style.trimRight();
  269. }
  270.  
  271. // public domain by gnblizz
  272. // contact me with my username + '@web.de'