u-Youtube

make Youtube under ur control

当前为 2022-04-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name u-Youtube
  3. // @name:zh-CN 功夫制霸YouTube
  4. // @name:zh-TW 功夫製霸YouTube
  5. // @name:en u-Youtube
  6. // @name:ua u-Youtube
  7. // @name:ja カンフー支配YouTube
  8. // @name:ko 쿵푸 지배YouTube
  9. // @name:it u-Youtube
  10. // @name:de u-Youtube
  11. // @name:fr u-Youtube
  12. // @namespace https://github.com/rasso1/u-Youtube
  13. // @version 1.31
  14. // @description make Youtube under ur control
  15. // @description:zh-TW make Youtube under ur control
  16. // @description:en make Youtube under ur control
  17. // @description:ja あなたのコントロール下でYouTubeを作る
  18. // @description:ko 유튜브를 당신의 통제하에 두십시오
  19. // @description:it rendi youtube sotto il tuo controllo
  20. // @description:de Machen Sie YouTube unter Ihrer Kontrolle
  21. // @description:fr faire de youtube sous votre contrôle
  22. // @author ok!
  23. // @match https://www.youtube.com/*
  24. // @match https://youtube.com/*
  25. // @run-at document-start
  26. // @contributionURL https://paypal.me/kongfuY
  27.  
  28. // ==/UserScript==
  29. (function() {
  30. 'use strict';
  31. var expand_description = 1;var subscription_up = 1;
  32. var sec_sub,sec_fwd,wheel_sec,buffer_time,dark_mode,video_speed,video_quality,english_mode,comment_right,temp_buffer,temp_speed,speed_display,current_time,doc_s,icare_mode;
  33. var inner_hight=window.innerHeight-80;
  34. var inner_width=window.innerWidth*0.37;
  35. //var inner_hight=500;
  36.  
  37. var youtube_hand = {
  38. message_box: {
  39. show: function(message) {
  40. document.querySelector("#container > #movie_player .ytp-bezel-text").innerHTML = message;
  41. document.querySelector("#container > #movie_player .ytp-bezel-text").parentNode.parentNode.style.display = "";
  42. document.querySelector("#container > #movie_player .ytp-bezel-text").parentNode.parentNode.classList.remove("ytp-bezel-text-hide");
  43. setTimeout(youtube_hand.message_box.hide, 1500);
  44. },
  45. hide: function() {
  46. document.querySelector("#container > #movie_player .ytp-bezel-text").innerText = "";
  47. document.querySelector("#container > #movie_player .ytp-bezel-text").parentNode.parentNode.style.display = "none";
  48. }
  49. },
  50. dark_eye:function (){
  51. if(localStorage.getItem('icare_mode')==1){
  52. document.querySelector("html").style="font-size:13px;font-family: Roboto, Arial, sans-serif;"
  53. }
  54. else {document.querySelector("html").style="font-size:10px;font-family: Roboto, Arial, sans-serif;"}
  55.  
  56. if(localStorage.getItem('dark_mode')==1){
  57. if(!document.querySelector("html").hasAttribute("dark")){
  58. document.querySelector("html").setAttribute("dark",true);}
  59. }
  60. else if(document.querySelector("html").hasAttribute("dark"))
  61. {document.querySelector("html").removeAttribute("dark")}
  62. if(localStorage.getItem("comment_right")==1&&document.querySelector("#columns #primary #primary-inner #sections")&&document.querySelector("#secondary #secondary-inner")){
  63. //评论右上移
  64. document.querySelector("#columns #primary #primary-inner #sections").style="width:"+inner_width+"px;height:"+inner_hight+"px;overflow-y:auto";
  65. document.querySelector("#columns #primary #primary-inner #sections").classList.add('standardized-themed-scrollbar');
  66. // document.querySelector("#columns #primary #primary-inner #sections")
  67. document.querySelector("#secondary #secondary-inner").append(document.querySelector("#columns #primary #primary-inner #sections"));
  68. document.querySelector("#page-manager #columns > #secondary > #secondary-inner > #sections").onscroll=function(){
  69. document.querySelector("body").style.overflow="hidden";
  70. }
  71. document.querySelector("#page-manager #columns > #secondary > #secondary-inner > #sections").onpointerleave=function(){
  72. document.querySelector("body").style.overflow="";
  73. }
  74. /*
  75. document.querySelector("#page-manager #columns > #secondary > #secondary-inner > #sections").onscroll=function(){
  76. let comment_height= parseInt(document.querySelector("#page-manager #columns > #secondary > #secondary-inner > #sections").style.height);
  77. comment_height+=1;
  78. document.querySelector("#page-manager #columns > #secondary > #secondary-inner > #sections").style.height = comment_height+"px";
  79. document.querySelector("#page-manager #columns > #secondary > #secondary-inner > #sections").style.float="right";
  80. };
  81. */
  82. //related 左下移
  83. document.querySelector("#columns #primary #primary-inner").append(document.querySelector("#secondary #secondary-inner #related"));
  84.  
  85. }
  86. },
  87. dark_eye1:function (){
  88. if(localStorage.getItem('dark_mode')==1){
  89. var style_type = document.createElement("style");style_type.id = "style_type";
  90. style_type.innerHTML = `#end > div.dropdown-hover > div{font-size:12px;color:#bbb !important;background-color:#202020 !important;}
  91. #end > div.dropdown-hover > button{background-color:#222 !important;} #end > div.dropdown-hover path{fill:transparent !important;stroke:white !important;}
  92. #end > div.dropdown-hover > div > div{color:#aaa !important;background-color:#202020 !important;}
  93. #end > div.dropdown-hover > div > div p{font-size:12px;color:#bbb !important;background-color:#202020 !important;}
  94. .dropdown-hover button div{font-size:12px;color:#aaa !important;background-color:#333 !important;}
  95. #sec_sub,#sec_fwd,#wheel_sec,#buffer_time{font-size:12px;color:#bbb !important;background-color:#333 !important;border-radius:5px;}`;
  96. document.head.appendChild(style_type);
  97. }
  98. },
  99.  
  100. //播放设置
  101. play_menu:function(){
  102.  
  103.  
  104. var html_app = document.createElement("div");
  105. html_app.innerHTML = `
  106. <button style="border:none;outline:none;background-color:#fff;height:37px;width:37px;margin-right:10px;" aria-label="缓存/速度设置"><svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;"><g class="style-scope yt-icon">
  107. <path d="M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.1-1.65c.2-.15.25-.42.13-.64l-2-3.46c-.12-.22-.4-.3-.6-.22l-2.5 1c-.52-.4-1.08-.73-1.7-.98l-.37-2.65c-.06-.24-.27-.42-.5-.42h-4c-.27 0-.48.18-.5.42l-.4 2.65c-.6.25-1.17.6-1.7.98l-2.48-1c-.23-.1-.5 0-.6.22l-2 3.46c-.14.22-.08.5.1.64l2.12 1.65c-.04.32-.07.65-.07.98s.02.66.06.98l-2.1 1.65c-.2.15-.25.42-.13.64l2 3.46c.12.22.4.3.6.22l2.5-1c.52.4 1.08.73 1.7.98l.37 2.65c.04.24.25.42.5.42h4c.25 0 .46-.18.5-.42l.37-2.65c.6-.25 1.17-.6 1.7-.98l2.48 1c.23.1.5 0 .6-.22l2-3.46c.13-.22.08-.5-.1-.64l-2.12-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z" fill="transparent" stroke="black"></path>
  108. </g></svg>
  109. </button>
  110.  
  111. <div style="background:#fff;border-radius: 10px;left: -160px;right: 0;margin-left: 0;margin-right: -100px;padding-top: 10px;" class="dropdown-box fadeInDown"><div class="item clearfix" style="border-radius:10px;"><p style="margin:10px auto;font-size:18px;"><span class="mandarin invisible">播放设置&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="english">Playback Setting&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><font size=2>Chs </font><input style="margin:auto" id="english_mode" class="switch switch-anim" type="checkbox" checked></p>
  112. <div style="margin:10px auto;font-size:12px;"><hr /><hr /></div>
  113. <p style="margin:10px auto;font-size:16px;"><span class="mandarin invisible" style="margin:10px auto;font-size:16px;">当前速度:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="english">current speed:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="speed_display"></span></p>
  114. <p style="margin:10px auto;font-size:16px;"><span class="mandarin invisible">选择播放速度:&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="english">specify spee<font color=#5bb7fe>d</font>:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><button id="speed_button" style="background-color: #5bb7fe;border-radius:5px;color:white;font-size:12px;"> &nbsp; 1x&nbsp; </button></p><input type="range" min="0" max="100" value="25" class="slider" id="speed_slider"><br /><br />
  115. <p style="margin:10px auto;font-size:16px;"><span class="mandarin invisible">跳过片头秒数:&nbsp;&nbsp;&nbsp;</span><span class="english">skip the title:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><input type="text" id="sec_fwd" style="width:40px;height:12px;vertical-align: middle;padding: 5px;background-color:#fff;border: 2px solid #ddd;border-radius:5px;font-size:12px;" placeholder="seconds">
  116. <p style="margin:10px auto;font-size:16px;"><span class="mandarin invisible">跳过片尾秒数:&nbsp;&nbsp;&nbsp;</span><span class="english">skip the end:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><input type="text" id="sec_sub" style="width:40px;height:12px;vertical-align: middle;padding: 5px;background-color: #fff;border: 2px solid #ddd;border-radius:5px;font-size:12px;" placeholder="seconds"></p>
  117. <p style="margin:10px auto;font-size:16px;"><span class="mandarin invisible">鼠标滚动秒数:&nbsp;&nbsp;&nbsp;</span><span class="english">mouse scroll:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><input type="text" id="wheel_sec" style="width:40px;height:12px;vertical-align: middle;padding: 5px;background-color: #fff;border: 2px solid #ddd;border-radius:5px;font-size:12px;" placeholder="seconds"></p>
  118. <p style="margin:10px auto;font-size:16px;"><span class="mandarin invisible">暂停缓存秒数:&nbsp;&nbsp;&nbsp;</span><span class="english">paus<font color=#5bb7fe>e</font> n cashing:&nbsp;&nbsp;&nbsp;&nbsp;</span><input type="text" id="buffer_time" style="width:40px;height:12px;vertical-align: middle;padding: 5px;background-color: #fff;border: 2px solid #ddd;border-radius:5px;font-size:12px;" placeholder="seconds"></p>
  119. <p style="margin:10px auto;font-size:16px;"><span class="mandarin invisible">播放质量:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span class="english">specify resolution&nbsp;</span> <select id="video_quality" style="border-radius:5px;"><option value="auto">auto</option><option value="hd2160">4K 2160p</option><option value="hd1440">HD 1440p</option><option value="hd1080">HD 1080p</option><option value="hd720">720p</option> <option value="large">480p</option><option value="medium">360p</option><option value="small">240p</option><option value="tiny">144p</option> </select></p>
  120. <p style="margin:10px auto 20px auto;font-size:16px;"><span class="mandarin invisible">评论载右:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="english">comments to right:&nbsp;&nbsp;&nbsp;</span><input style="margin:auto" id="comment_to" class="switch switch-anim" type="checkbox" checked></p>
  121. <p style="margin:10px auto 20px auto;font-size:16px;"><span class="mandarin invisible">眼保模式 :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="english">iCare mode:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><input style="margin:auto" id="icare_mode" class="switch switch-anim" type="checkbox" checked></p>
  122. <p style="margin:10px auto 20px auto;font-size:16px;"><span class="mandarin invisible">暗夜模式 :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="english">dark mode:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><input style="margin:auto" id="dark_mode" class="switch switch-anim" type="checkbox" checked></p>
  123. <p style="margin:10px auto 20px auto;font-size:16px;"><span class="mandarin invisible">捐赠&#126980;:&nbsp; </span><span class="english">donate&#127854;:&nbsp;&nbsp;</span><a href="https://paypal.me/kongfuY" style="color:#5bb7fe;">paypal.me/kongfuY</a></p></div></div>
  124.  
  125. <style>#speed_slider {width: 175px;}.invisible {display: none;}.ytd-feed-filter-chip-bar-renderer.style-scope{z-index:999 !important;}.fadeInDown{-webkit-animation:fadeInDown .5s .2s ease both;-moz-animation:fadeInDown .5s .2s ease both}@-webkit-keyframes fadeInDown{0%{opacity:0;-webkit-transform:translateY(-10px)}100%{opacity:1;-webkit-transform:translateY(0)}}@-moz-keyframes fadeInDown{0%{opacity:0;-moz-transform:translateY(-10px)}100%{opacity:1;-moz-transform:translateY(0)}}.dropdown{position:relative}.dropdown-box{display:none;position:absolute;z-index:999999999}.dropdown-box.top{bottom:100%;padding-bottom:10px;left:50%;margin-left:-80px}.dropdown-box.bottom{top:100%;padding-top:10px;left:50%;margin-left:-80px}.dropdown-box.left{left:100%;padding-left:10px;bottom:0}.dropdown-box.right{right:100%;padding-right:10px;bottom:0}.dropdown-box .item{padding:10px;width:250px;border-radius:2px}.dropdown-hover{position:relative}.dropdown-hover:hover .dropdown-box{display:block}</style>
  126. <style>a {color: #670000;}.switch {width: 26px;height: 13px;position: relative;border: 1px solid #dfdfdf;background-color: #fdfdfd;box-shadow: #dfdfdf 0 0 0 0 inset; border-radius: 18px;background-clip: content-box;display: inline-block;-webkit-appearance: none;user-select: none;outline: none;} .switch:before { content: '';width: 13px;height: 13px;position: absolute;top: 0;left: 0;border-radius: 12px;background-color: #fff;box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);}.switch:checked {border-color: #5bb7fe;box-shadow: #5bb7fe 0 0 0 16px inset;background-color: #5bb7fe;}.switch:checked:before {left: 15px;}.switch.switch-anim {transition: border cubic-bezier(0, 0, 0, 1) 0.4s, box-shadow cubic-bezier(0, 0, 0, 1) 0.4s;}.switch.switch-anim:before {transition: left 0.3s;}.switch.switch-anim:checked {box-shadow: #5bb7fe 0 0 0 14px inset;background-color: #5bb7fe;transition: border ease 0.4s, box-shadow ease 0.4s, background-color ease 1.2s;}.switch.switch-anim:checked:before {transition: left 0.3s;}.text-red {color: #aaa;}</style>
  127. <style>.standardized-themed-scrollbar::-webkit-scrollbar {
  128. width: 1em;
  129. }
  130. .standardized-themed-scrollbar::-webkit-scrollbar-track {
  131. -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
  132. }
  133. .standardized-themed-scrollbar::-webkit-scrollbar-thumb {
  134. background-color: darkgrey;
  135. height: 56px;border-radius: 10px;border: 4px solid transparent;background-clip: content-box;
  136. }</style>
  137. `;
  138. html_app.classList.add('dropdown-hover');
  139. document.querySelector("#end").appendChild(html_app);
  140.  
  141. //
  142. var speed_slider=document.getElementById("speed_slider"),speed_button=document.getElementById("speed_button"),
  143. y=document.getElementById("sec_sub"),z=document.getElementById("wheel_sec"),x=document.getElementById("buffer_time"),w=document.getElementById("dark_mode"),
  144. s=document.getElementById("video_quality"),v=document.getElementById("sec_fwd"),t=document.getElementById("english_mode"),c=document.getElementById("comment_to"),iii=document.getElementById("icare_mode");
  145. dark_mode = localStorage.getItem('dark_mode');comment_right = localStorage.getItem('comment_right');icare_mode = localStorage.getItem('icare_mode');
  146. var english_mode = localStorage.getItem('english_mode');
  147. speed_display=document.getElementById("speed_display");
  148. const mandarins = document.querySelectorAll('.mandarin');const englishs = document.querySelectorAll('.english');
  149.  
  150.  
  151. video_speed = localStorage.getItem('speed');sec_fwd = localStorage.getItem('sec_fwd');sec_sub = localStorage.getItem('sec_sub');
  152. wheel_sec = localStorage.getItem('wheel_sec');buffer_time = localStorage.getItem('buffer_time');
  153. video_quality = localStorage.getItem('video_quality')?localStorage.getItem('video_quality'):"auto";
  154.  
  155. english_mode = localStorage.getItem('english_mode');
  156. //判读英文菜单
  157. if(localStorage.getItem('english_mode')==1){
  158. for (const mandarin of mandarins) {
  159. mandarin.className -= ' invisible';
  160. }
  161. for (const english of englishs) {
  162. english.className += ' invisible';
  163. }
  164. }
  165.  
  166. video_speed?speed_display.innerHTML=video_speed+"x":speed_display.innerHTML="1x";
  167.  
  168. setTimeout(function (){
  169. if(video_speed&&document.querySelector('#movie_player'))
  170. document.querySelector("#movie_player > div.html5-video-container > video").playbackRate = video_speed;},4000);
  171.  
  172. speed_slider.value = localStorage.getItem('speed')*25;
  173.  
  174. speed_slider.oninput=function(){localStorage.setItem('speed',this.value/25);video_speed = localStorage.getItem('speed');video_speed?speed_display.innerHTML=video_speed+"x":speed_display.innerHTML="1x";
  175. document.querySelector("#movie_player > div.html5-video-container > video").playbackRate = video_speed;
  176. }
  177.  
  178. speed_button.onclick=function(){localStorage.setItem('speed',1);video_speed = localStorage.getItem('speed');video_speed?speed_display.innerHTML=video_speed+"x":speed_display.innerHTML="1x";
  179. document.querySelector("#movie_player > div.html5-video-container > video").playbackRate = video_speed;
  180. speed_slider.value = localStorage.getItem('speed')*25;
  181. }
  182.  
  183. sec_fwd?v.value=sec_fwd:v.value="";
  184. v.onchange=function(){localStorage.setItem('sec_fwd',this.value);sec_fwd = localStorage.getItem('sec_fwd');sec_fwd?v.value=sec_fwd:v.value="";
  185. }
  186. sec_sub?y.value=sec_sub:y.value="";
  187. y.onchange=function(){localStorage.setItem('sec_sub',this.value);sec_sub = localStorage.getItem('sec_sub');sec_sub?y.value=sec_sub:y.value="";
  188. }
  189.  
  190. wheel_sec?z.value=wheel_sec:z.value="";
  191. z.onchange=function(){localStorage.setItem('wheel_sec',this.value);wheel_sec = localStorage.getItem('wheel_sec');wheel_sec?z.value=wheel_sec:z.value="";
  192. }
  193. buffer_time?x.value=buffer_time:x.value="";
  194. x.onchange=function(){localStorage.setItem('buffer_time',this.value);buffer_time = localStorage.getItem('buffer_time');buffer_time?x.value=buffer_time:x.value="";
  195. }
  196. c.checded=comment_right; if(comment_right!=1){document.getElementById("comment_to").removeAttribute('checked');}
  197. c.onchange=function(){if(c.checked){localStorage.setItem('comment_right','1');youtube_hand.dark_eye();}
  198. else{localStorage.setItem('comment_right',0);
  199. //评论右上移
  200.  
  201. document.querySelector("#columns #primary #primary-inner").append(document.querySelector("#secondary #secondary-inner #sections"));
  202. //related 左下移
  203. document.querySelector("#secondary #secondary-inner").prepend(document.querySelector("#related"));
  204.  
  205. }
  206. comment_right = localStorage.getItem('comment_right');
  207. }
  208.  
  209. iii.checded=icare_mode; if(icare_mode!=1){document.getElementById("icare_mode").removeAttribute('checked');}
  210. iii.onchange=function(){if(iii.checked){localStorage.setItem('icare_mode','1');}
  211. else{localStorage.setItem('icare_mode',0);
  212. }
  213. icare_mode = localStorage.getItem('icare_mode');
  214. }
  215.  
  216. w.checded=dark_mode; if(dark_mode!=1){document.getElementById("dark_mode").removeAttribute('checked');}
  217. w.onchange=function(){if(w.checked){localStorage.setItem('dark_mode','1');youtube_hand.dark_eye();youtube_hand.dark_eye1();}
  218. else{localStorage.setItem('dark_mode',0);
  219. document.querySelector("html").removeAttribute("dark");
  220. document.querySelector('#style_type').remove();
  221. }
  222. dark_mode = localStorage.getItem('dark_mode');
  223. }
  224. t.checded=english_mode; if(english_mode!=1){document.getElementById("english_mode").removeAttribute('checked');}
  225. t.onchange=function(){if(t.checked){localStorage.setItem('english_mode','1');
  226. for (const mandarin of mandarins) {
  227. mandarin.className -= ' invisible';}
  228. for (const english of englishs) {
  229. english.className += ' invisible';}
  230. }
  231. else{localStorage.setItem('english_mode',0);
  232. for (const mandarin of mandarins) {
  233. mandarin.className += ' invisible';}
  234. for (const english of englishs) {
  235. english.className -= ' invisible';}
  236. }
  237. english_mode = localStorage.getItem('english_mode');
  238. }
  239.  
  240. if(video_quality){
  241. for(var i=0;i<s.length;i++){
  242. if(s.options[i].value==video_quality){
  243. s.options[i].selected=true;
  244. }
  245. }
  246. }
  247. s.onchange=function (){
  248. var quality_value = s[s.selectedIndex].getAttribute("value");
  249. localStorage.setItem('video_quality',quality_value);
  250. video_quality = localStorage.getItem('video_quality');
  251. var avail_quali;var v_elem = document.querySelector("#movie_player");
  252. if((avail_quali = v_elem.getAvailableQualityLevels())&&avail_quali.indexOf(video_quality) == -1){
  253. v_elem.setPlaybackQualityRange(avail_quali[0],avail_quali[0]);
  254. }
  255. else{v_elem.setPlaybackQualityRange(video_quality,video_quality);}
  256. }
  257.  
  258. },
  259.  
  260. play_main:function (){
  261.  
  262. sec_fwd = localStorage.getItem('sec_fwd');
  263. sec_sub = localStorage.getItem('sec_sub');
  264. wheel_sec = localStorage.getItem('wheel_sec');
  265. buffer_time = localStorage.getItem('buffer_time');
  266.  
  267. var video_speed = localStorage.getItem('speed');
  268.  
  269. var video_elem,v_elem;
  270.  
  271.  
  272. //每3秒试执行主应用操作
  273. var main_timer = setInterval(function () {
  274. video_elem = document.querySelector("#movie_player > div.html5-video-container > video");
  275. v_elem = document.querySelector("#movie_player");
  276.  
  277. if (video_elem){
  278. //main_opr();
  279.  
  280. video_elem.onloadeddata = function (){
  281.  
  282. main_opr();
  283. if(buffer_time){
  284. youtube_hand.message_box.show("<div>video speed "+video_speed+"x</div><div>cashe "+buffer_time+" seconds</div><div>"+document.querySelector("#info-text > #info-strings > yt-formatted-string").innerText+"</div>");
  285. }
  286. else {youtube_hand.message_box.show("<div>video speed "+video_speed+"x</div><div>no cashe</div><div>"+document.querySelector("#info-text > #info-strings > yt-formatted-string").innerText+"</div>");
  287. }
  288. setTimeout(function(){video_elem.onloadeddata = "";},2000)
  289.  
  290. }
  291. /* document.addEventListener("yt-navigate-finish", function() {
  292. video_elem.currentTime=0;
  293. current_time=0;
  294. main_opr();
  295. }) */
  296.  
  297. video_elem.ondurationchange = function(){
  298. video_elem.currentTime=0;
  299. current_time=0;
  300. video_speed = localStorage.getItem('speed');
  301. if(buffer_time){
  302. youtube_hand.message_box.show("<div>video speed "+video_speed+"x</div><div>cashe "+buffer_time+" seconds</div><div>"+document.querySelector("#info-text > #info-strings > yt-formatted-string").innerText+"</div>");
  303. }
  304. else {youtube_hand.message_box.show("<div>video speed "+video_speed+"x</div><div>no cashe</div><div>"+document.querySelector("#info-text > #info-strings > yt-formatted-string").innerText+"</div>");
  305. }
  306. main_opr();
  307. }
  308.  
  309. clearInterval(main_timer);}
  310. },100)
  311.  
  312. //主应用操作
  313. function main_opr() {
  314. doc_s = window.document;
  315. //视频质量选择
  316.  
  317. var avail_quali;var current_time;
  318. if((avail_quali = v_elem.getAvailableQualityLevels())&&avail_quali.indexOf(video_quality) == -1){
  319. v_elem.setPlaybackQualityRange(avail_quali[0],avail_quali[0]);
  320. }
  321. else if(video_quality=="auto"){}
  322. else if(video_quality){v_elem.setPlaybackQualityRange(video_quality,video_quality);}
  323. //点开视频介绍
  324. if(expand_description){
  325.  
  326. if(document.getElementById("action-panel-details")) {
  327. document.getElementById("action-panel-details").classList.remove("yt-uix-expander-collapsed");
  328. }
  329.  
  330. if(document.querySelector("#more > .more-button.style-scope.ytd-video-secondary-info-renderer")) {
  331. document.querySelector("#more > .more-button.style-scope.ytd-video-secondary-info-renderer").click();
  332. }
  333. }
  334.  
  335. //前跳过秒数+速度+播放质量设定
  336. video_elem.oncanplay = function(){
  337. if(video_speed&&video_elem){
  338. video_elem.playbackRate = video_speed;
  339. }
  340. // if(current_time>200){current_time=0}
  341. if(sec_fwd&&(video_elem.currentTime < sec_fwd/1)){
  342. video_elem.currentTime += sec_fwd/1;
  343. video_elem.oncanplay = "";
  344. }
  345. // video_elem.currentTime += 1;
  346.  
  347. }
  348.  
  349. //暂停缓存
  350.  
  351. sec_sub = localStorage.getItem('sec_sub');
  352. video_elem.onpause = function(){
  353. //youtube_hand.message_box.show('<div>'+document.querySelector("#header-author yt-formatted-string > a").innerText+'</div>');
  354. if(!buffer_time||buffer_time == 0){return;}
  355. if(parseInt(video_elem.currentTime)==parseInt(video_elem.duration)){current_time=0;video_elem.onpause = "";video_elem.onplay = "";video_elem.oncanplaythrough ="";}
  356. else{current_time = parseInt(video_elem.currentTime);
  357. video_elem.oncanplaythrough = function(){
  358. if(parseInt(video_elem.currentTime)==parseInt(video_elem.duration)){current_time=0;video_elem.onpause = "";video_elem.onplay = "";video_elem.oncanplaythrough ="";}
  359. else{video_elem.currentTime +=1;
  360. if(sec_sub){
  361. if((video_elem.currentTime-current_time)>(buffer_time?buffer_time:0)||(video_elem.duration<(video_elem.currentTime+parseInt(sec_sub)+10)))
  362. {video_elem.currentTime = current_time;
  363. console.log(current_time);console.log(video_elem.currentTime);
  364. video_elem.oncanplaythrough='';current_time=0;}
  365. }
  366. else{
  367. if(current_time!=0){
  368. if((video_elem.currentTime-current_time)>(buffer_time?buffer_time:0)||(video_elem.duration<(video_elem.currentTime+20)))
  369. {video_elem.currentTime = current_time;
  370. video_elem.oncanplaythrough='';}
  371. }
  372. else{ video_elem.oncanplaythrough='';}
  373. }
  374. }
  375. }
  376. video_elem.currentTime += 1;
  377. }
  378. }
  379. video_elem.onplay = function(){
  380.  
  381. if(parseInt(video_elem.currentTime)==parseInt(video_elem.duration-1)){current_time = 0;video_elem.onpause = "";video_elem.onplay = "";video_elem.oncanplaythrough ="";} // new
  382. else if(current_time){video_elem.currentTime = current_time;
  383. video_elem.oncanplaythrough = "";
  384. }
  385. }
  386. video_elem.onended = function(){current_time = 0;video_elem.onpause = "";video_elem.onplay = "";video_elem.oncanplaythrough ="";
  387. }
  388. //中键全屏
  389.  
  390. video_elem.addEventListener("mouseup", function(e) {
  391. e.preventDefault();
  392. if(e.button==1){
  393. document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-right-controls > button.ytp-fullscreen-button.ytp-button").click();
  394. }
  395. }, false);
  396. //按c开启/停止缓冲功能,按e调整视频速度
  397. doc_s.onkeydown = key_down;
  398.  
  399. function key_down(e){
  400. //document.addEventListener("keydown", function(e) {
  401. if (document.activeElement.id != "" && document.activeElement.id != "movie_player") {
  402. return;}
  403.  
  404. else{
  405. if (e.keyCode == 69) {
  406. e.preventDefault();
  407. if(buffer_time){
  408. temp_buffer = buffer_time;
  409. buffer_time="";
  410. current_time=0;
  411. //localStorage.setItem('buffer_time','');
  412. youtube_hand.message_box.show("no cashing set");
  413. }
  414. else if(temp_buffer){buffer_time=temp_buffer;
  415. // localStorage.setItem('buffer_time',temp_buffer);
  416. youtube_hand.message_box.show("cashing "+buffer_time+" seconds set");
  417. }
  418. else{youtube_hand.message_box.show("no cashing time preset");}
  419. }
  420. else if(e.keyCode == 68) {
  421. if(video_speed != 1){
  422. temp_speed = video_speed;
  423. video_speed=1;
  424. video_elem.playbackRate = video_speed;
  425. speed_display.innerHTML="1x";
  426. //localStorage.setItem('speed','1')
  427. youtube_hand.message_box.show("video speed 1x set");
  428. }
  429. else if(temp_speed){
  430. if(localStorage.getItem('speed')!=temp_speed){video_speed=localStorage.getItem('speed');}
  431. else{video_speed=temp_speed;}
  432. video_elem.playbackRate = video_speed/1;
  433. speed_display.innerHTML=video_speed+"x";
  434. //localStorage.setItem('speed',temp_speed);
  435. youtube_hand.message_box.show("video speed "+video_speed+"x set");
  436. }
  437. else{ youtube_hand.message_box.show("no video speed preset");}
  438.  
  439. }
  440. doc_s.onkeydown = "";
  441. setTimeout(function(){doc_s.onkeydown = key_down;},1500);
  442. }
  443. }
  444.  
  445. // 滚轮前进后退
  446. video_elem.onwheel = function(e){e.preventDefault()};
  447. v_elem.onwheel = wheel_e;
  448.  
  449. function wheel_e (event) {
  450. event.preventDefault();
  451.  
  452. video_elem.currentTime += parseInt(event.deltaY>0?wheel_sec/1:-wheel_sec) ;
  453.  
  454. v_elem.onwheel="";
  455. setTimeout(function(){v_elem.onwheel= wheel_e;},300);
  456.  
  457. //同时重设播放速度
  458. // video_speed = localStorage.getItem('speed');
  459. // document.querySelector("#movie_player > div.html5-video-container > video").playbackRate = video_speed;
  460.  
  461. }
  462.  
  463. //每隔25秒获取播放剩余时间,如在25秒内则执行主程序
  464. if(sec_sub !== ""&&sec_sub !=0){
  465. const sec_sub2=sec_sub/1+12;
  466. setInterval(function(){
  467. let left_duration = get_dura();
  468. if((left_duration < sec_sub) && (left_duration != 0))
  469. {
  470.  
  471. next_exec();
  472.  
  473. }
  474. }, 1000);
  475. }
  476.  
  477. //next part 执行
  478. function next_exec(){
  479. const sel_part2 = document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > a.ytp-next-button.ytp-button");
  480. if (sel_part2)
  481. {console.log("clicked next---");sel_part2.click();
  482. // video_elem.currentTime=0;
  483. current_time=0;}
  484. }
  485.  
  486. //获取播放剩余时间
  487. function get_dura() {
  488. const sel_start = video_elem.currentTime;
  489. const sel_fin = video_elem.duration;
  490. if (sel_fin) {
  491. return sel_fin-sel_start;
  492. }
  493. return 0;
  494. }
  495.  
  496.  
  497.  
  498.  
  499. }
  500.  
  501. },
  502.  
  503. move_menu:function (){
  504. //点开显示其余items
  505. document.querySelector("#sections > ytd-guide-section-renderer:nth-child(2) > #items > ytd-guide-collapsible-entry-renderer > #expander-item > #endpoint").click();
  506. //移动频道到左顶部
  507. document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1)").parentNode.append(document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1)"))
  508.  
  509.  
  510. //页面写入script和style
  511. var a_bug = document.createElement("script");
  512. a_bug.innerHTML = `// 监听draggable的相关事件
  513. function dragstart_handler(ev) {
  514. console.log("dragStart");
  515. // Add the target element's id to the data transfer object
  516. ev.dataTransfer.setData("text", ev.target.id);
  517. ev.dataTransfer.setData("text1", ev.target);
  518. console.log(ev.dataTransfer.getData("text1"));
  519. ev.dataTransfer.dropEffect = "move";
  520. }
  521. function dragEnter(ev) {
  522. console.log("dragenter");
  523. ev.preventDefault();
  524. ev.target.className += ' drag-over';
  525. }
  526. function dragLeave(e) {
  527. ev.preventDefault();
  528. this.className = 'droppable';
  529. }
  530. function dragover_handler(ev) {
  531. ev.preventDefault();
  532. //ev.dataTransfer.dropEffect = "move"
  533. }
  534. function drop_handler(ev) {
  535. ev.preventDefault();
  536. // Get the id of the target and add the moved element to the target's DOM
  537. var data = ev.dataTransfer.getData("text");
  538. var first=ev.target.firstChild; //得到第一个元素
  539. ev.target.insertBefore(document.getElementById(data),first); //在第原来的第一个元素之前插入
  540. //ev.target.appendChild(document.getElementById(data));
  541. }
  542. function dragend_handler(ev) {
  543. console.log("dragEnd");
  544. // Remove all of the drag data
  545. ev.dataTransfer.clearData();
  546. //localStorage.setItem("itemstate",document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1) #items").outerHTML);
  547.  
  548. //itemdetail写入localStorage
  549. var json = [];
  550. var data = {};
  551. var items_length=document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer").length
  552. for(var i=0;i<items_length-1;i++){
  553. data = {};
  554. //data.id = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer")[i].id;
  555. //data.imgsrc = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer #img")[i].src;
  556. data.text =document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer")[i].innerText;
  557. //data.href = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer > #endpoint")[i].href;
  558.  
  559. json.push(data);
  560.  
  561. }
  562. var jsonString = JSON.stringify(json);//[{"id":1,"imgsrc":"test1","text":2}]
  563. localStorage.setItem("itemdetail",jsonString);
  564. //localStorage.setItem("item_new","");
  565. }
  566. function noAllowDrop(ev) {
  567. console.log("stopPropagation");
  568. ev.stopPropagation();
  569. }
  570.  
  571.  
  572. //点击订阅或退订时,删除localStorage内已有相同item
  573. if(document.querySelector("#inner-header-container #subscribe-button")){var subscribe_button = document.querySelector("#inner-header-container #subscribe-button")}
  574. else if(document.querySelector("#meta-contents #top-row > #subscribe-button")){var subscribe_button = document.querySelector("#meta-contents #top-row > #subscribe-button");}
  575. // var subscribe_button = document.querySelector("#inner-header-container #subscribe-button")?document.querySelector("#inner-header-container #subscribe-button"):document.querySelector("#meta-contents #top-row > #subscribe-button");
  576.  
  577. if(subscribe_button){
  578.  
  579. subscribe_button.onclick=function(){
  580.  
  581. //localStorage.setItem("item_new",document.querySelector("#text > a").innerText);
  582. //localStorage.removeItem("itemdetail",document.querySelector("#channel-name #text").innerText);
  583. let obj = JSON.parse(localStorage.itemdetail);
  584. for(let j=obj.length-1;j>-1;j--){
  585. if(obj[j]&&obj[j].text==document.querySelector("#channel-name #text").innerText){
  586. let items_down = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer");
  587.  
  588. items_down.forEach(function(element,index,array) {
  589.  
  590. if(element.firstElementChild.title==document.querySelector("#channel-name #text").innerText){
  591.  
  592. document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1) #items").append(element);
  593. return false;
  594. }
  595. })
  596.  
  597. delete obj[j];}
  598. }
  599. localStorage.setItem("itemdetail",JSON.stringify(obj));
  600. console.log("delete suc");
  601. }
  602. }
  603. `;
  604. document.body.appendChild(a_bug);
  605.  
  606. var style_type2 = document.createElement("style");style_type2.id = "style_type";
  607. style_type2.innerHTML = `#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer{margin: 1em 0em 1em 0em !important;}
  608. .drag-over {
  609. border-style: dashed;
  610. }
  611. .droppable{}
  612. `;
  613. //#expandable-items > ytd-guide-entry-renderer{margin: 1.2em 0em 1.2em 0em !important;}
  614. document.head.appendChild(style_type2);
  615.  
  616. //开始操作
  617. var menu_opr = setInterval(function(){
  618.  
  619. // const droppables = document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1)");
  620. if(document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1) #items > ytd-guide-entry-renderer")){
  621. const droppables = document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1) > #items");
  622. const draggable = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer");
  623. const no_draggable = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer > #endpoint");
  624. // const no_droppable = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer > #endpoint > tp-yt-paper-item");
  625. // const no_droppable = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer > #endpoint *");
  626. const no_droppable = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items *");
  627.  
  628. const draggable2 = document.querySelectorAll("#expandable-items > ytd-guide-entry-renderer");
  629. const no_draggable2 = document.querySelectorAll("#expandable-items > ytd-guide-entry-renderer > #endpoint");
  630. // const no_droppable2 = document.querySelectorAll("#expandable-items > ytd-guide-entry-renderer > #endpoint *");
  631.  
  632. droppables.setAttribute("ondrop","drop_handler(event);");
  633. droppables.setAttribute("ondragover","dragover_handler(event);");
  634. // droppables.setAttribute("ondragenter","dragEnter(event);");
  635. // droppables.setAttribute("ondragleave","dragLeave(event);");
  636. no_draggable.forEach(function(element,index,array) {
  637. element.setAttribute("draggable",false);
  638. });
  639. no_draggable2.forEach(function(element,index,array) {
  640. element.setAttribute("draggable",false);
  641. });
  642.  
  643. no_droppable.forEach(function(element,index,array) {
  644. element.setAttribute("ondragover","noAllowDrop(event);");
  645. });
  646. // no_droppable2.forEach(function(element,index,array) {
  647. // element.setAttribute("ondragover","noAllowDrop(event);");
  648. //});
  649.  
  650.  
  651. draggable.forEach(function(element,index,array) {
  652. if(index<array.length){
  653. element.setAttribute("draggable",true);
  654. element.setAttribute("ondragstart","dragstart_handler(event);");
  655. element.setAttribute("ondragend","dragend_handler(event);");
  656. if(!element.id){element.setAttribute("id","move"+index);}
  657. }
  658. });
  659. let index_x =0;
  660. draggable2.forEach(function(element,index,array) {
  661. index_x=index+7;
  662. element.setAttribute("draggable",true);
  663. element.setAttribute("ondragstart","dragstart_handler(event);");
  664. element.setAttribute("ondragend","dragend_handler(event);");
  665. element.setAttribute("id","move"+index_x);
  666.  
  667. });
  668.  
  669. //把隐藏内容拉出来,放入items
  670. const parent_item = document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1) #items");
  671. let insert_sec = document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1) #items > ytd-guide-collapsible-entry-renderer");
  672. let new_content2=document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) #items > ytd-guide-collapsible-entry-renderer #expanded #expandable-items > ytd-guide-entry-renderer");
  673. new_content2.forEach(function(element){parent_item.insertBefore(element,insert_sec)});
  674.  
  675.  
  676. const obj = JSON.parse(localStorage.getItem("itemdetail"));
  677.  
  678. //getItem("itemdetail")然后写入网页列表
  679. if(localStorage.getItem("itemdetail")){
  680.  
  681. var items_drag = document.querySelectorAll("#sections > ytd-guide-section-renderer:nth-child(1) > #items > ytd-guide-entry-renderer");
  682.  
  683. for(var j=obj.length-1;j>-1;j--){
  684. // if(j==0){
  685. items_drag.forEach(function(element,index,array) {
  686.  
  687. //console.log(element.firstElementChild.title);
  688. //console.log(obj[j].text);
  689. if(obj[j]&&element.firstElementChild.title==obj[j].text){
  690.  
  691. parent_item.prepend(element);
  692. return false;
  693. }
  694. })
  695.  
  696. }
  697.  
  698.  
  699. }
  700. //把当日订阅置顶
  701. document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1) > #items").prepend(document.querySelector("#sections > ytd-guide-section-renderer:nth-child(2) #items > ytd-guide-entry-renderer:nth-child(4)"));
  702.  
  703. clearInterval(menu_opr);
  704. }
  705.  
  706. },100)
  707.  
  708. }
  709.  
  710.  
  711. }
  712.  
  713.  
  714.  
  715. var load_menu = setInterval(function(){
  716. //youtube_hand.dark_eye();
  717.  
  718. if(document.querySelector("#end")){
  719. youtube_hand.play_menu();
  720. youtube_hand.play_main();
  721. youtube_hand.dark_eye1();
  722.  
  723. //document.querySelector("html").onpropertychange = youtube_hand.dark_eye;
  724.  
  725. clearInterval(load_menu);
  726. }
  727. },100)
  728.  
  729. /*
  730. window.onload=function(){
  731. document.addEventListener("yt-navigate-finish", function() {
  732. youtube_hand.play_menu();
  733. youtube_hand.play_main();
  734. youtube_hand.dark_eye1();
  735. })
  736. };
  737. */
  738. setInterval(function(){ youtube_hand.dark_eye();},800)
  739.  
  740.  
  741. if(subscription_up){
  742. var move_ma=setInterval(function(){
  743. if(document.querySelector("#sections > ytd-guide-section-renderer:nth-child(2)"))
  744. {
  745. youtube_hand.move_menu();
  746.  
  747. clearInterval(move_ma);
  748. }
  749. },200)
  750. }
  751.  
  752.  
  753. })();