// ==UserScript== // @name NBA.com - Spoiler Blocker // @version 1.0 // @description Enhances NBA.com by hiding video lengths and adding fictitious durations to the progress bar to prevent spoilers. It also hides spoilers on the front page. // @author You // @match *://*.nba.com/* // @license MIT // @grant none // @run-at document-start // @namespace https://greasyfork.org/users/1291378 // @downloadURL none // ==/UserScript== (function() { 'use strict'; document.addEventListener('DOMContentLoaded', function() { setTimeout(showToast, 500); // Delaying the toast display by 500 milliseconds if (window.location.href === 'https://www.nba.com/') { // Only run this block if the current URL is exactly 'https://www.nba.com/' // Inject CSS to hide specific elements as soon as the page starts loading. const css = '.MaxWidthContainer_mwc__ID5AG { display: none !important; }'; const head = document.head || document.getElementsByTagName('head')[0]; const style = document.createElement('style'); style.type = 'text/css'; if (style.styleSheet){ // IE8 and below style.styleSheet.cssText = css; } else { // Other browsers style.appendChild(document.createTextNode(css)); } head.appendChild(style); } // Check if URL does not contain "watchLive=true" if (!window.location.search.includes('watchLive=true')) { // Functions related to videos, progress bars, and custom buttons function createAndAppendButton(container, label, seconds) { const button = document.createElement('button'); button.textContent = label; button.style.padding = '8px'; button.style.marginLeft = '5px'; button.style.background = '#FFF'; button.style.color = '#000'; button.style.border = 'none'; button.style.cursor = 'pointer'; // When clicked, the button adjusts the current time of the video. button.onclick = function() { const video = document.querySelector('video'); if (video) { video.currentTime += seconds; } }; container.appendChild(button); } function getRandomMaxLength() { const threeHoursInSeconds = 3 * 60 * 60; const oneHourInSeconds = 60 * 60; return threeHoursInSeconds + Math.floor(Math.random() * oneHourInSeconds); } const standardMaxLength = getRandomMaxLength(); function randomizeProgressBar() { const progressBar = document.getElementById('progress-bar'); const rangeInput = document.querySelector('.sc-beqWaB.bpZMgR input[type="range"]'); if (progressBar && rangeInput) { progressBar.max = standardMaxLength; rangeInput.max = standardMaxLength; rangeInput.setAttribute('aria-valuemax', standardMaxLength); } } function hideTimeElements() { const timePattern = /\b\d{2}:\d{2}:\d{2}\b/; const spans = document.querySelectorAll('span'); spans.forEach(span => { if (timePattern.test(span.innerText)) { span.style.display = 'none'; } }); } const observer = new MutationObserver((mutations) => { mutations.forEach(mutation => { if (mutation.type === 'childList' || mutation.type === 'attributes') { hideTimeElements(); } }); }); function addSkipButtonsIfControlBarExists() { const controlBar = document.querySelector('.sc-lnAgIa.hfaRgm.controlbar'); if (controlBar && !controlBar.dataset.skipButtonsAdded) { controlBar.dataset.skipButtonsAdded = 'true'; createAndAppendButton(controlBar, 'Skip Short Timeout (30sec)', 30); createAndAppendButton(controlBar, 'Skip Timeout (90sec)', 90); createAndAppendButton(controlBar, 'Skip Free Throws (1min)', 60); createAndAppendButton(controlBar, 'Skip Halftime (15min)', 900); } } observer.observe(document.body, { attributes: true, childList: true, subtree: true }); setInterval(randomizeProgressBar, 1000); hideTimeElements(); addSkipButtonsIfControlBarExists(); } function showToast() { const toast = document.createElement('div'); toast.textContent = 'NBA Spoiler Blocker has been activated!'; toast.style.position = 'fixed'; toast.style.top = '20px'; toast.style.left = '50%'; toast.style.transform = 'translateX(-50%)'; toast.style.padding = '10px 20px'; toast.style.color = '#FFF'; toast.style.background = '#FF0000'; toast.style.borderRadius = '5px'; toast.style.boxShadow = '0 2px 6px rgba(0,0,0,0.3)'; toast.style.zIndex = '99999'; document.body.appendChild(toast); setTimeout(() => toast.remove(), 3000); } }); })();