Greasy Fork

Greasy Fork is available in English.

虎牙极简界面

简单又优雅的界面,去除不必要的元素和广告,增加空格快捷键:按空格即可控制播放与暂停

当前为 2022-08-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         虎牙极简界面
// @namespace    http://tampermonkey.net/
// @version      1.2.0
// @description  简单又优雅的界面,去除不必要的元素和广告,增加空格快捷键:按空格即可控制播放与暂停
// @author       You
// @match        https://www.huya.com/*
// @icon         https://www.google.com/s2/favicons?domain=huya.com
// @grant        none
// @license MIT
// ==/UserScript==
  // player-videotype-list
  // player-box-stat3
(function() {
  'use strict';

  const selector = value => document.querySelector(value)
  const selectotAll = value => document.querySelectorAll(value)

  // 增加播放快捷键
  window.onkeydown = (event) => {
    if (event.keyCode === 32) {
      selector('#player-btn').click()
      event.preventDefault();
    }
  }

  // 移除不必要的页面元素
  const removeNodesFunc = (nodes) => {
    nodes.forEach(node => {
      document.querySelector(node)?.remove()
    })
  }

  // 移除广告弹窗
  const removeAds = () => {
    const removeNodes = ['.room-gg-chat', '.room-mod-ggTop', '.banner-ab-warp']
    removeNodesFunc(removeNodes)
    // 移除所有的iframe
    selectotAll('iframe').forEach(iframe => iframe.remove())
  }
  
  setInterval(() => {
    removeAds()
  }, 1000);

  // 切换最高清晰度
  const swtichQuality = () => {
    const ul = document.querySelector('.player-videotype-list')
    if (ul) {
      const firstLi = ul.firstElementChild
      // 切换到最高清画质
      firstLi.click()
    }
  }

  // 将header以及播放室移到body中,删除#root元素
  const purify = () => {
    document.body.setAttribute('style', 'overflow: auto')
    document.body.appendChild(selector('#duya-header'))
    document.body.appendChild(selector('.room-core'))
    selector('.room-core').
    setAttribute('style', 'position: absolute; top: 60px !important; overflow: auto;')
    selector('#root').remove()
    setTimeout(() => {
      clearTool()
    }, 3000)
  }

  // 清除不必要的工具
  const clearTool = () => {
    const unUseTool = [
      // 工具栏右边工具
      '.player-gift-right',
      '#player-face',
      '#week-star-btn',
      '#diy-pet-icon',
      // 工具栏左边魔法学院
      '#diy-activity-icon-13833',
      // 秘法寻宝
      '#front-4a0mhq51_web_video_com',
      // 贵族周福利
      '#diy-activity-icon-13889',
      // 更多悬浮窗箭头
      '.player-arrow-down',
    ]
    removeNodesFunc(unUseTool)
     selector('.more-attivity-panel').
     setAttribute('style', 'left: -64px !important; width: 240px !important;')
  }

  setTimeout(() => {
    swtichQuality()
    purify()
    onVideoPlay()
  }, 2000);

})();