BilibiliTimer

B站H5播放器全屏时右上角实时显示当前系统时间

目前為 2017-06-06 提交的版本,檢視 最新版本

// ==UserScript==
// @name         BilibiliTimer
// @version      1.0.3
// @description  B站H5播放器全屏时右上角实时显示当前系统时间
// @author       AnnAngela
// @match        *://www.bilibili.com/video/*
// @match        *://www.bilibili.com/html/*layer.htm*
// @run-at       document-start
// @grant        unsafeWindow
// @namespace    https://gf.qytechs.cn/users/129402
// ==/UserScript==

(function() {
    'use strict';
    /* 
     * 出于实现上的考虑,以下代码被保存为纯文本,并通过unsafeWindow.eval运行,以操作真实环境下的DOM节点
     */
    var code = [
        "\"use strict\";",
        "var _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function(obj) {",
        "return typeof obj;",
        "} : function(obj) {",
        "return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;",
        "};",
        "",
        "function _inherits(subClass, superClass) {",
        "if (typeof superClass !== \"function\" && superClass !== null) {",
        "throw new TypeError(\"Super expression must either be null or a function, not \" + (typeof superClass === \"undefined\" ? \"undefined\" : _typeof(superClass)));",
        "}",
        "subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });",
        "if (superClass) {",
        "if (Object.setPrototypeOf) Object.setPrototypeOf(subClass, superClass);",
        "else subClass.__proto__ = superClass;",
        "}",
        "}",
        "",
        "function _classCallCheck(instance, Constructor) {",
        "if (!(instance instanceof Constructor)) {",
        "throw new TypeError(\"Cannot call a class as a function\");",
        "}",
        "}",
        "",
        "function _possibleConstructorReturn(self, call) {",
        "if (!self) {",
        "throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");",
        "}",
        "return call && ((typeof call === \"undefined\" ? \"undefined\" : _typeof(call)) === \"object\" || typeof call === \"function\") ? call : self;",
        "}",
        "var BilibiliPlayerDate = function(_Date) {",
        "_inherits(BilibiliPlayerDate, _Date);",
        "",
        "function BilibiliPlayerDate() {",
        "var _ref;",
        "for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; }",
        "_classCallCheck(this, BilibiliPlayerDate);",
        "var _this = _possibleConstructorReturn(this, (_ref = BilibiliPlayerDate.__proto__ || Object.getPrototypeOf(BilibiliPlayerDate)).call.apply(_ref, [this].concat(args)));",
        "[\"getDate\", \"getFullYear\", \"getHours\", \"getMilliseconds\", \"getMinutes\", \"getMonth\", \"getSeconds\", \"getTime\", \"getUTCDate\", \"getUTCFullYear\", \"getUTCHours\", \"getUTCMilliseconds\", \"getUTCMinutes\", \"getUTCMonth\", \"getUTCSeconds\", \"getYear\"].forEach(function(key) {",
        "_this[key] = function() {",
        "var result = Date.prototype[key].bind(this).apply(undefined, arguments);",
        "if (key.includes('Month')) result++;",
        "if (typeof result === 'number' && (result + '').length === 1) return \"0\" + result;",
        "else return result + '';",
        "};",
        "});",
        "return _this;",
        "}",
        "return BilibiliPlayerDate;",
        "}(Date);",
        "var timer = window.$('<div/>');",
        "timer.attr('id', 'BilibiliTimer');",
        "var globallock = false;",
        "timer.css({ right: '10px', background: 'rgba(28,28,28,.8)', 'border-radius': '4px', color: '#fff', 'font-family': '\"Noto Sans CJK SC DemiLight\",Roboto,\"Segoe UI\",Tahoma,Arial,Helvetica,sans-serif', '-webkit-font-smoothing': 'antialiased', position: 'absolute', top: '10px', 'z-index': '64', padding: '15px 36px 15px 15px', display: 'none' });",
        "var button = window.$('<a/>');",
        "button.text('[x]');",
        "button.css({ position: 'absolute', right: '10px', top: '10px', 'z-index': '49', color: '#ddd, 'font-size': '13px' });",
        "timer.append(button);",
        "button.on('click', function() {",
        "globallock = true;",
        "timer.fadeOut(370);",
        "});",
        "timer.append('<div>当前时间:<span></span></div>');",
        "setInterval(function() {",
        "var globalmode = !!window.$('.mode-fullscreen')[0];",
        "if (globalmode) {",
        "if (!globallock) timer.fadeIn();",
        "} else {",
        "globallock = false;",
        "timer.fadeOut();",
        "}",
        "if (timer.is(':visible')) {",
        "var date = new BilibiliPlayerDate();",
        "timer.find('span').text(date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds());",
        "}",
        "}, 137);",
        "(function loop(timer) {",
        "if (!window.$('.bilibili-player-video-wrap')[0]) {",
        "console.debug('BilibiliTimer', 'nope');",
        "setTimeout(loop, timer, 1370);",
        "} else {",
        "window.$('.bilibili-player-video-wrap').append(timer);",
        "console.debug('BilibiliTimer', 'Yep', window.$('#BilibiliTimer'));",
        "}",
        "})(timer);"
    ].join('');
    unsafeWindow.addEventListener('load', function() {
        unsafeWindow.eval(code);
    });
})();

QingJ © 2025

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