假油管的助手

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

  1. // ==UserScript==
  2. // @name Fake-Youtube Helper
  3. // @name:zh-CN 假油管的助手
  4. // @namespace https://greasyfork.org/users/159546
  5. // @version 1.3.4
  6. // @description Fix so much problem. Caution: This script is not for really Youtube.
  7. // @description:zh-CN 修复了油管的很多问题。注意:这个脚本不是给真的油管使用。
  8. // @author LEORChn
  9. // @include *:8700/*
  10. // @include *:10000/*
  11. // @include *//leorchn.github.io/yt/
  12. // @run-at document-start
  13. // @grant none
  14. // ==/UserScript==
  15. var vip,fun;
  16. (function(){
  17. recheck();
  18. })();
  19. function recheck(){ doEvents();
  20. switch(location.port){
  21. case'':if(document.readyState.toLowerCase()=='complete'){init();return;}else break;
  22. case'8700':
  23. var a=ft('a');
  24. for(var i=0,len=a.length;i<len;i++)
  25. if(gfun(a[i].href)=='testtube'){
  26. start();
  27. return;
  28. }
  29. break;
  30. default:
  31. if(document.title.includes(unescape('%u5927%u6cd5')))
  32. location.href='//'+location.hostname+':8700';return;
  33. }
  34. setTimeout(recheck,500);
  35. }
  36. function start(){
  37. initPlayServer();
  38. fun=gfun(location.href);
  39. switch(fun){
  40. case'watch':
  41. auto_expand();
  42. case'user':
  43. case'channel':
  44. fix_player();
  45. case'results':
  46. case'':
  47. fix_watch_page_link();
  48. fix_img();
  49. break;
  50. }
  51. addfeature();
  52. }
  53. function fix_watch_page_link(){
  54. var ip=vip.split('//')[1],hexip='';
  55. 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);
  56. for(var a=ft('a'),i=a.length-1;i>=0;i--)
  57. if(a[i] && a[i].href.indexOf(ip)>0)
  58. if(!funny_2_do(a[i]))
  59. a[i].href=a[i].href.replace(vip,'')+'&pid='+hexip;
  60. //for(var a=fc('blank'),i=a.length-1;i>=0;i--) a[i].remove();
  61. }
  62. function fix_img(){
  63. for(var a=ft('img'),i=0,len=a.length;i<len;i++){
  64. var tmp=a[i].getAttribute('data-thumb');
  65. if(tmp) a[i].src=tmp;
  66. }
  67. }
  68. function fix_player(){
  69. var a,vid;
  70. switch(fun){
  71. case'user':case'channel':a=fv('upsell-video');if(!a)return;vid=a.getAttribute('data-video-id');break;
  72. case'watch':a=fix_fullpage();vid=gvid(); fc('meh')[0].className=''; break;
  73. }
  74. vp=ct('video');
  75. a.appendChild(vp);
  76. vp.outerHTML='<video id="leorvp" src="'+vip+'/live?v='+vid+'" style="width:100%;height:100%" controls="controls" autoPlay>Failed</video>';
  77. a.className=a.className.replace('off-screen-target','');
  78. 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;}
  79. a=fv('player-unavailable'); a.className=a.className.replace('player-height','');
  80. vp=a=fv('leorvp');
  81. a.onclick=function(){if(a.paused)a.play();else a.pause();};
  82. }
  83. function fix_fullpage(){
  84. var w=fv('playerbox'),o=fv('theater-background'),l=absLeft(o),t=absTop(o);
  85. if(w)return o;
  86. w=ct('div');
  87. w.id='playerbox';
  88. w.className='player-width player-height';
  89. w.style.cssText='position:absolute;left:'+l+'px;top:'+t+'px;z-index:5222';
  90. ft('body')[0].appendChild(w);
  91. var limtip=fv('player-unavailable');
  92. limtip.style.color='#ffffff';limtip.style.backgroundColor='transparent';
  93. w.appendChild(limtip);
  94. return w;
  95. }
  96. function auto_expand(){
  97. var vdetail=fv('action-panel-details');
  98. vdetail.className=vdetail.className.replace('yt-uix-expander-collapsed','');
  99. }
  100. function initPlayServer(){
  101. for(var a=ft('a'),i=0,len=a.length,fstr=0;i<len;i++){
  102. fstr=a[i].href.indexOf('/watch?');
  103. if(fstr>0){
  104. vip=a[i].href.substring(0,fstr);
  105. return;
  106. }
  107. }
  108. gbakip();
  109. }
  110. function gbakip(){
  111. if(location.href.indexOf('pid=')==0)return;
  112. var ip=location.href.split('pid=')[1].split('&')[0].match(/[0-9a-fA-F]{2}/g);
  113. for(var i=0,len=4;i<4;i++) ip[i]=parseInt(ip[i],16);
  114. vip='http://'+ip.join('.')+':9999';
  115. }
  116. function gfun(url){return url.split('?')[0].split('/')[3];}
  117. function gvid(){return location.href.split('v=')[1].split('&')[0];}
  118. function fv(id){return document.getElementById(id);}
  119. function ft(tag){return document.getElementsByTagName(tag);}
  120. function fc(cname){return document.getElementsByClassName(cname);}
  121. function ct(tag,to){to=document.createElement(tag);return to;}
  122. function tip(s){console.log(s);}
  123. function doEvents(){console.log('doEvents');}
  124. function absTop(e,l){l=l?l:0;return e.offsetParent==null?l:absTop(e.offsetParent,l+e.offsetTop);}
  125. function absLeft(e,l){l=l?l:0;return e.offsetParent==null?l:absLeft(e.offsetParent,l+e.offsetLeft);}
  126. //----- -----
  127. var vp,ctl;
  128. function addfeature(){
  129. switch(fun){
  130. case'watch':
  131. initPlayerControl();
  132. }
  133. funny();
  134. }
  135. function initPlayerControl(){
  136. fv('placeholder-player').outerHTML+='<div id="vpctl" class="player-width"></div>';
  137. ctl=fv('vpctl');
  138. vpctl.onselectstart=function(){return false;};
  139. vpctl.style.cursor='default';
  140. vshareEntry(); loopEntry(); downloadEntry(); fullPageEntry(); playSpeedEntry();
  141. }
  142. function vshareEntry(){
  143. var n=ct('a');
  144. n.onclick=fc('action-panel-trigger-share')[0].onclick=function(){prompt('Press Ctrl+C','http://youtu.be/'+gvid());};
  145. n.innerText='share, ';
  146. ctl.appendChild(n);
  147. n=ct('a');
  148. n.onclick=function(){prompt('Press Ctrl+C','http://youtu.be/'+gvid()+'?t='+parseInt(vp.currentTime)+'s');};
  149. n.innerText='with timestamp';
  150. ctl.appendChild(n);
  151. }
  152. function loopEntry(){
  153. var n=ct('text');
  154. n.innerHTML='<input type="checkbox" id="looper" /><text id="loopertext">loop </text>';
  155. ctl.appendChild(n);
  156. fv('looper').onchange=loopStatOC;
  157. fv('loopertext').onclick=loopStat;
  158. }
  159. function loopStat(){ var e=fv('looper'); e.checked=!e.checked; loopStatOC(); }
  160. function loopStatOC(){ vp.loop=fv('looper').checked; }
  161. function downloadEntry(){
  162. var n=ct('text');
  163. n.innerHTML='<a id="vdlgo" target="_blank">Download</a><select id="vdltype" style="width:100px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">'+
  164. '<option>Video</option><option>Audio</option><option>Video (Live-Play Source)</option></select>';
  165. ctl.appendChild(n);
  166. download_seturl();
  167. n=fv('vdltype');
  168. n.onclick=download_seturl;
  169. }
  170. function download_seturl(){
  171. var dl=vip+'/download?v='+gvid()+'&type=',vdlgo=fv('vdlgo');
  172. switch(fv('vdltype').selectedIndex){
  173. case 0:vdlgo.href=dl+'video';break;
  174. case 1:vdlgo.href=dl+'audio';break;
  175. case 2:vdlgo.href=fv('leorvp').src;
  176. }
  177. }
  178. function playSpeedEntry(){
  179. var n=ct('text');
  180. n.innerHTML='Playback speed<select id="vpps"><option>0.5</option><option>0.8</option><option selected>1</option>'+
  181. '<option>1.2</option><option>1.3</option><option>1.5</option><option>2</option></select>';
  182. ctl.appendChild(n); n.style.cssText='float:right';
  183. fv('vpps').onclick=function(e){vp.playbackRate=parseFloat(e.target.options[e.target.selectedIndex].innerText);};
  184. }
  185. function fullPageEntry(){
  186. var n=ct('a');
  187. n.innerText='Fullpage';
  188. n.style.cssText='float:right;margin-left:5px';
  189. ctl.appendChild(n);
  190. vp.ondblclick=n.onclick=function(){
  191. var pb=fv('playerbox'),o=fix_fullpage(),l=absLeft(o),t=absTop(o);
  192. pb.style.cssText=pb.style.cssText?'':'position:absolute;left:'+l+'px;top:'+t+'px;z-index:5222';
  193. pb.className=pb.style.cssText?'player-width player-height':'fullpagescreen';
  194. //pb.offsetHeight=pb.offsetWidth*0.5625+'px';
  195. scrollTo(0,0);
  196. };
  197. n=ct('style');
  198. n.type='text/css';
  199. n.innerHTML='.fullpagescreen{background-color:#404040;position:absolute;width:100%;height:100%;top:0px;left:0px;z-index:5222}';
  200. fv('yt-masthead-container').style.background=fv('search-btn').style.background=fv('masthead-search-terms').style.background='transparent';
  201. fv('masthead-search-term').style.color='#888';
  202. var yinsiquantixing=fc('yt-consent-banner');
  203. if(yinsiquantixing[0])yinsiquantixing[0].style.background='transparent';
  204. ft('body')[0].appendChild(n);
  205. }
  206. var interest=0;
  207. function funny(){
  208. //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]);
  209. }
  210. function funny_1_do(b){b.innerText='';b.parentNode.remove();}
  211. function funny_2_do(a){
  212. var kwg=['%u8fd1%u5e73','%u6cfd%u6c11','%u6fa4%u6c11','%u6cd5%u8f6e','%u6cd5%u8f2a','%u5927%u6cd5','%u8feb%u5bb3'];
  213. for(var lv=0,llen=10,curnode=a;lv<llen;lv++)
  214. if(curnode.nodeName.toUpperCase()!="LI") curnode=curnode.parentNode;
  215. else for(var k in kwg)if(curnode.innerText.includes(unescape(kwg[k]))){
  216. tip(curnode);
  217. curnode.remove();interest++;if(interest>9)location.href='//tusenpo.github.io/FlappyFrog';//funny_3_do();
  218. return true;
  219. }
  220. return false;
  221. }
  222. function funny_3_do(){ ft('body')[0].outerHTML='<body style="background:#ffffff"><iframe style="width:88%;height:88%" src="http://map.google.cn"></iframe></body>'; }
  223. function funny_4_do(){ var n=ct('div'),b=ft('body');if(b.length==0)return;b[0].appendChild(n);n.outerHTML='<div class="blank" style="position:absolute;width:99%;height:999%;top:0px;background-color:#ffffff"></div>';}