Greasy Fork

Greasy Fork is available in English.

Youtube-PC-新标签页打开

Youtube新标签页打开.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Youtube-PC-新标签页打开
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Youtube新标签页打开.
// @author       zyronon
// @license      GPL License
// @match        https://www.youtube.com/*
// @homepage     https://github.com/zyronon/web-scripts
// @homepageURL  https://github.com/zyronon/web-scripts
// @icon         https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @license MIT
// @grant        GM_openInTab
// @run-at       document-start

// ==/UserScript==

(function () {
  'use strict';

  let pageType = {
    value: 'home'
  }

  function stop(e) {
    e.preventDefault()
    e.stopPropagation()
    e.stopImmediatePropagation()
    return true
  }

//打开新标签页
  function openNewTab(href, active = false) {
    GM_openInTab(href, {active});
  }

  function checkPageType() {
    if (location.pathname === '/watch') {
      pageType.value = 'watch'
    }
    if (location.pathname === '/') {
      pageType.value = 'home'
    }
    if (location.pathname.startsWith('/@')) {
      pageType.value = 'user'
    }
  }

  function checkIsWatchPage() {
    checkPageType()
    return pageType.value === 'watch'
  }

  function findA(target, e) {
    let parentNode = target
    let count = 0
    while (parentNode.tagName !== 'A' && count < 10) {
      count++
      parentNode = parentNode.parentNode
    }
    console.log(parentNode)
    openNewTab(parentNode.href, true)
    return stop(e)
  }

  function checkA(e) {
    let target = e.target;
    let tagName = target.tagName;
    let classList = target.classList
    console.log('e', e, target, tagName, classList,)
    if (tagName === 'YTD-THUMBNAIL-OVERLAY-HOVER-TEXT-RENDERER') {
      console.log('合辑')
      if (checkIsWatchPage()) return
      return findA(target, e)
    }

    if (tagName === 'SPAN' && Array.from(classList).some(v => v.includes('ytd-thumbnail-overlay-hover-text-renderer'))) {
      console.log('合辑-全部播放',)
      if (checkIsWatchPage()) return
      return findA(target, e)
    }
    if (tagName === 'SPAN' && Array.from(classList).some(v => v.includes('yt-formatted-string'))) {
      console.log('描述',)
      if (checkIsWatchPage()) return
      return findA(target, e)
    }

    if (tagName === 'YT-FORMATTED-STRING' && Array.from(classList).some(v =>
      (
        v.includes('ytd-rich-grid-media') ||
        v.includes('ytd-video-renderer')
      )
    )) {
      console.log('标题',)
      if (checkIsWatchPage()) return
      return findA(target, e)
    }

    if (tagName === 'IMG' && Array.from(classList).some(v =>
      (
        v.includes('yt-core-imag') ||
        v.includes('ytd-moving-thumbnail-renderer')
      )
    )) {
      console.log('封面')
      if (checkIsWatchPage()) return
      return findA(target, e)
    }
    if (tagName === 'DIV') {
      if (Array.from(classList).some(v =>
        (
          v.includes('ytd-thumbnail-overlay-toggle-button-renderer') ||
          v.includes('ytd-video-preview') ||
          v.includes('ytp-inline-preview-scrim')
        )
      )) {
        console.log('封面')
        if (checkIsWatchPage()) return
        return findA(target, e)
      }
    }

    if (tagName === 'A' && target.href.includes('/@')) {
      console.log('作者')
      if (checkIsWatchPage()) return
      return findA(target, e)
    }

    // return stop(e)
  }

  window.addEventListener('click', checkA, true);
  let fs = localStorage.getItem('fs')
  if (fs) {
    document.documentElement.style.fontSize = fs + 'px'
  }
})();