您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Open "Video" tab of youtube channel by default
当前为
// ==UserScript== // @name YT video tab by default // @description Open "Video" tab of youtube channel by default // @author MK // @namespace max44 // @homepage https://greasyfork.org/en/users/309172-max44 // @match *://*.youtube.com/* // @match *://*.youtu.be/* // @icon https://cdn.icon-icons.com/icons2/1488/PNG/512/5295-youtube-i_102568.png // @version 1.1 // @license MIT // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js // @run-at document-idle // ==/UserScript== (function() { 'use strict'; var urlAtLastCheck = ""; var divTabs = null; const config = {childList: true, subtree: true}; const rootCallback = function (mutationsList, observer) { if (urlAtLastCheck != document.location.href) { urlAtLastCheck = document.location.href; openVideoTab(); } } const rootNode = document.querySelector("body"); if (rootNode != null) { const rootObserver = new MutationObserver(rootCallback); rootObserver.observe(rootNode, config); } function openVideoTab() { var pathArray = window.location.pathname.split('/'); var firstPath = pathArray[1]; var lastPath = pathArray[pathArray.length - 1]; if (firstPath === "" || firstPath === "watch" || firstPath === "playlist" || firstPath === "feed" || firstPath === "gaming" || firstPath === "live" || lastPath === "history" || lastPath === "featured" || lastPath === "videos" || lastPath === "playlists" || lastPath === "community" || lastPath === "channels" || lastPath === "about") { //If not a channel or any channel's tab was selected //console.log("Not a channel or any tab is selected"); } else { //If a channel let waitHeader = setInterval(function() { //Wait untile header loaded divTabs = $( "div#tabsContainer > div#tabsContent > tp-yt-paper-tab" ); //Get array of tabs as HTML elements if (divTabs != null && divTabs.length >= 2) { clearInterval(waitHeader); //Stop waiting for tabs //Count visible tabs var countVisible = 0; var i; var tabIndex = -1; for (i = 0; i < divTabs.length; i++) { if (isVisible(divTabs[i])) countVisible++; if (countVisible == 2) tabIndex = i; //Video tab is 2nd visible } if (countVisible > 4) { //Enough number of visible tabs - normal channel divTabs[tabIndex].click(); //console.log("Video tab (" + tabIndex + ") is activated. Visible tabs: " + countVisible); } } }, 250); //Interval to wait for header with tabs loading if (divTabs != null) divTabs = null; //console.log(" "); } } function isVisible(pObj) { //Check all the parents of element to find whether it is visible or not if (pObj != null) { var checkNext = true; var vObj = pObj; while (checkNext) { checkNext = false; //console.log("checking element " + vObj.tagName + "#" + vObj.id + ": '" + document.defaultView.getComputedStyle(vObj,null)['display'] + "'"); if (document.defaultView.getComputedStyle(vObj,null)['display'] != "none") { if (vObj.parentElement != null) { vObj = vObj.parentElement; checkNext = true; } } else { return false; } } return true; } return false; } })();