Greasy Fork

Greasy Fork is available in English.

自用bilibili脚本

吧啦吧啦

当前为 2021-12-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         自用bilibili脚本
// @namespace    mimiko/bilibili
// @version      0.0.2
// @description  吧啦吧啦
// @author       Mimiko
// @license      MIT
// @match        *://www.bilibili.com/*
// @grant        GM.addStyle
// ==/UserScript==
// http://greasyfork.icu/zh-CN/scripts/436748-%E8%87%AA%E7%94%A8bilibili%E8%84%9A%E6%9C%AC

(() => {

  if (window.top !== window.self) return

  // function

  const asBangumi = () => {
    log('as bangumi')
    asPlayer()
    hide('#review_module') // 隐藏点评
  }

  const asCommon = () => {
    log('as common')
    hide('#internationalHeader .nav-link-item:last-of-type') // 移除下载APP
  }

  const asIndex = () => {
    log('as index')
    hide('#reportFirst2') // 隐藏推广
    hide('#bili_live') // 隐藏直播
    removeNodeByText('#elevator .item', '直播') // 处理电梯
  }

  const asPlayer = () => {
    log('as player')
    hide('.bilibili-player-electric-panel') // 隐藏充电面板
    hide('.bilibili-player-ending-panel') // 隐藏视频推荐
    hide('.bilibili-player-video-hint') // 隐藏弹幕礼仪
  }

  const asVideo = () => {
    log('as video')
    asPlayer()
  }

  const hide = (
    selector,
  ) => GM.addStyle(`${selector} { display: none !important; }`)

  const log = (...args) => console.log('[bilibili]', ...args)

  const removeNodeByText = (
    selector,
    text,
  ) => document.querySelectorAll(selector).forEach($it => {
    const content = $it.textContent?.trim()
    if (content === text) $it.remove()
  })

  const route = () => {
    asCommon()
    const path = window.location.pathname
    if (path === '/') return asIndex()
    if (path.startsWith('/video/BV')) return asVideo()
    if (path.startsWith('/bangumi/play/ep')) return asBangumi()
  }

  // execute
  route()

})()