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