@khabzox/ytb-shorts-blocker
Version:
Block YouTube Shorts and keep your feed clean
2 lines (1 loc) • 3.31 kB
JavaScript
var Q={enabled:!0,blockingMode:"hide",showNotifications:!0,blockInSearch:!0,blockInHome:!0,blockInSubscriptions:!0,blockInTrending:!1,allowWhitelistedChannels:!0,debugMode:!1},q={settings:{...Q},isActive:!1,observer:null},$=(j)=>{q.settings={...Q,...j}},W=()=>{if(!q.settings.enabled)return;if(typeof window==="undefined"||typeof document==="undefined"){console.warn("YouTube Shorts Blocker: Not in browser environment");return}C(),Y(),q.isActive=!0,console.log("YouTube Shorts Blocker initialized")},G=(j)=>{if(q.settings.enabled=j,j&&!q.isActive)W();else if(!j&&q.isActive)H()},R=(j)=>{q.settings.blockingMode=j},_=()=>{if(typeof document==="undefined")return;Y()},p=()=>{return{...q.settings}},v=(j)=>{q.settings={...q.settings,...j}},x=()=>{return{...q}},z=()=>{if(typeof document==="undefined")return[];let j=["ytd-rich-grid-media[is-shorts]","ytd-rich-item-renderer[is-shorts]","ytd-video-renderer[is-shorts]",'a[href*="/shorts/"]',"[data-shorts-selector]"],y=[];return j.forEach((J)=>{document.querySelectorAll(J).forEach((P)=>y.push(P))}),y},X=(j,y)=>{switch(y){case"hide":j.style.display="none";break;case"remove":j.remove();break;case"redirect":j.style.opacity="0.5",j.style.pointerEvents="none";break}},A=()=>{if(typeof window==="undefined")return!1;return window.location.hostname.includes("youtube.com")},B=()=>{if(typeof window==="undefined")return!1;return window.location.pathname.includes("/shorts/")},D=()=>{if(typeof window==="undefined")return!1;return window.location.pathname==="/"||window.location.pathname==="/feed/subscriptions"},L=()=>{if(typeof window==="undefined")return!1;return window.location.pathname==="/results"},O=()=>{if(typeof window==="undefined")return!1;return window.location.pathname==="/feed/subscriptions"},U=()=>{if(typeof window==="undefined")return!1;return window.location.pathname==="/trending"},C=()=>{if(!document.body)return;let j=new MutationObserver((y)=>{y.forEach((J)=>{if(J.type==="childList")J.addedNodes.forEach((K)=>{if(K.nodeType===Node.ELEMENT_NODE)K.querySelectorAll("ytd-rich-grid-media[is-shorts], ytd-rich-item-renderer[is-shorts]").forEach((Z)=>{X(Z,q.settings.blockingMode)})})})});j.observe(document.body,{childList:!0,subtree:!0}),q.observer=j},Y=()=>{let j=z();if(j.forEach((y)=>{X(y,q.settings.blockingMode)}),q.settings.debugMode)console.log(`Blocked ${j.length} shorts elements`)},H=()=>{if(q.observer)q.observer.disconnect(),q.observer=null;q.isActive=!1},I={SHORTS:"[data-shorts-selector]",SHORTS_GRID:"[data-shorts-grid]",SHORTS_ITEM:"[data-shorts-item]"},N={HIDE:"hide",REMOVE:"remove",REDIRECT:"redirect"},M="1.0.4",V="khabzox",f="MIT",h={name:"YouTube Shorts Blocker",version:M,description:"Block YouTube Shorts and keep your feed clean",author:V,license:f,repository:"https://github.com/khabzox/ytb-shorts-blocker",homepage:"https://github.com/khabzox/ytb-shorts-blocker#readme"};function w(j){$(j),W()}export{v as updateSettings,G as setEnabled,R as setBlockingMode,A as isYouTubePage,U as isTrendingPage,O as isSubscriptionsPage,B as isShortsPage,L as isSearchPage,D as isHomePage,W as initBlocker,x as getState,p as getSettings,z as detectShorts,w as default,$ as createBlocker,_ as blockShorts,X as blockElement,M as VERSION,I as SELECTORS,f as LICENSE,h as EXTENSION_INFO,Q as DEFAULT_SETTINGS,N as BLOCKING_MODES,V as AUTHOR};