假油管的助手【已停止更新】

修复了油管的很多问题。注意:这个脚本不是给真的油管使用。

当前为 2018-03-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Fake-Youtube Helper [Stopped update]
  3. // @name:zh-CN 假油管的助手【已停止更新】
  4. // @namespace https://greasyfork.org/users/159546
  5. // @version 1.3
  6. // @description Fix so much problem. Caution: This script is not for really Youtube.
  7. // @description:zh-CN 修复了油管的很多问题。注意:这个脚本不是给真的油管使用。
  8. // @author LEORChn
  9. // @match http*://youtu.be:8700/*
  10. // @run-at document-start
  11. // @grant none
  12. // ==/UserScript==
  13. var vip,fun;
  14. (function(){
  15. recheck();
  16. })();
  17. function recheck(){ doEvents();
  18. var a=ft('a');
  19. for(var i=0,len=a.length;i<len;i++)
  20. if(gfun(a[i].href)=='testtube'){
  21. start();
  22. return;
  23. }
  24. setTimeout(recheck,1000);
  25. }
  26. function start(){
  27. initPlayServer();
  28. fun=gfun(location.href);
  29. switch(fun){
  30. case'user':
  31. case'watch':
  32. fix_player();
  33. case'results':
  34. case'channel':
  35. case'':
  36. fix_watch_page_link();
  37. fix_img();
  38. break;
  39. }
  40. addfeature();
  41. }
  42. function fix_watch_page_link(){
  43. var ip=vip.split('//')[1],hexip='';
  44. for(var i=0,len=4,h=ip.split(':')[0].split('.');i<len;i++) hexip+=(h[i]>15?'':'0')+parseInt(h[i],10).toString(16);
  45. for(var a=ft('a'),i=0,len=a.length;i<len;i++)
  46. if(a[i].href.indexOf(ip)>0)
  47. a[i].href=a[i].href.replace(vip,'')+'&pid='+hexip;
  48. }
  49. function fix_img(){
  50. for(var a=ft('img'),i=0,len=a.length;i<len;i++){
  51. var tmp=a[i].getAttribute('data-thumb');
  52. if(tmp) a[i].src=tmp;
  53. }
  54. }
  55. function fix_player(){
  56. var a,vid;
  57. switch(fun){
  58. case'user':a=fv('upsell-video');if(a==null)return;vid=a.getAttribute('data-video-id');break;
  59. case'watch':a=fix_fullpage();vid=gvid();break;
  60. }
  61. vp=ct('video');
  62. a.appendChild(vp);
  63. vp.outerHTML='<video id="leorvp" src="'+vip+'/live?v='+vid+'" style="width:100%;height:100%" controls="controls" autoPlay>Failed</video>';
  64. a.className=a.className.replace('off-screen-target','');
  65. for(var i=0,b=ft('button'),len=b.length;i<len;i++) if(b[i].parentElement.id=='watch7-player-age-gate-content'){b[i].remove();break;}
  66. fc('meh')[0].className='';
  67. a=fv('player-unavailable'); a.className=a.className.replace('player-height','');
  68. vp=a=fv('leorvp');
  69. a.onclick=function(){if(a.paused)a.play();else a.pause();};
  70. }
  71. function fix_fullpage(){
  72. var w=fv('playerbox'),o=fv('placeholder-player'),l=absLeft(o),t=absTop(o)-100;
  73. if(w)return o;
  74. w=ct('div');
  75. w.id='playerbox';
  76. w.className='player-width player-height';
  77. w.style.cssText='position:absolute;left:'+l+'px;top:'+t+'px;z-index:5222';
  78. ft('body')[0].appendChild(w);
  79. var limtip=fv('player-unavailable');
  80. limtip.style.color='#ffffff';limtip.style.backgroundColor='transparent';
  81. w.appendChild(limtip);
  82. return w;
  83. }
  84. function initPlayServer(){
  85. for(var a=ft('a'),i=0,len=a.length,fstr=0;i<len;i++){
  86. fstr=a[i].href.indexOf('/watch?');
  87. if(fstr>0){
  88. vip=a[i].href.substring(0,fstr);
  89. return;
  90. }
  91. }
  92. gbakip();
  93. }
  94. function gbakip(){
  95. if(location.href.indexOf('pid=')==0)return;
  96. var ip=location.href.split('pid=')[1].split('&')[0].match(/[0-9a-fA-F]{2}/g);
  97. for(var i=0,len=4;i<4;i++) ip[i]=parseInt(ip[i],16);
  98. vip='http://'+ip.join('.')+':9999';
  99. }
  100. function gfun(url){return url.split('?')[0].split('/')[3];}
  101. function gvid(){return location.href.split('v=')[1].split('&')[0];}
  102. function fv(id){return document.getElementById(id);}
  103. function ft(tag){return document.getElementsByTagName(tag);}
  104. function fc(cname){return document.getElementsByClassName(cname);}
  105. function ct(tag,to){to=document.createElement(tag);return to;}
  106. function tip(s){console.log(s);}
  107. function doEvents(){console.log('doEvents');}
  108. function absTop(e){var l=0;while(e){l+=e.offsetTop;e=e.parentElement;}return l;}
  109. function absLeft(e){var l=0;while(e){l+=e.offsetLeft;e=e.parentElement;}return l;}
  110. //----- -----
  111. var vp,ctl;
  112. function addfeature(){
  113. switch(fun){
  114. case'watch':
  115. initPlayerControl();
  116. }
  117. funny();
  118. }
  119. function initPlayerControl(){
  120. fv('placeholder-player').outerHTML+='<div id="vpctl" class="player-width"></div>';
  121. ctl=fv('vpctl');
  122. vpctl.onselectstart=function(){return false;};
  123. vpctl.style.cursor='default';
  124. vshareEntry(); loopEntry(); downloadEntry(); fullPageEntry(); playSpeedEntry();
  125. }
  126. function vshareEntry(){
  127. var n=ct('a');
  128. n.onclick=function(){prompt('Press Ctrl+C','http://youtu.be/'+gvid());};
  129. n.innerText='share, ';
  130. ctl.appendChild(n);
  131. n=ct('a');
  132. n.onclick=function(){prompt('Press Ctrl+C','http://youtu.be/'+gvid()+'?t='+parseInt(vp.currentTime)+'s');};
  133. n.innerText='with timestamp';
  134. ctl.appendChild(n);
  135. }
  136. function loopEntry(){
  137. var n=ct('text');
  138. n.innerHTML='<input type="checkbox" id="looper" /><text id="loopertext">loop </text>';
  139. ctl.appendChild(n);
  140. fv('looper').onchange=loopStatOC;
  141. fv('loopertext').onclick=loopStat;
  142. }
  143. function loopStat(){ var e=fv('looper'); e.checked=!e.checked; loopStatOC(); }
  144. function loopStatOC(){ vp.loop=fv('looper').checked; }
  145. function downloadEntry(){
  146. var n=ct('text');
  147. n.innerHTML='<a id="vdlgo" target="_blank">Download</a><select id="vdltype" style="width:100px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">'+
  148. '<option>Video</option><option>Audio</option><option>Video (Live-Play Source)</option></select>';
  149. ctl.appendChild(n);
  150. download_seturl();
  151. n=fv('vdltype');
  152. n.onclick=download_seturl;
  153. }
  154. function download_seturl(){
  155. var dl=vip+'/download?v='+gvid()+'&type=',vdlgo=fv('vdlgo');
  156. switch(fv('vdltype').selectedIndex){
  157. case 0:vdlgo.href=dl+'video';break;
  158. case 1:vdlgo.href=dl+'audio';break;
  159. case 2:vdlgo.href=fv('leorvp').src;
  160. }
  161. }
  162. function playSpeedEntry(){
  163. var n=ct('text');
  164. n.innerHTML='Playback speed<select id="vpps"><option>0.5</option><option>0.8</option><option selected>1</option>'+
  165. '<option>1.2</option><option>1.3</option><option>1.5</option><option>2</option></select>';
  166. ctl.appendChild(n); n.style.cssText='float:right';
  167. fv('vpps').onclick=function(e){vp.playbackRate=parseFloat(e.target.options[e.target.selectedIndex].innerText);};
  168. }
  169. function fullPageEntry(){
  170. var n=ct('a');
  171. n.innerText='Fullpage';
  172. n.style.cssText='float:right;margin-left:5px';
  173. ctl.appendChild(n);
  174. n.onclick=function(){
  175. var pb=fv('playerbox'),o=fix_fullpage(),l=absLeft(o),t=absTop(o)-100;
  176. pb.style.cssText=pb.style.cssText?'':'position:absolute;left:'+l+'px;top:'+t+'px;z-index:5222';
  177. pb.className=pb.style.cssText?'player-width player-height':'fullpagescreen';
  178. };
  179. vp.ondblclick=n.onclick;
  180. n=ct('style');
  181. n.type='text/css';
  182. n.innerHTML='.fullpagescreen{background-color:#404040;position:absolute;width:100%;height:100%;top:0px;left:0px;z-index:5222}';
  183. //alert(n.outerHTML);
  184. ft('body')[0].appendChild(n);
  185. }
  186. function funny(){
  187. //for(var i=0,b=fc('yt-uix-button-content'),len=b.length;i<len;i++) if(b[i]&&!b[i].parentNode.href&&isNaN(b[i].innerText)) funny_1_do(b[i]);
  188. }
  189. function funny_1_do(b){b.innerText='';b.parentNode.remove();}