虎牙Plus

虎牙自动领取任务经验、开宝箱,复制直播流链接,简化页面,去广告, 夜间模式,自动进入剧场模式

目前为 2020-05-13 提交的版本。查看 最新版本

  1. 'use strict';
  2. // ==UserScript==
  3. // @name 虎牙Plus
  4. // @namespace http://tampermonkey.net/
  5. // @icon https://www.google.com/s2/favicons?domain=huya.com
  6. // @version 1.0.2
  7. // @description 虎牙自动领取任务经验、开宝箱,复制直播流链接,简化页面,去广告, 夜间模式,自动进入剧场模式
  8. // @author Francis
  9. // @match *://*.huya.com/*
  10. // @grant GM_setClipboard
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. let $;
  15.  
  16. function addUi(){
  17. let style = document.createElement('style');
  18. style.appendChild(document.createTextNode(`
  19. span.copy-stream-link:after {
  20. display: none;
  21. position: absolute;
  22. content: "";
  23. right: -20px;
  24. top: 6px;
  25. width: 18px;
  26. height: 18px;
  27. overflow: hidden;
  28. background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA4RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJ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WtDN4ekxp6uZh7zWXpmid9sYfpzSkhbfwHU6/JBJuNSekZbCn+bOysUbJ+V+dNsTYgKspNvQmRQPMw4bKDt0gCaXcOmSgXLpER/GMnwC+2NLYD09eeBkylganoMajuuQt94u3PLpJNhlj/MgpUrISf5FsSF7+GfLfZheKIrhpHJ767dsshwv1gwGm3YstUwav3ltT0ufDea3eZNSeO2ATQrAdNUr2fXVDJM8j3yFZC76Q6sCk6AZ58vQ7/5i1u7OuYkZMQX4aD4JASzbRBq2i7h4Pq8hdvIuRzECxQdugUKd1ZB7PIdEKgIg/ztD/nfzizMSS6HQwkl82a2GQs8b78iZEaKEDy8t0ZlQmZSGci5gH+7WB4EedseQH33fdgVfYIfkFPTDismSCkMTRhB7LYwsRPfTQOWLrDOmPkldVUAFwjZqhseveegTl8OvWOfxNLBREva7a1laOIb1OiK+GwTU0PPI+gafislmQ1k2CTUSilNCUBZJ6SOwXpo6q2WunuayPCVrx5/pn6gaRGMWfth4bIbQGu4K3bJu+o1Gb5jN7WgaP89bruI++rn/H+UkS86r+PRZZdqRh6NHBvePbHetKz0TWnGJK1B4zYACSIPh/zw2Rh60LEjLtrXG/bZSdBjclhsQ6AbeLkYs1akmCbnvA9nkVN0BIq9OWEfgZa+p4sxo5gFzMPtxtcjeTQRP95UdhZTL1TTaJFcKTOVOLNcFtNn1aZlt3/rEsxaWQyt1LqUlkCNnEOMizAysnfUrssotfKmyrmSVdEHkePs7tzgUeobWalPafteqOJ26q8AAwB8rQG0tt5ioQAAAABJRU5ErkJggg==);
  29. background-size: 18px 18px;
  30. }
  31.  
  32. span.copy-stream-link.copy-success:after {
  33. display: block;
  34. }
  35.  
  36. .huya-plus-btn{
  37. display: block;
  38. padding:0 10px;
  39. color:#b08444;
  40. background:#FFD29E;
  41. border-radius:15px;
  42. margin-left: 30px;
  43. user-select: none;
  44. transition:all .5s;
  45. }
  46.  
  47. .huya-plus-btn:hover{
  48. color:#FFF;
  49. background:#ffa801;
  50. }
  51.  
  52. #huya-ab,.player-banner-gift,#player-marquee-wrap,.room-gg-chat,.room-mod-ggTop{
  53. display:none !important;
  54. }
  55.  
  56. *{
  57. transition: background .5s;
  58. }
  59.  
  60. .night-mode .duya-header-wrap,
  61. .night-mode #main_col,
  62. .night-mode .room-hd-l,
  63. .night-mode .player-gift-wrap,
  64. .night-mode .chat-room__ft,
  65. .night-mode .jspPane,
  66. .night-mode #J_profileNotice>div,
  67. .night-mode .week-rank__btn,
  68. .night-mode .J_msg,
  69. .night-mode .chat-room__list,
  70. .night-mode .msg-nobleEnter,
  71. .night-mode .msg-nobleEnter>div,
  72. .night-mode .msg-nobleSpeak,
  73. .night-mode .player-face-arrow,
  74. .night-mode #player-gift-tip,
  75. .night-mode .jspVerticalBar,
  76. .night-mode .illegal-report,
  77. .night-mode .subscribe-hd.sub-on,
  78. .night-mode .huya-plus-btn,
  79. .night-mode #player-gift-tip bottom,
  80. .night-mode #player-gift-tip btn,
  81. .night-mode .fansBadge-box,
  82. .night-mode .nav-expand-list,
  83. .night-mode .tt-user-card,
  84. .night-mode .share-entrance,
  85. .night-mode .search-suggest,
  86. .night-mode .u-links,
  87. .night-mode .entrance-expand,
  88. .night-mode .gameBuy-bd,
  89. .night-mode .guide-to-app,
  90. .night-mode .chat-room__wrap,
  91. .night-mode .night-mode-btn-wrapper,
  92. .night-mode #J_profileNotice,
  93. .night-mode .msg-onTVLottery,
  94. .night-mode .room-core
  95. {
  96. background-color: rgb(47, 48, 53) !important;
  97. }
  98.  
  99. .night-mode .subscribe-hd.sub-on,
  100. .night-mode .huya-plus-btn,
  101. .night-mode .nav-expand-game dd a
  102. {
  103. background-color: #464646 !important;
  104. }
  105.  
  106. .night-mode .subscribe-hd.sub-on,
  107. .night-mode .huya-plus-btn,
  108. .night-mode .match-item
  109. {
  110. color: #8e8a8a !important;
  111. }
  112.  
  113. .night-mode .hy-nav-link,
  114. .night-mode .hy-nav-title,
  115. .night-mode .nav-user-title,
  116. .night-mode #J_roomTitle,
  117. .night-mode .msg,
  118. .night-mode .subscribe-hd.sub-on,
  119. .night-mode .huya-plus-btn,
  120. .night-mode .cont-item,
  121. .night-mode .week-rank__btn,
  122. .night-mode .week-rank-name,
  123. .night-mode .msg-nobleEnter,
  124. .night-mode .peo-name,
  125. .night-mode .search-item,
  126. .night-mode .history-bd .new-clickstat,
  127. .night-mode .from,
  128. .night-mode .to,
  129. .night-mode .nav-expand-game dd a,
  130. .night-mode .hy-header-match-preview-name,
  131. .night-mode #pub_msg_input,
  132. .night-mode #search-bar-input:focus
  133. {
  134. color: #E7E7E7 !important;
  135. }
  136.  
  137. .night-mode .room-sidebar,
  138. .night-mode .duya-header-wrap,
  139. .night-mode .week-rank__unit,
  140. .night-mode .chat-room__input,
  141. .night-mode .chatNotice,
  142. .night-mode #J_profileNotice,
  143. .night-mode .plaer-face-icon-bg,
  144. .night-mode .chat-room__ft__chat,
  145. .night-mode #tipsOrchat
  146. {
  147. border-color: #3e3e3e !important;
  148. }
  149.  
  150. .night-mode .week-rank__btn.active,
  151. .night-mode #pub_msg_input,
  152. .night-mode #J_weekRankList li:hover,
  153. .night-mode #J_fansRankList li:hover,
  154. .night-mode .seat-item:hover,
  155. .night-mode #search-bar-input,
  156. .night-mode .search-item:hover,
  157. .night-mode .video-link:hover,
  158. .night-mode .history-bd .new-clickstat:hover,
  159. .night-mode .video-item:hover,
  160. .night-mode .match-item:hover,
  161. .night-mode .hy-header-match-preview li:hover
  162. {
  163. background-color: #565656 !important;
  164. }
  165.  
  166. .night-mode-btn-wrapper{
  167. float: left;
  168. position: relative;
  169. margin-left:15px;
  170. background: #FFF;
  171. height: 100%;
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. }
  176.  
  177. .night-mode-switch-btn{
  178. width: 50px;
  179. border: 1px solid #e4e4e4;
  180. height: 26px;
  181. border-radius: 13px;
  182. background-color:#ff8a00;
  183. }
  184.  
  185. .night-mode-switch-dot{
  186. width: 24px;
  187. height: 24px;
  188. border-radius: 12px;
  189. background: #FFF;
  190. line-height: 24px;
  191. border:1px solid #b1b1b1;
  192. text-align: center;
  193. color: #6b6b6b;
  194. transition: all .5s;
  195. cursor: pointer;
  196. user-select:none;
  197. }
  198.  
  199. .night-mode .night-mode-switch-btn{
  200. background-color:#8c8c8c;
  201. }
  202.  
  203. .night-mode .night-mode-switch-dot{
  204. transform: translateX(24px);
  205. }
  206. `));
  207.  
  208. document.head.appendChild(style);
  209.  
  210. let copyStreamLinkNode = document.createElement('div');
  211. copyStreamLinkNode.style = "cursor: pointer;display:inline-flex;vertical-align:top;";
  212. const openWithPlayerBtn = isMacOS() ? `<span class="huya-plus-btn open-with-iina" style="position: relative;">使用IINA打开</span>`: `<span class="huya-plus-btn open-with-potplayer" style="position: relative;">使用PotPlayer打开</span>`;
  213. copyStreamLinkNode.innerHTML = `<span class="huya-plus-btn copy-stream-link" style="position: relative;">复制直播流</span>${openWithPlayerBtn}`;
  214. document.querySelector('.host-title').appendChild(copyStreamLinkNode);
  215.  
  216. document.querySelector('.copy-stream-link').onclick = e=>{
  217. GM_setClipboard(getStreamUrl());
  218. showCopySuccessIcon();
  219. };
  220.  
  221. $(".open-with-iina").click(()=>{
  222. openStreamWithIINA(getStreamUrl());
  223. });
  224.  
  225. $(".open-with-potplayer").click(()=>{
  226. openStreamWithPotPlayer(getStreamUrl());
  227. });
  228. }
  229.  
  230. function getStreamUrl(){
  231. let config = unsafeWindow.hyPlayerConfig;
  232. try{
  233. let info = config.stream.data[0].gameStreamInfoList[0]
  234. return `${info.sHlsUrl}/${info.sStreamName}.${info.sHlsUrlSuffix}?${info.sHlsAntiCode}`;
  235. }catch(e){
  236. alert("获取直播流链接失败,房间未开播或刷新页面后重试")
  237. throw e;
  238. }
  239. }
  240.  
  241. function isMacOS(){
  242. var UserAgent = navigator.userAgent.toLowerCase();
  243. return /mac os/.test(UserAgent);
  244. }
  245.  
  246. function showCopySuccessIcon(){
  247. $('span.copy-stream-link').addClass('copy-success');
  248. setTimeout(()=>{$('span.copy-stream-link').removeClass('copy-success');},1000)
  249. }
  250.  
  251. function autoReceiveBoxReward(){
  252. let rewardBtns = $(".player-box-list .player-box-stat3").filter((i,it)=>$(it).css("visibility") === 'visible');
  253. if(rewardBtns.size() > 0){
  254. let btn = $(rewardBtns[0]);
  255. btn.click();
  256. let waitComplete = ()=>{
  257. if(btn.css("visibility") === 'hidden'){
  258. $("#player-box").hide();
  259. console.log("开启宝箱");
  260. autoReceiveBoxReward();
  261. } else {
  262. setTimeout(waitComplete,1000);
  263. }
  264. };
  265. setTimeout(waitComplete,1000);
  266. }
  267. }
  268.  
  269. function autoReceiveTaskXP(){
  270. let taskBtns = $(".tasks .status .status-get");
  271. if(taskBtns.size() > 0){
  272. $.each(taskBtns,(_,btn)=>{
  273. $(btn).click();
  274. });
  275. console.log(`自动领取经验,本次完成${taskBtns.length}个任务`)
  276. }
  277. }
  278.  
  279. function cleanPage(){
  280. $(".room-gg-chat").remove();
  281. $(".room-footer").remove();
  282. }
  283.  
  284. function completeChatTask(){
  285. const taskInfo = $(".tasks .tit").filter((i,it)=>$(it).text() === '在1场直播中发送弹幕');
  286. const taskDone = taskInfo.siblings(".status").find(".status-ing").size() === 0;
  287. if(!taskDone){
  288. chat('[送花]')
  289. }
  290. }
  291.  
  292. function chat(msg){
  293. $("#pub_msg_input").val(msg).keyup();
  294. $("#msg_send_bt").click();
  295. }
  296.  
  297. function pageLoaded(){
  298. $ = unsafeWindow.$
  299. if($){
  300. if($(".tasks .status").size() == 0){
  301. $(".nav-user-title").mouseenter()
  302. }
  303. return $(".box-icon-word").size() > 0 && $(".tasks .status").size() > 0
  304. }
  305. return false;
  306. }
  307.  
  308. function openStreamWithPotPlayer(streamUrl){
  309. openStreamWithPlayer("PotPlayer://", streamUrl);
  310. }
  311.  
  312. function openStreamWithIINA(streamUrl){
  313. openStreamWithPlayer("iina://weblink?url=", streamUrl)
  314. }
  315.  
  316. function openStreamWithPlayer(playerUrlSchema, streamUrl){
  317. window.open(`${playerUrlSchema}${streamUrl}`, "_self")
  318. }
  319.  
  320. async function waitLoad(){
  321. return new Promise(function(resolve,reject){
  322. let w = ()=>{
  323. if(pageLoaded()){
  324. resolve();
  325. } else {
  326. setTimeout(w,1000);
  327. }
  328. }
  329. w();
  330. });
  331. }
  332.  
  333. function nightMode(){
  334. $("#J_global_user_tips").before(`
  335. <div class="night-mode-btn-wrapper">
  336. <div class="night-mode-switch-btn">
  337. <div class="night-mode-switch-dot">日</div>
  338. </div>
  339. </div>
  340. `)
  341.  
  342. let switchDay = ()=>{
  343. $(".night-mode-switch-dot").text("日");
  344. document.body.classList.remove('night-mode');
  345. localStorage.setItem("night-mode",false);
  346. }
  347.  
  348. let switchNight = ()=>{
  349. $(".night-mode-switch-dot").text("夜");
  350. document.body.classList.add('night-mode');
  351. localStorage.setItem("night-mode",true);
  352. }
  353.  
  354. $(".night-mode-switch-btn").click(()=>{
  355. if(document.body.classList.contains("night-mode")){
  356. switchDay();
  357. } else {
  358. switchNight();
  359. }
  360. })
  361.  
  362. if(localStorage.getItem("night-mode") === 'true'){
  363. switchNight();
  364. }
  365. }
  366.  
  367. let timer;
  368. (async function() {
  369. let intervalInMills = 10 * 60 * 1000 + 100;
  370. let task = ()=>{
  371. autoReceiveBoxReward();
  372. autoReceiveTaskXP();
  373. };
  374. await waitLoad();
  375.  
  376. cleanPage();
  377. nightMode();
  378. $(".player-fullpage-btn").click();
  379. completeChatTask();
  380. addUi();
  381. task();
  382. if(timer) clearInterval(timer);
  383. timer = setInterval(task,intervalInMills);
  384. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址