Greasy Fork is available in English.

B站转YouTube

B站快速携带标题搜索Youtube

// ==UserScript==
// @name         B站转YouTube
// @namespace    http://tampermonkey.net/
// @version      v1.0
// @description  B站快速携带标题搜索Youtube
// @author       SJ
// @match        *://www.bilibili.com/video/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    window.onload = function() {
        // 页面完全加载后,再等待1秒执行
        setTimeout(function() {
            // 获取元素
            var title = document.querySelector("head > title").innerText.split("_")[0];
            var toolbar = document.querySelector("#arc_toolbar_report > div.video-toolbar-left > div.video-toolbar-left-main");

            // 构造搜索 URL
            var search_url = `https://www.youtube.com/results?search_query=${encodeURIComponent(title)}`;

            // 创建新的链接元素
            var newLink = document.createElement('a');
            newLink.className = 'toolbar-left-item-wrap';
            newLink.href = search_url;
            newLink.target = '_blank';
            newLink.innerHTML = `
                <div title="转YTB" class="video-fav video-toolbar-left-item" data-v-b42ec39c="" data-v-1359e6fc="">
                    <svg t="1719887498118" class="video-share-icon video-toolbar-item-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4271" width="200" height="200">
                        <path d="M941.3 296.1c-10.3-38.6-40.7-69-79.2-79.3C792.2 198 512 198 512 198s-280.2 0-350.1 18.7C123.3 227 93 257.4 82.7 296 64 366 64 512 64 512s0 146 18.7 215.9c10.3 38.6 40.7 69 79.2 79.3C231.8 826 512 826 512 826s280.2 0 350.1-18.8c38.6-10.3 68.9-40.7 79.2-79.3C960 658 960 512 960 512s0-146-18.7-215.9zM423 646V378l232 133-232 135z" p-id="4272" fill="#d81e06"></path>
                    </svg>
                    <span class="video-fav-info video-toolbar-item-text" data-v-b42ec39c="">Youtube</span>
                </div>
            `;

            // 将新创建的链接添加到工具栏
            toolbar.appendChild(newLink);
        }, 1000); // 延迟1秒执行
    };
})();