Skip to content
Discussion options

You must be logged in to vote
// ==UserScript==
// @name         B站推荐视频新标签页打开
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  点击B站右侧推荐视频时,强制在新标签页中打开
// @author       Your Name
// @match        https://www.bilibili.com/video/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // 监听点击事件,处理推荐视频链接
    function handleRecommendClicks(event) {
        // 获取点击的目标元素
        const target = event.target;

        // 检查点击的是否是推荐视频的链接
        const videoLink = target.closest('a[href^="/video/"]');
        if (videoLink) {
            // 阻止默认行为(在当前页面打开)
            event.preventDefault();

            // 获取视频的完整链接
            const videoUrl = new URL(videoLink.href, window.…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by iduee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants