要使用這個代碼,需要安裝暴力猴插件(Tampermonkey,也叫篡改猴)
Chrome插件位置:
個人使用YT主要都是搜索資料,不是要看那些沒資料的短內容,那類內容不適合我,出現在版面上,需要很多次不必要的下拉。只有浪費時間,減低作業效率。
我不反對讓short給適合的觀眾看,確實有很大一批觀眾喜歡看,只是對於不喜歡的,沒需要的,Youtube卻沒法隱藏,就借助GPT弄一下簡單的代碼。(Chrome的暴力猴插件使用中)
主要功用是在YT主頁和搜索結果,不再出現Short,但是,右上通知欄還是會出現short通知(如果有支持的Youtuber更新short還是會關註支持一下),那部分屬於通知,不在程式碼處理範圍。主要只是希望在處理資訊時,減少short的干擾。
暴力猴代碼(分割線後)
// ==UserScript==
// @name YouTube Shorts Blocker
// @namespace http://tampermonkey.net/
// @version 1.2
// @description 隱藏 YouTube Shorts,並阻止跳轉到 shorts 頁面
// @author GPT
// @match *://www.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 若是 shorts 頁面,跳轉回首頁
if (window.location.pathname.startsWith('/shorts')) {
window.location.href = 'https://www.youtube.com/';
}
// 動態觀察 YouTube 頁面變化
const observer = new MutationObserver(() => {
removeShorts();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// 隱藏所有 shorts
function removeShorts() {
const shorts = document.querySelectorAll('ytd-rich-grid-media[is-shorts], ytd-reel-shelf-renderer, a[href^="/shorts"]');
shorts.forEach(el => el.style.display = 'none');
// 可選:刪除搜尋結果中的 shorts 分類
const tabs = document.querySelectorAll('a[title="Shorts"], ytd-guide-entry-renderer a[href^="/shorts"]');
tabs.forEach(el => el.style.display = 'none');
}
})();