Zabránit aut. přehrávání videí na YouTube profilech

Zabránit automatickému přehrávání doporučených videí na stránkách profilů kanálů YouTube.

  1. // ==UserScript==
  2. // @name Prevent autoplayed featured videos on YouTube channel profile pages
  3. // @description Prevent autoplayed featured videos on YouTube channel profile pages.
  4. // @name:ar منع تشغيل فيديوهات مميزة تلقائيًا بصفحات قنوات يوتيوب
  5. // @description:ar منع تشغيل الفيديوهات المميزة تلقائيًا في صفحات ملفات قنوات يوتيوب.
  6. // @name:bg Предотвратяване на авт. видеа в YouTube профили
  7. // @description:bg Предотвратяване на автоматично възпроизвеждане на представени видеа на профилните страници на канали в YouTube.
  8. // @name:cs Zabránit aut. přehrávání videí na YouTube profilech
  9. // @description:cs Zabránit automatickému přehrávání doporučených videí na stránkách profilů kanálů YouTube.
  10. // @name:da Forhindr aut. afspilning på YouTube kanalprofiler
  11. // @description:da Forhindr automatisk afspilning af fremhævede videoer på YouTube-kanalprofil sider.
  12. // @name:de Verhindern von Autoplay auf YouTube-Profilseiten
  13. // @description:de Verhindern des automatischen Abspielens von vorgestellten Videos auf YouTube-Kanalprofilseiten.
  14. // @name:el Αποτροπή aut. βίντεο σε YouTube προφίλ καναλιών
  15. // @description:el Αποτροπή αυτόματης αναπαραγωγής προβεβλημένων βίντεο στις σελίδες προφίλ καναλιών YouTube.
  16. // @name:en Prevent autoplayed featured videos on YouTube profiles
  17. // @description:en Prevent autoplayed featured videos on YouTube channel profile pages.
  18. // @name:eo Malhelpi aut. ludon en YouTube kanalprofiloj
  19. // @description:eo Malhelpi aŭtomatan ludon de elstaraj filmetoj en YouTube-kanalaj profilpaĝoj.
  20. // @name:es Evitar aut. videos en perfiles de canales YouTube
  21. // @description:es Evitar la reproducción automática de videos destacados en las páginas de perfil de canales de YouTube.
  22. // @name:fi Estä aut. videoiden toisto YouTube-profiileissa
  23. // @description:fi Estä esiteltyjen videoiden automaattinen toisto YouTube-kanavien profiilisivuilla.
  24. // @name:fr Empêcher aut. vidéos sur profils YouTube
  25. // @description:fr Empêcher la lecture automatique des vidéos mises en avant sur les pages de profil des chaînes YouTube.
  26. // @name:fr-CA Empêcher aut. vidéos sur profils YouTube
  27. // @description:fr-CA Empêcher la lecture automatique des vidéos en vedette sur les pages de profil des chaînes YouTube.
  28. // @name:he מניעת השמעת סרטונים אוטו' בפרופילי YouTube
  29. // @description:he מניעת השמעה אוטומטית של סרטונים מומלצים בדפי פרופיל ערוצי YouTube.
  30. // @name:hr Sprječavanje aut. videa na YouTube profilima
  31. // @description:hr Sprječavanje automatskog reproduciranja istaknutih videa na stranicama profila YouTube kanala.
  32. // @name:hu Megakadályozza aut. videók YouTube profilokon
  33. // @description:hu Megakadályozza a kiemelt videók automatikus lejátszását a YouTube-csatorna profiloldalain.
  34. // @name:id Cegah aut. video unggulan di profil YouTube
  35. // @description:id Cegah pemutaran otomatis video unggulan di halaman profil kanal YouTube.
  36. // @name:it Impedisci aut. video su profili YouTube
  37. // @description:it Impedisci la riproduzione automatica dei video in evidenza sulle pagine dei profili dei canali YouTube.
  38. // @name:ja YouTubeチャンネルで注目の動画自動再生を防ぐ
  39. // @description:ja YouTubeチャンネルプロフィールページでの注目の動画の自動再生を防ぐ。
  40. // @name:ka YouTube-ზე ავტო დაკვრის თავიდან აცილება
  41. // @description:ka YouTube-ის არხის პროფილის გვერდებზე გამორჩეული ვიდეოების ავტომატური დაკვრის თავიდან აცილება.
  42. // @name:ko YouTube 채널 프로필에서 자동 재생 방지
  43. // @description:ko YouTube 채널 프로필 페이지에서 추천 동영상의 자동 재생 방지.
  44. // @name:nb Forhindre aut. videoer på YouTube profiler
  45. // @description:nb Forhindre automatisk avspilling av fremhevede videoer på YouTube-kanalprofil sider.
  46. // @name:nl Voorkom aut. video’s op YouTube profielen
  47. // @description:nl Voorkom automatisch afspelen van aanbevolen video’s op YouTube-kanaalprofielpagina’s.
  48. // @name:pl Zapobiegaj aut. filmom na profilach YouTube
  49. // @description:pl Zapobiegaj automatycznemu odtwarzaniu polecanych filmów na stronach profili kanałów YouTube.
  50. // @name:pt-BR Impedir aut. vídeos em perfis do YouTube
  51. // @description:pt-BR Impedir a reprodução automática de vídeos em destaque nas páginas de perfil de canais do YouTube.
  52. // @name:ro Împiedică aut. video pe profiluri YouTube
  53. // @description:ro Împiedică redarea automată a videoclipurilor recomandate pe paginile de profil ale canalelor YouTube.
  54. // @name:ru Предотвращение авт. видео на профилях YouTube
  55. // @description:ru Предотвращение автоматического воспроизведения избранных видео на страницах профилей каналов YouTube.
  56. // @name:sk Zabrániť aut. videám na profiloch YouTube
  57. // @description:sk Zabrániť automatickému prehrávaniu odporúčaných videí na stránkach profilov kanálov YouTube.
  58. // @name:sr Спречи аутоматску репродукцију на YouTube профилима
  59. // @description:sr Спречавање аутоматске репродукције истакнутих видео записа на страницама профила YouTube канала.
  60. // @name:sv Förhindra aut. videor på YouTube profiler
  61. // @description:sv Förhindra automatisk uppspelning av utvalda videor på YouTube-kanalprofil sidor.
  62. // @name:th ป้องกันวิดีโอเด่น aut. ในโปรไฟล์ YouTube
  63. // @description:th ป้องกันการเล่นอัตโนมัติของวิดีโอเด่นในหน้าประวัติช่อง YouTube
  64. // @name:tr YouTube profilinde aut. videoları engelle
  65. // @description:tr YouTube kanal profil sayfalarında öne çıkan videoların otomatik oynatılmasını engelle.
  66. // @name:ug YouTube پروفىلدىكى فىلىملارنىڭ aut. توسۇش
  67. // @description:ug YouTube قانال پروفىل بەتلىرىدىكى تەۋسىيە قىلىنغان فىلىملارنىڭ ئاپتوماتىك ئوينىلىشىنى توسۇش.
  68. // @name:uk Запобігання авт. відео на профілях YouTube
  69. // @description:uk Запобігання автоматичному відтворенню рекомендованих відео на сторінках профілів каналів YouTube.
  70. // @name:vi Ngăn aut. video trên hồ sơ kênh YouTube
  71. // @description:vi Ngăn chặn phát tự động các video nổi bật trên trang hồ sơ kênh YouTube.
  72. // @name:zh 防止YouTube频道页面特色视频自动播放
  73. // @description:zh 防止YouTube频道简介页面上的特色视频自动播放。
  74. // @name:zh-CN 防止YouTube频道页面特色视频自动播放
  75. // @description:zh-CN 防止YouTube频道简介页面上的特色视频自动播放。
  76. // @name:zh-HK 防止YouTube頻道頁面特色影片自動播放
  77. // @description:zh-HK 防止YouTube頻道簡介頁面上的特色影片自動播放。
  78. // @name:zh-SG 防止YouTube频道页面特色视频自动播放
  79. // @description:zh-SG 防止YouTube频道简介页面上的特色视频自动播放。
  80. // @name:zh-TW 防止YouTube頻道頁面精選影片自動播放
  81. // @description:zh-TW 防止YouTube頻道簡介頁面上的精選影片自動播放。
  82. // @namespace http://tampermonkey.net/
  83. // @icon https://cdn-icons-png.flaticon.com/64/2504/2504965.png
  84. // @version 1.3.2
  85. // @author aspen138
  86. // @match https://www.youtube.com/@*/featured
  87. // @match https://www.youtube.com/@*
  88. // @match https://www.youtube.com/*
  89. // @exclude https://www.youtube.com/watch?v=*
  90. // @license MIT
  91. // @grant GM_registerMenuCommand
  92. // @grant GM_unregisterMenuCommand
  93. // @grant GM_setValue
  94. // @grant GM_getValue
  95. // @grant GM_notification
  96. // @grant GM_info
  97. // @grant window.onurlchange
  98. // ==/UserScript==
  99.  
  100.  
  101.  
  102. // ↓↓↓↓↓↓↓↓↓模板,建议直接复制 //
  103.  
  104. // 自定义 urlchange 事件(用来监听 URL 变化)
  105. function addUrlChangeEvent() {
  106. history.pushState = ( f => function pushState(){
  107. var ret = f.apply(this, arguments);
  108. window.dispatchEvent(new Event('pushstate'));
  109. window.dispatchEvent(new Event('urlchange'));
  110. return ret;
  111. })(history.pushState);
  112.  
  113. history.replaceState = ( f => function replaceState(){
  114. var ret = f.apply(this, arguments);
  115. window.dispatchEvent(new Event('replacestate'));
  116. window.dispatchEvent(new Event('urlchange'));
  117. return ret;
  118. })(history.replaceState);
  119.  
  120. window.addEventListener('popstate',()=>{
  121. window.dispatchEvent(new Event('urlchange'))
  122. });
  123. }
  124.  
  125.  
  126. var menu_ALL = [
  127. ['menu_isEnableHighlightChannelSubscriberNumber', '高亮频道订阅数', '高亮频道订阅数', false]
  128. ], menu_ID = [];
  129. for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
  130. if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
  131. }
  132.  
  133.  
  134. // 注册脚本菜单
  135. function registerMenuCommand() {
  136. if (menu_ID.length >= menu_ALL.length){ // 如果菜单ID数组长度大于等于菜单数组长度,说明不是首次添加菜单,需要卸载所有脚本菜单
  137. for (let i=0;i<menu_ID.length;i++){
  138. GM_unregisterMenuCommand(menu_ID[i]);
  139. }
  140. }
  141. for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
  142. menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
  143. menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][3]?'✅':'❌'} ${menu_ALL[i][1]}`, function(){menu_switch(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`,`${menu_ALL[i][2]}`)});
  144. }
  145. }
  146.  
  147.  
  148. // 菜单开关
  149. function menu_switch(menu_status, Name, Tips) {
  150. if (menu_status == 'true'){
  151. GM_setValue(`${Name}`, false);
  152. GM_notification({text: `已关闭 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
  153. }else{
  154. GM_setValue(`${Name}`, true);
  155. GM_notification({text: `已开启 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
  156. }
  157. registerMenuCommand(); // 重新注册脚本菜单
  158. };
  159.  
  160.  
  161. // 返回菜单值
  162. function menu_value(menuName) {
  163. for (let menu of menu_ALL) {
  164. if (menu[0] == menuName) {
  165. return menu[3]
  166. }
  167. }
  168. }
  169.  
  170. for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
  171. if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
  172. }
  173. registerMenuCommand();
  174. if (window.onurlchange === undefined) {addUrlChangeEvent();} // Tampermonkey v4.11 版本添加的 onurlchange 事件 grant,可以监控 pjax 等网页的 URL 变化
  175.  
  176. // ↑↑↑↑↑↑↑↑↑↑↑↑模板,建议直接复制 //
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. (function() {
  184. 'use strict';
  185. // Function to pause the video
  186. function pauseVideo() {
  187. const video = document.querySelector('video');
  188. if (video && !video.paused) {
  189. video.pause();
  190. //console.log('YouTube autoplay video paused.');
  191. }
  192. }
  193.  
  194. // Function to bold and highlight the specified element and its children
  195. function highlightElement() {
  196. if(!( GM_getValue('menu_isEnableHighlightChannelSubscriberNumber', false) ) ) return;
  197.  
  198.  
  199. const element = document.querySelector('.page-header-view-model-wiz__page-header-content-metadata');
  200. if (element) {
  201. element.style.backgroundColor = 'yellow'; // Highlight with yellow background
  202.  
  203. // Bold and mimic the style for each child
  204. Array.from(element.children).forEach(child => {
  205. child.style.fontWeight = 'bold'; // Make each child bold
  206. child.style.color = 'red'; // Set font color to red
  207. child.style.textDecoration = 'none'; // Remove any text decoration if needed
  208. });
  209.  
  210. // Also, bold and mimic styles for any spans inside the children
  211. const spans = element.querySelectorAll('span');
  212. spans.forEach(span => {
  213. span.style.fontWeight = 'bold';
  214. span.style.color = 'red'; // Set font color to red
  215. span.style.textDecoration = 'none'; // Remove any text decoration
  216. });
  217.  
  218. //console.log('Element and its children highlighted and bolded with red font color.');
  219. }
  220. }
  221.  
  222. // Create a MutationObserver to monitor for video elements
  223. const observer = new MutationObserver((mutations) => {
  224. pauseVideo();
  225. highlightElement();
  226. });
  227.  
  228. // Start observing the document body for changes
  229. observer.observe(document.body, { childList: true, subtree: true });
  230.  
  231. // Attempt to pause the video and highlight the element immediately in case they're already there
  232. pauseVideo();
  233. highlightElement();
  234.  
  235. // Counter for setInterval executions
  236. let executionCount = 0;
  237.  
  238. // Use setInterval to repeatedly check for the element and apply styles
  239. const intervalId = setInterval(() => {
  240. highlightElement();
  241. executionCount++;
  242.  
  243. // Clear the interval after two executions
  244. if (executionCount >= 2) {
  245. clearInterval(intervalId);
  246. }
  247. }, 1000); // Check every 1000 milliseconds (1 second)
  248. })();