B站自动宽屏<1>

自动宽屏、自动调整滚动条位置、右侧空白区域点击回到顶部

目前為 2021-04-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name        B站自动宽屏<1>
// @description 自动宽屏、自动调整滚动条位置、右侧空白区域点击回到顶部
// @version     3
// @author      zhanq修改、原作者Huu Lane
// @include     *://www.bilibili.com/video/*
// @namespace nobody_space
// ==/UserScript==

//////////////////////////////
//自动宽屏、调整滚动条位置
;(async function () {
  // prevent space bar from scrolling page

  window.addEventListener('keydown', function (e) {
    if (e.code === 'Space' && e.target == document.body) {
      e.preventDefault()
    }
  })

  const sleep = function * (sec) {
    while (true) {
      yield new Promise(res => setTimeout(res, sec * 1000))
    }

  }

  for await (const __ of sleep(0.5)) {
    const box = document.querySelector(
      '.bilibili-player-video-control-bottom-right',
    )
    const btn = box.querySelector('.bilibili-player-video-btn-widescreen')
    if (btn) {
      btn.click()
      break
    }
  }
   window.scrollTo(0,143.8)
})()

////////////////////////////////
//右侧大区域添加回到顶部隐藏按钮
;(async function() {
    var btnId = '__gotop';
    var isIE = !!window.ActiveXObject && /msie (\d)/i.test(navigator.userAgent) ? RegExp['$1'] : false;

    function $() {
        return document.getElementById(arguments[0]);
    }

    function getScrollTop() {
        return ('pageYOffset' in window) ? window.pageYOffset
            : document.compatMode === "BackCompat"
            && document.body.scrollTop
            || document.documentElement.scrollTop ;
    }

    function bindEvent(event, func) {
        if (window.addEventListener) {
            window.addEventListener(event, func, false);
        } else if (window.attachEvent) {
            window.attachEvent('on' + event, func);
        }
    }

    bindEvent('load',
        function() {
            var css = 'width:125px;height:560px;position:fixed;right:10px;top:8px;border-radius:10px;cursor:pointer;display:none;';

            if (isIE && isIE < 7) {
                css += '_position:absolute;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-30-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))';
                var style = document.createStyleSheet();
                style.cssText = '*html{background-image:url(about:blank);background-attachment:fixed;}';
            }

            var html = '';
            var el = document.createElement('DIV');
            el.id = btnId;
            el.style.cssText = css;
            el.innerHTML = html;
            document.body.appendChild(el);

            el.onclick = function() {
                (
                    window.scrollTo(0,143.8)
                )();
            };

            el.onmouseover = function() {
                $(btnId).firstChild.style.borderBottom = '14px solid #ddd';
                $(btnId).firstChild.firstChild.style.backgroundColor = '#ddd';
            };

            el.onmouseout = function() {
                $(btnId).firstChild.style.borderBottom = '14px solid #fff';
                $(btnId).firstChild.firstChild.style.backgroundColor = '#fff';
            };
        }
    );

    bindEvent('scroll',
        function() {
            var top = getScrollTop(), display = 'none';

            if (top >= 0) {
                display = 'block';
            }

            $(btnId).style.display = display;
        });
})();