Youtube-PC-新标签页打开

Youtube新标签页打开.

  1. // ==UserScript==
  2. // @name Youtube-PC-新标签页打开
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Youtube新标签页打开.
  6. // @author zyronon
  7. // @license GPL License
  8. // @match https://www.youtube.com/*
  9. // @homepage https://github.com/zyronon/web-scripts
  10. // @homepageURL https://github.com/zyronon/web-scripts
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=gf.qytechs.cn
  12. // @require https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js
  13. // @license MIT
  14. // @grant GM_openInTab
  15. // @run-at document-start
  16.  
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. 'use strict';
  21.  
  22. let pageType = {
  23. value: 'home'
  24. }
  25.  
  26. function stop(e) {
  27. e.preventDefault()
  28. e.stopPropagation()
  29. e.stopImmediatePropagation()
  30. return true
  31. }
  32.  
  33. //打开新标签页
  34. function openNewTab(href, active = false) {
  35. GM_openInTab(href, {active});
  36. }
  37.  
  38. function checkPageType() {
  39. if (location.pathname === '/watch') {
  40. pageType.value = 'watch'
  41. }
  42. if (location.pathname === '/') {
  43. pageType.value = 'home'
  44. }
  45. if (location.pathname.startsWith('/@')) {
  46. pageType.value = 'user'
  47. }
  48. }
  49.  
  50. function checkIsWatchPage() {
  51. checkPageType()
  52. return pageType.value === 'watch'
  53. }
  54.  
  55. function findA(target, e) {
  56. let parentNode = target
  57. let count = 0
  58. while (parentNode.tagName !== 'A' && count < 10) {
  59. count++
  60. parentNode = parentNode.parentNode
  61. }
  62. console.log(parentNode)
  63. openNewTab(parentNode.href, true)
  64. return stop(e)
  65. }
  66.  
  67. function checkA(e) {
  68. let target = e.target;
  69. let tagName = target.tagName;
  70. let classList = target.classList
  71. console.log('e', e, target, tagName, classList,)
  72. if (tagName === 'YTD-THUMBNAIL-OVERLAY-HOVER-TEXT-RENDERER') {
  73. console.log('合辑')
  74. if (checkIsWatchPage()) return
  75. return findA(target, e)
  76. }
  77.  
  78. if (tagName === 'SPAN' && Array.from(classList).some(v => v.includes('ytd-thumbnail-overlay-hover-text-renderer'))) {
  79. console.log('合辑-全部播放',)
  80. if (checkIsWatchPage()) return
  81. return findA(target, e)
  82. }
  83. if (tagName === 'SPAN' && Array.from(classList).some(v => v.includes('yt-formatted-string'))) {
  84. console.log('描述',)
  85. if (checkIsWatchPage()) return
  86. return findA(target, e)
  87. }
  88.  
  89. if (tagName === 'YT-FORMATTED-STRING' && Array.from(classList).some(v =>
  90. (
  91. v.includes('ytd-rich-grid-media') ||
  92. v.includes('ytd-video-renderer')
  93. )
  94. )) {
  95. console.log('标题',)
  96. if (checkIsWatchPage()) return
  97. return findA(target, e)
  98. }
  99.  
  100. if (tagName === 'IMG' && Array.from(classList).some(v =>
  101. (
  102. v.includes('yt-core-imag') ||
  103. v.includes('ytd-moving-thumbnail-renderer')
  104. )
  105. )) {
  106. console.log('封面')
  107. if (checkIsWatchPage()) return
  108. return findA(target, e)
  109. }
  110. if (tagName === 'DIV') {
  111. if (Array.from(classList).some(v =>
  112. (
  113. v.includes('ytd-thumbnail-overlay-toggle-button-renderer') ||
  114. v.includes('ytd-video-preview') ||
  115. v.includes('ytp-inline-preview-scrim')
  116. )
  117. )) {
  118. console.log('封面')
  119. if (checkIsWatchPage()) return
  120. return findA(target, e)
  121. }
  122. }
  123.  
  124. if (tagName === 'A' && target.href.includes('/@')) {
  125. console.log('作者')
  126. if (checkIsWatchPage()) return
  127. return findA(target, e)
  128. }
  129.  
  130. // return stop(e)
  131. }
  132.  
  133. window.addEventListener('click', checkA, true);
  134. let fs = localStorage.getItem('fs')
  135. if (fs) {
  136. document.documentElement.style.fontSize = fs + 'px'
  137. }
  138. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址