Bilibili 跳转按钮

在指定页面添加一个跳转按钮,跳转到指定页面

目前為 2024-04-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Bilibili 跳转按钮
// @namespace    https://www.bilibili.com/
// @version      0.5
// @description  在指定页面添加一个跳转按钮,跳转到指定页面
// @author       咖啡_l
// @match        https://www.bilibili.com/
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 创建一个按钮
    var jumpButton = document.createElement('button');
    jumpButton.innerText = '当前在线';
    jumpButton.style.position = 'fixed';
    jumpButton.style.top = '65%'; // 放置在页面中间
    jumpButton.style.right = '0px'; // 靠右
    jumpButton.style.transform = 'translateY(-50%)'; // 垂直居中
    jumpButton.style.backgroundColor = 'lightblue'; // 设置背景颜色为淡蓝色
    jumpButton.style.border = 'none'; // 去除边框
    jumpButton.style.padding = '10px 20px'; // 设置内边距
    jumpButton.style.color = '#fff'; // 设置文字颜色为白色
    jumpButton.style.fontWeight = 'bold'; // 设置文字加粗
    jumpButton.style.cursor = 'pointer'; // 鼠标指针样式为手型
    jumpButton.style.zIndex = '9999';

    // 给按钮添加点击事件,点击时跳转到指定页面
    jumpButton.addEventListener('click', function() {
        window.location.href = 'https://www.bilibili.com/video/online.html?spm_id_from=333.851.b_7265706f7274466972737432.14';
    });

    // 将按钮添加到页面上
    document.body.appendChild(jumpButton);
})();