您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a YouTube button to Google search results with a modified search query URL
// ==UserScript== // @name Google Search to YouTube Button // @namespace http://tampermonkey.net/ // @version 1.0 // @description Adds a YouTube button to Google search results with a modified search query URL // @author Zapper // @match https://www.google.com/search* // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // Find the target div and textarea elements const targetDiv = document.querySelector('div.RNNXgb'); const searchInput = document.querySelector('textarea.gLFyf'); // Create a button element const youtubeButton = document.createElement('button'); youtubeButton.innerText = 'Youtube'; // Apply CSS styling to the button youtubeButton.style.color = '#FFFFFF'; youtubeButton.style.padding = '10px'; youtubeButton.style.background = 'linear-gradient(to left, rgba(255, 68, 54, 1), rgba(255, 68, 54, 0))'; youtubeButton.style.border = 'none'; youtubeButton.style.borderRadius = '24px'; youtubeButton.style.borderTopLeftRadius = '0'; youtubeButton.style.borderBottomLeftRadius = '0'; youtubeButton.style.cursor = 'pointer'; youtubeButton.href = 'https://www.youtube.com/results?search_query'; // Handle button click event youtubeButton.addEventListener('click', function() { // Get the current search query from the textarea const searchQuery = searchInput.value.trim(); // Replace spaces with '+' const modifiedQuery = searchQuery.replace(/ /g, '+'); // Create the YouTube search URL const youtubeURL = `https://www.youtube.com/results?search_query=${modifiedQuery}`; // Open the YouTube URL in a new tab window.open(youtubeURL); }); // Append the button to the target div targetDiv.appendChild(youtubeButton); // Add scroll event listener window.addEventListener('scroll', function() { // Check if the user is at the top of the page const isAtTop = window.pageYOffset === 0; // Update the button's border radius based on scroll position youtubeButton.style.borderRadius = isAtTop ? '24px' : '16px'; }); // Set the URL as the tooltip when hovering over the button youtubeButton.addEventListener('mouseenter', function() { const searchQuery = searchInput.value.trim(); const modifiedQuery = searchQuery.replace(/ /g, '+'); const youtubeURL = `https://www.youtube.com/results?search_query=${modifiedQuery}`; youtubeButton.title = `Go to YouTube: ${youtubeURL}`; }); // Remove the tooltip when not hovering over the button youtubeButton.addEventListener('mouseleave', function() { youtubeButton.removeAttribute('title'); }); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址