Google - Change "Videos" tab to "YouTube"

Replaces the "Videos" navigation tab with "YouTube" so you can easily go to YouTube with your Google search query

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          Google - Change "Videos" tab to "YouTube"
// @namespace     http://userscripts.org/users/23652
// @description   Replaces the "Videos" navigation tab with "YouTube" so you can easily go to YouTube with your Google search query
// @include       http://www.google.com/search?*q=*
// @include       https://www.google.com/search?*q=*
// @copyright     JoeSimmons
// @version       1.0.2
// @license       GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @grant         GM_addStyle
// ==/UserScript==

(function () {
    var videosLink = document.querySelector('#hdtb-msb .hdtb-mitem a[href*="&tbm=vid"]'),
        intv;

    function changeLink() {
        if (videosLink.firstChild.data === 'YouTube' && videosLink.href.indexOf('youtube.com') !== -1) {
            return window.clearInterval(intv);
        }

        // change the link's text
        videosLink.firstChild.data = 'YouTube';

        // change the link's url
        videosLink.href = 'https://www.youtube.com/results?search_query=' + location.href.match(/[?&]?q=([^&]*)/)[1];
    }

    // make sure the page is not in a frame
    // and if there is a "Videos" link
    if (window.frameElement || window !== window.top || !videosLink) { return; }

    // change the link's text
    // keep changing it until it actually changes... sometimes it doesn't work right away

    intv =  window.setInterval(changeLink, 500);
}());