防止YouTube频道简介页面上的特色视频自动播放。
// ==UserScript==
// @name Prevent autoplayed featured videos on YouTube channel profile pages
// @description Prevent autoplayed featured videos on YouTube channel profile pages.
// @name:ar منع تشغيل فيديوهات مميزة تلقائيًا بصفحات قنوات يوتيوب
// @description:ar منع تشغيل الفيديوهات المميزة تلقائيًا في صفحات ملفات قنوات يوتيوب.
// @name:bg Предотвратяване на авт. видеа в YouTube профили
// @description:bg Предотвратяване на автоматично възпроизвеждане на представени видеа на профилните страници на канали в YouTube.
// @name:cs Zabránit aut. přehrávání videí na YouTube profilech
// @description:cs Zabránit automatickému přehrávání doporučených videí na stránkách profilů kanálů YouTube.
// @name:da Forhindr aut. afspilning på YouTube kanalprofiler
// @description:da Forhindr automatisk afspilning af fremhævede videoer på YouTube-kanalprofil sider.
// @name:de Verhindern von Autoplay auf YouTube-Profilseiten
// @description:de Verhindern des automatischen Abspielens von vorgestellten Videos auf YouTube-Kanalprofilseiten.
// @name:el Αποτροπή aut. βίντεο σε YouTube προφίλ καναλιών
// @description:el Αποτροπή αυτόματης αναπαραγωγής προβεβλημένων βίντεο στις σελίδες προφίλ καναλιών YouTube.
// @name:en Prevent autoplayed featured videos on YouTube profiles
// @description:en Prevent autoplayed featured videos on YouTube channel profile pages.
// @name:eo Malhelpi aut. ludon en YouTube kanalprofiloj
// @description:eo Malhelpi aŭtomatan ludon de elstaraj filmetoj en YouTube-kanalaj profilpaĝoj.
// @name:es Evitar aut. videos en perfiles de canales YouTube
// @description:es Evitar la reproducción automática de videos destacados en las páginas de perfil de canales de YouTube.
// @name:fi Estä aut. videoiden toisto YouTube-profiileissa
// @description:fi Estä esiteltyjen videoiden automaattinen toisto YouTube-kanavien profiilisivuilla.
// @name:fr Empêcher aut. vidéos sur profils YouTube
// @description:fr Empêcher la lecture automatique des vidéos mises en avant sur les pages de profil des chaînes YouTube.
// @name:fr-CA Empêcher aut. vidéos sur profils YouTube
// @description:fr-CA Empêcher la lecture automatique des vidéos en vedette sur les pages de profil des chaînes YouTube.
// @name:he מניעת השמעת סרטונים אוטו' בפרופילי YouTube
// @description:he מניעת השמעה אוטומטית של סרטונים מומלצים בדפי פרופיל ערוצי YouTube.
// @name:hr Sprječavanje aut. videa na YouTube profilima
// @description:hr Sprječavanje automatskog reproduciranja istaknutih videa na stranicama profila YouTube kanala.
// @name:hu Megakadályozza aut. videók YouTube profilokon
// @description:hu Megakadályozza a kiemelt videók automatikus lejátszását a YouTube-csatorna profiloldalain.
// @name:id Cegah aut. video unggulan di profil YouTube
// @description:id Cegah pemutaran otomatis video unggulan di halaman profil kanal YouTube.
// @name:it Impedisci aut. video su profili YouTube
// @description:it Impedisci la riproduzione automatica dei video in evidenza sulle pagine dei profili dei canali YouTube.
// @name:ja YouTubeチャンネルで注目の動画自動再生を防ぐ
// @description:ja YouTubeチャンネルプロフィールページでの注目の動画の自動再生を防ぐ。
// @name:ka YouTube-ზე ავტო დაკვრის თავიდან აცილება
// @description:ka YouTube-ის არხის პროფილის გვერდებზე გამორჩეული ვიდეოების ავტომატური დაკვრის თავიდან აცილება.
// @name:ko YouTube 채널 프로필에서 자동 재생 방지
// @description:ko YouTube 채널 프로필 페이지에서 추천 동영상의 자동 재생 방지.
// @name:nb Forhindre aut. videoer på YouTube profiler
// @description:nb Forhindre automatisk avspilling av fremhevede videoer på YouTube-kanalprofil sider.
// @name:nl Voorkom aut. video’s op YouTube profielen
// @description:nl Voorkom automatisch afspelen van aanbevolen video’s op YouTube-kanaalprofielpagina’s.
// @name:pl Zapobiegaj aut. filmom na profilach YouTube
// @description:pl Zapobiegaj automatycznemu odtwarzaniu polecanych filmów na stronach profili kanałów YouTube.
// @name:pt-BR Impedir aut. vídeos em perfis do YouTube
// @description:pt-BR Impedir a reprodução automática de vídeos em destaque nas páginas de perfil de canais do YouTube.
// @name:ro Împiedică aut. video pe profiluri YouTube
// @description:ro Împiedică redarea automată a videoclipurilor recomandate pe paginile de profil ale canalelor YouTube.
// @name:ru Предотвращение авт. видео на профилях YouTube
// @description:ru Предотвращение автоматического воспроизведения избранных видео на страницах профилей каналов YouTube.
// @name:sk Zabrániť aut. videám na profiloch YouTube
// @description:sk Zabrániť automatickému prehrávaniu odporúčaných videí na stránkach profilov kanálov YouTube.
// @name:sr Спречи аутоматску репродукцију на YouTube профилима
// @description:sr Спречавање аутоматске репродукције истакнутих видео записа на страницама профила YouTube канала.
// @name:sv Förhindra aut. videor på YouTube profiler
// @description:sv Förhindra automatisk uppspelning av utvalda videor på YouTube-kanalprofil sidor.
// @name:th ป้องกันวิดีโอเด่น aut. ในโปรไฟล์ YouTube
// @description:th ป้องกันการเล่นอัตโนมัติของวิดีโอเด่นในหน้าประวัติช่อง YouTube
// @name:tr YouTube profilinde aut. videoları engelle
// @description:tr YouTube kanal profil sayfalarında öne çıkan videoların otomatik oynatılmasını engelle.
// @name:ug YouTube پروفىلدىكى فىلىملارنىڭ aut. توسۇش
// @description:ug YouTube قانال پروفىل بەتلىرىدىكى تەۋسىيە قىلىنغان فىلىملارنىڭ ئاپتوماتىك ئوينىلىشىنى توسۇش.
// @name:uk Запобігання авт. відео на профілях YouTube
// @description:uk Запобігання автоматичному відтворенню рекомендованих відео на сторінках профілів каналів YouTube.
// @name:vi Ngăn aut. video trên hồ sơ kênh YouTube
// @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.
// @name:zh 防止YouTube频道页面特色视频自动播放
// @description:zh 防止YouTube频道简介页面上的特色视频自动播放。
// @name:zh-CN 防止YouTube频道页面特色视频自动播放
// @description:zh-CN 防止YouTube频道简介页面上的特色视频自动播放。
// @name:zh-HK 防止YouTube頻道頁面特色影片自動播放
// @description:zh-HK 防止YouTube頻道簡介頁面上的特色影片自動播放。
// @name:zh-SG 防止YouTube频道页面特色视频自动播放
// @description:zh-SG 防止YouTube频道简介页面上的特色视频自动播放。
// @name:zh-TW 防止YouTube頻道頁面精選影片自動播放
// @description:zh-TW 防止YouTube頻道簡介頁面上的精選影片自動播放。
// @namespace http://tampermonkey.net/
// @icon https://cdn-icons-png.flaticon.com/64/2504/2504965.png
// @version 1.3.2
// @author aspen138
// @match https://www.youtube.com/@*/featured
// @match https://www.youtube.com/@*
// @match https://www.youtube.com/*
// @exclude https://www.youtube.com/watch?v=*
// @license MIT
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_notification
// @grant GM_info
// @grant window.onurlchange
// ==/UserScript==
// ↓↓↓↓↓↓↓↓↓模板,建议直接复制 //
// 自定义 urlchange 事件(用来监听 URL 变化)
function addUrlChangeEvent() {
history.pushState = ( f => function pushState(){
var ret = f.apply(this, arguments);
window.dispatchEvent(new Event('pushstate'));
window.dispatchEvent(new Event('urlchange'));
return ret;
})(history.pushState);
history.replaceState = ( f => function replaceState(){
var ret = f.apply(this, arguments);
window.dispatchEvent(new Event('replacestate'));
window.dispatchEvent(new Event('urlchange'));
return ret;
})(history.replaceState);
window.addEventListener('popstate',()=>{
window.dispatchEvent(new Event('urlchange'))
});
}
var menu_ALL = [
['menu_isEnableHighlightChannelSubscriberNumber', '高亮频道订阅数', '高亮频道订阅数', false]
], menu_ID = [];
for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
}
// 注册脚本菜单
function registerMenuCommand() {
if (menu_ID.length >= menu_ALL.length){ // 如果菜单ID数组长度大于等于菜单数组长度,说明不是首次添加菜单,需要卸载所有脚本菜单
for (let i=0;i<menu_ID.length;i++){
GM_unregisterMenuCommand(menu_ID[i]);
}
}
for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
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]}`)});
}
}
// 菜单开关
function menu_switch(menu_status, Name, Tips) {
if (menu_status == 'true'){
GM_setValue(`${Name}`, false);
GM_notification({text: `已关闭 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
}else{
GM_setValue(`${Name}`, true);
GM_notification({text: `已开启 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
}
registerMenuCommand(); // 重新注册脚本菜单
};
// 返回菜单值
function menu_value(menuName) {
for (let menu of menu_ALL) {
if (menu[0] == menuName) {
return menu[3]
}
}
}
for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
}
registerMenuCommand();
if (window.onurlchange === undefined) {addUrlChangeEvent();} // Tampermonkey v4.11 版本添加的 onurlchange 事件 grant,可以监控 pjax 等网页的 URL 变化
// ↑↑↑↑↑↑↑↑↑↑↑↑模板,建议直接复制 //
(function() {
'use strict';
// Function to pause the video
function pauseVideo() {
const video = document.querySelector('video');
if (video && !video.paused) {
video.pause();
//console.log('YouTube autoplay video paused.');
}
}
// Function to bold and highlight the specified element and its children
function highlightElement() {
if(!( GM_getValue('menu_isEnableHighlightChannelSubscriberNumber', false) ) ) return;
const element = document.querySelector('.page-header-view-model-wiz__page-header-content-metadata');
if (element) {
element.style.backgroundColor = 'yellow'; // Highlight with yellow background
// Bold and mimic the style for each child
Array.from(element.children).forEach(child => {
child.style.fontWeight = 'bold'; // Make each child bold
child.style.color = 'red'; // Set font color to red
child.style.textDecoration = 'none'; // Remove any text decoration if needed
});
// Also, bold and mimic styles for any spans inside the children
const spans = element.querySelectorAll('span');
spans.forEach(span => {
span.style.fontWeight = 'bold';
span.style.color = 'red'; // Set font color to red
span.style.textDecoration = 'none'; // Remove any text decoration
});
//console.log('Element and its children highlighted and bolded with red font color.');
}
}
// Create a MutationObserver to monitor for video elements
const observer = new MutationObserver((mutations) => {
pauseVideo();
highlightElement();
});
// Start observing the document body for changes
observer.observe(document.body, { childList: true, subtree: true });
// Attempt to pause the video and highlight the element immediately in case they're already there
pauseVideo();
highlightElement();
// Counter for setInterval executions
let executionCount = 0;
// Use setInterval to repeatedly check for the element and apply styles
const intervalId = setInterval(() => {
highlightElement();
executionCount++;
// Clear the interval after two executions
if (executionCount >= 2) {
clearInterval(intervalId);
}
}, 1000); // Check every 1000 milliseconds (1 second)
})();