抖音网页版优化

抖音网页版推荐、直播优化,网页全屏,全黑,自动按浏览器窗口调整大小

As of 2023-04-20. See the latest version.

  1. // ==UserScript==
  2. // @name 抖音网页版优化
  3. // @description 抖音网页版推荐、直播优化,网页全屏,全黑,自动按浏览器窗口调整大小
  4. // @namespace https://space.bilibili.com/482343
  5. // @author 古海沉舟
  6. // @license 古海沉舟
  7. // @version 1.9.1
  8. // @match https://www.douyin.com/*
  9. // @include https://www.douyin.com/recommend
  10. // @include https://www.douyin.com/*
  11. // @include https://www.douyin.com/?*
  12. // @include https://www.douyin.com/follow
  13. // @include https://live.douyin.com/*
  14. // @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
  15. // @run-at document-end
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_addValueChangeListener
  19. // @noframes
  20. // ==/UserScript==
  21.  
  22. var lastindex=0,livecount=0,livewidth=0,onelinecount,livelinecount;
  23.  
  24. function keydown(event) {
  25. //console.log(event.keyCode);
  26. if(event.keyCode == 109 || event.keyCode == 189){ // 按-或者小键盘-
  27. pagefullscreen();
  28. }
  29. }
  30. document.addEventListener('keydown', keydown, false);
  31.  
  32. var haspagefullscreen=0;
  33. if (location.href.indexOf("https://www.douyin.com/follow")>-1){
  34. haspagefullscreen=1;
  35.  
  36. let livestyle = document.createElement('style');
  37. livestyle.classList.add("live");
  38. livestyle.innerHTML = `
  39. .NQ38Bc0h .nvzm0QdP .X5RsU67Q { display: flex; flex-wrap: wrap; flex: 1 1 auto; overflow-y: scroll; }
  40. div.X5RsU67Q { width: 100%; overflow: auto; margin: auto; }
  41. div.X5RsU67Q { left: 0 !important; right: 0 !important; bottom: 0 !important; top: 0 !important; position: absolute !important; margin: auto !important; transform: none !important; }
  42. .NQ38Bc0h{height:100%}
  43. .JTIGfG2P.aSKksRfh { display: flex; flex-wrap: wrap; flex: 6 1 auto; overflow-y: scroll; height: auto !important; max-height: 550px !important; }
  44. .YwClj8rK:hover{
  45. flex: 12 1;
  46. }
  47. .YwClj8rK { min-height: 20px !important; }
  48. .NQ38Bc0h .nvzm0QdP .X5RsU67Q .o3pEYU7M { height: 80px !important; margin-left: 5px !important; margin-right: 5px !important; }
  49. .Jt6LO5RK .qOwBZHet .trexWhDY { border-radius: 0%; height: 48px; width: 48px; }
  50. .Jt6LO5RK .qOwBZHet .trexWhDY { animation: none; }
  51. .Jt6LO5RK .qOwBZHet { margin-top: 13px; margin-bottom: 2px; }
  52. .Jt6LO5RK .qOwBZHet .y5X4PaKT, .Jt6LO5RK .qOwBZHet .o4w20gFP, div.XcEg0PrM,div.Lo8QPz5R{ display: none !important }
  53.  
  54. .lXuWkeYW, .lXuWkeYW .oJArD0aS {
  55. height: 60px !important;
  56. }
  57.  
  58. div[data-e2e="recommend-guide-mask"]{display: none!important}
  59. `
  60. document.body.appendChild(livestyle);
  61. var liveheight=setInterval(function(){
  62. //直播个数
  63. livecount=$(`#douyin-right-container > div.JTIGfG2P.aSKksRfh > div > div.nvzm0QdP > div.X5RsU67Q > a`).length;
  64. console.log("直播个数",livecount);
  65. //宽度
  66. livewidth=$(`#douyin-right-container > div.JTIGfG2P.aSKksRfh > div > div.nvzm0QdP > div.X5RsU67Q`).width();
  67. console.log("宽度",livewidth);
  68. //每行多少列
  69. onelinecount=Math.trunc(livewidth/90);
  70. console.log("每行多少列",onelinecount);
  71. //多少行
  72. livelinecount=Math.ceil(livecount/onelinecount);
  73. console.log("多少行",livelinecount);
  74. //显示部分多高
  75. livecount=$(`#douyin-right-container`).height()-60;
  76. console.log("显示部分多高",livecount);
  77. //最大比例
  78. livewidth=Math.trunc(livecount/80)-1;
  79. console.log("最大比例",livewidth);
  80. //当前数量比例
  81. onelinecount=(livelinecount*80)/(livecount-(livelinecount*80))
  82. console.log("当前数量比例",onelinecount);
  83. //应该显示比例
  84. livelinecount=Math.min(livewidth,onelinecount);
  85. console.log("应该显示比例",livelinecount);
  86. if (isNaN(livelinecount) || livelinecount==null){
  87. return
  88. }
  89. clearInterval(liveheight);
  90. let livestyle2 = document.createElement('style');
  91. livestyle2.classList.add("live2");
  92. livestyle2.innerHTML = `
  93. .JTIGfG2P.aSKksRfh { display: flex; flex-wrap: wrap; flex: `+livelinecount+` 1 auto; overflow-y: scroll; height: auto !important; max-height: 550px !important; }
  94. `
  95. document.body.appendChild(livestyle2);
  96. },500);
  97.  
  98. }
  99. function pagefullscreen(){
  100. var is=0;
  101. //$(`#slidelist > div > div.swiper-wrapper > div.swiper-slide-active xg-icon.xgplayer-page-full-screen > div.xgplayer-icon`).click();
  102. $(`#sliderVideo xg-icon.xgplayer-page-full-screen > div.xgplayer-icon`).each(function(){
  103. haspagefullscreen=1;
  104. $(this).click();
  105. is=1;
  106. if (is){return}
  107. console.log("非推荐");
  108. $(`xg-controls xg-icon>div > div:nth-child(2)`).each(function(){
  109. if ($(this).parent().text().indexOf("网页全屏")<0)return;
  110. console.log("判断:",$(this).text()," ",$(this)[0]);
  111. haspagefullscreen=1;
  112. $(this).click();
  113. })
  114. })
  115. if (is){return}
  116. $(`div[data-e2e="living-container"] xg-icon>div>div`).each(function(){
  117. if ($(this).parent().text().indexOf("网页全屏")<0)return;
  118. console.log("判断:",$(this).text()," ",$(this)[0]);
  119. haspagefullscreen=1;
  120. $(this).click();
  121. })
  122.  
  123. }
  124. var firstfullscreen=setInterval(function(){
  125. if (haspagefullscreen){
  126. clearInterval(firstfullscreen);
  127. return;
  128. }
  129. pagefullscreen();
  130. },1000);
  131.  
  132. setInterval(function(){
  133. filtergift();
  134. },1000);
  135.  
  136. function filtergift(){ //过滤直播礼物
  137. $(`div.webcast-chatroom___item span.Q7mln_nz`).each(function(){
  138. if ($(this).text().indexOf("送出了")>-1){
  139. console.log($(this).parent().parent().parent().parent().text().replace(/\n/g, " ").replace(/\s\s/g, " "));
  140. $(this).parent().parent().parent().parent().hide();
  141. }
  142. })
  143. }
  144. function addCSS(){
  145. let wdstyle = document.createElement('style');
  146. wdstyle.classList.add("optimize");
  147. wdstyle.innerHTML = `
  148. div.gNyVUu_s, .OaNxZqFU img, .iRX47Q8q img { display: none!important }
  149. .qdcce5kG .VFMR0HAe { background: #0000 !important }
  150. .vLt8mbfQ .y8iJbHin .mMOxHVzv, .vLt8mbfQ .y8iJbHin .rrKCA47Q, div.webcast-chatroom, .BasEuG5Q ._QjzkgP3, .OaNxZqFU,.basicPlayer.xgplayer{ background: #000 !important }
  151. .Npz7CPXj, div.webcast-chatroom .webcast-chatroom___input-container .webcast-chatroom___textarea, .CgAB9miy, .JTIGfG2P, .NQ38Bc0h .XcEg0PrM, .N_HNXA04:not(.dUiu6B8O) .iViO9oMI, .UKFpY5tW, .SxCiQ8ip .EDvjMGPs,.SxCiQ8ip .A0ewbQCI,.fpRIB_wC,div.tgMCqIjJ, div.tgMCqIjJ.isDark,.sELpHy0M.metro .lgs6xhy7 .slot-item:hover,.sELpHy0M.metro .B9p3ney8:hover,.sELpHy0M.metro .UjStUCgW ._BSUxMOF:hover{ background: #111 !important }
  152. .N_HNXA04:not(.dUiu6B8O) .kQ2JnIMK .n9PPTk22, .N_HNXA04 .kQ2JnIMK, .iwzpXgQ3 .oJArD0aS, .xWPMYXKp .gOSlkVoB, .Exz5X5r1,.R5ITbXfy .k5cuEeRD,.sELpHy0M.metro .lgs6xhy7 .slot-item,.sELpHy0M.metro .B9p3ney8,.sELpHy0M.metro .UjStUCgW ._BSUxMOF{ background: #222 !important }
  153. div.JwGiJkkI, div.xgplayer-dynamic-bg, div.umOY7cDY, div.ruqvqPsH { display: none !important }
  154. .L8o4Hyg1,.L8o4Hyg1 .LFbb1oon,.L8o4Hyg1 .R6NHkCAw .i4vdvOF5{ box-shadow: none !important; border-bottom: none !important; border-right: none !important; }
  155.  
  156. .pgQgzInF.hqONwptG .Jf1GlewW.Ox89VrU5, .ckEyweZa.AmXnh1GR .QICHGW7r.RosH2lNv, .SxCiQ8ip.V6Va18Np .EDvjMGPs.FKQqfehj { height: 100% !important; }
  157. div.immersive-player-switch-on-hide-interaction-area, #video-info-wrap, xg-inner-controls.xg-inner-controls { opacity: 0.6 !important }
  158. .xgplayer-playswitch .xgplayer-playswitch-tab { opacity: 0 !important }
  159. div.xgplayer-playswitch-tab:hover, div.immersive-player-switch-on-hide-interaction-area:hover, #video-info-wrap:hover, xg-inner-controls.xg-inner-controls:hover { opacity: 1 !important }
  160. `
  161. document.body.appendChild(wdstyle);
  162. }
  163. addCSS();