UNPKG

@khabzox/ytb-shorts-blocker

Version:

Block YouTube Shorts and keep your feed clean

80 lines (79 loc) 7.97 kB
var k={HIDE:"hide",REMOVE:"remove",REDIRECT:"redirect"},$={enabled:!0,blockingMode:k.HIDE,showNotifications:!0,blockInSearch:!0,blockInHome:!0,blockInSubscriptions:!0,blockInTrending:!1,allowWhitelistedChannels:!0,whitelistedChannels:[],customCss:"",debugMode:!1,version:"1.0.4"},j={SETTINGS:"ytb_settings",STATS:"ytb_stats",CHANNEL_INFO:"ytb_channel_info",TEMP_DATA:"ytb_temp_data"};var z={BLOCKED:"ytb-blocked",HIDDEN:"ytb-hidden",REMOVED:"ytb-removed",DEBUG_HIGHLIGHT:"ytb-debug-highlight",DEBUG_OVERLAY:"ytb-debug-overlay",NOTIFICATION:"ytb-notification",POPUP_CONTAINER:"ytb-popup",STATS_DISPLAY:"ytb-stats",DISABLED:"ytb-disabled",LOADING:"ytb-loading",ERROR:"ytb-error"},K={HIDE_WITH_FADE:` .${z.BLOCKED} { opacity: 0 !important; transition: opacity 0.3s ease-out !important; pointer-events: none !important; } `,BLUR_EFFECT:` .${z.BLOCKED} { filter: blur(10px) !important; opacity: 0.3 !important; transition: all 0.3s ease-out !important; } `,GRAYSCALE_EFFECT:` .${z.BLOCKED} { filter: grayscale(100%) !important; opacity: 0.5 !important; position: relative !important; } .${z.BLOCKED}::after { content: "\uD83D\uDEAB BLOCKED SHORTS" !important; position: absolute !important; top: 50% !important; left: 50% !important; transform: translate(-50%, -50%) !important; background: rgba(0, 0, 0, 0.8) !important; color: white !important; padding: 8px 12px !important; border-radius: 4px !important; font-size: 12px !important; font-weight: bold !important; z-index: 1000 !important; } `,SLIDE_OUT_EFFECT:` .${z.BLOCKED} { transform: translateX(-100%) !important; transition: transform 0.5s ease-in-out !important; opacity: 0 !important; } `};async function b(){try{let q=await chrome.storage.sync.get(j.SETTINGS);return{...$,...q[j.SETTINGS]}}catch(q){return console.error("Failed to get settings:",q),$}}async function F(q){try{let Q={...await b(),...q};await chrome.storage.sync.set({[j.SETTINGS]:Q}),console.log("Settings saved successfully:",Q)}catch(H){throw console.error("Failed to save settings:",H),H}}async function V(){try{let q=await chrome.storage.local.get(j.STATS);return{...{totalBlocked:0,sessionBlocked:0,lastResetDate:new Date().toISOString(),dailyStats:{},weeklyStats:{},monthlyStats:{}},...q[j.STATS]}}catch(q){return console.error("Failed to get stats:",q),{totalBlocked:0,sessionBlocked:0,lastResetDate:new Date().toISOString(),dailyStats:{},weeklyStats:{},monthlyStats:{}}}}function Z(){return{toggleSwitch:document.getElementById("toggle-extension"),blockingModeSelect:document.getElementById("blocking-mode"),notificationsToggle:document.getElementById("notifications"),blockInHomeToggle:document.getElementById("block-in-home"),blockInSearchToggle:document.getElementById("block-in-search"),blockInSubscriptionsToggle:document.getElementById("block-in-subscriptions"),blockInTrendingToggle:document.getElementById("block-in-trending"),whitelistToggle:document.getElementById("whitelist-channels"),debugToggle:document.getElementById("debug-mode"),statsDisplay:document.getElementById("stats-display"),statusIndicator:document.getElementById("status-indicator"),saveButton:document.getElementById("save-settings"),resetButton:document.getElementById("reset-settings")}}var J={settings:$,stats:null,isLoading:!0,error:null};function X(q){J={...J,...q},M()}function M(){let q=Z();if(J.isLoading){C();return}if(J.error){L(J.error);return}q.toggleSwitch.checked=J.settings.enabled,q.blockingModeSelect.value=J.settings.blockingMode,q.notificationsToggle.checked=J.settings.showNotifications,q.blockInHomeToggle.checked=J.settings.blockInHome,q.blockInSearchToggle.checked=J.settings.blockInSearch,q.blockInSubscriptionsToggle.checked=J.settings.blockInSubscriptions,q.blockInTrendingToggle.checked=J.settings.blockInTrending,q.whitelistToggle.checked=J.settings.allowWhitelistedChannels,q.debugToggle.checked=J.settings.debugMode,U(),f(),D(),N()}function U(){let H=Z().toggleSwitch,Q=H.parentElement?.querySelector(".toggle-switch"),x=H.parentElement?.querySelector(".toggle-slider");if(Q&&x)if(H.checked)Q.classList.remove("bg-gray-300"),Q.classList.add("bg-primary-600"),x.classList.add("translate-x-5");else Q.classList.remove("bg-primary-600"),Q.classList.add("bg-gray-300"),x.classList.remove("translate-x-5")}function C(){let q=Z();q.statusIndicator.innerHTML=` <div class="flex items-center space-x-2 text-yellow-300"> <div class="animate-spin rounded-full h-4 w-4 border-2 border-yellow-300 border-t-transparent"></div> <span>Loading...</span> </div> `}function L(q){let H=Z();H.statusIndicator.innerHTML=` <div class="flex items-center space-x-2 text-red-300"> <span>⚠️</span> <span>Error: ${q}</span> </div> `}function N(){}function f(){let q=Z(),H=J.settings.enabled;q.statusIndicator.innerHTML=` <div class="flex items-center space-x-2"> <span class="text-lg">${H?"✅":"❌"}</span> <span class="text-sm font-medium"> ${H?"Extension Enabled":"Extension Disabled"} </span> </div> `}function D(){let q=Z();if(!J.stats){q.statsDisplay.innerHTML=` <div class="text-center text-gray-500 italic"> No statistics available </div> `;return}q.statsDisplay.innerHTML=` <div class="grid grid-cols-2 gap-4"> <div class="text-center"> <div class="text-2xl font-bold text-primary-600 mb-1"> ${J.stats.totalBlocked||0} </div> <div class="text-xs text-gray-500 font-medium"> Total Blocked </div> </div> <div class="text-center"> <div class="text-2xl font-bold text-primary-600 mb-1"> ${J.stats.sessionBlocked||0} </div> <div class="text-xs text-gray-500 font-medium"> This Session </div> </div> </div> `}async function R(){let q=Z();try{X({isLoading:!0});let H={enabled:q.toggleSwitch.checked,blockingMode:q.blockingModeSelect.value,showNotifications:q.notificationsToggle.checked,blockInHome:q.blockInHomeToggle.checked,blockInSearch:q.blockInSearchToggle.checked,blockInSubscriptions:q.blockInSubscriptionsToggle.checked,blockInTrending:q.blockInTrendingToggle.checked,allowWhitelistedChannels:q.whitelistToggle.checked,debugMode:q.debugToggle.checked};await F(H),await chrome.tabs.query({active:!0,currentWindow:!0});let[Q]=await chrome.tabs.query({active:!0,currentWindow:!0});if(Q?.id)await chrome.tabs.sendMessage(Q.id,{action:"updateSettings",settings:H});X({settings:{...J.settings,...H},isLoading:!1}),B("Settings saved successfully!")}catch(H){X({error:"Failed to save settings",isLoading:!1})}}async function P(){try{X({isLoading:!0}),await F($);let[q]=await chrome.tabs.query({active:!0,currentWindow:!0});if(q?.id)await chrome.tabs.sendMessage(q.id,{action:"updateSettings",settings:$});X({settings:$,isLoading:!1}),B("Settings reset to defaults!")}catch(q){X({error:"Failed to reset settings",isLoading:!1})}}function B(q){let H=Z(),Q=H.saveButton.textContent,x=H.saveButton.className;H.saveButton.textContent=q,H.saveButton.className="flex-1 bg-green-600 hover:bg-green-700 text-white font-medium py-2.5 px-4 rounded-lg transition-colors duration-200 transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2",H.saveButton.disabled=!0,setTimeout(()=>{H.saveButton.textContent=Q,H.saveButton.className=x,H.saveButton.disabled=!1},2000)}async function Y(){try{X({isLoading:!0});let[q,H]=await Promise.all([b(),V()]);X({settings:q,stats:H,isLoading:!1})}catch(q){X({error:"Failed to load data",isLoading:!1})}}function W(){let q=Z();q.saveButton.addEventListener("click",R),q.resetButton.addEventListener("click",P),q.toggleSwitch.addEventListener("change",U),Y()}if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",W);else W();