diff --git a/Youtube-Ad-blocker-Reminder-Remover.user.js b/Youtube-Ad-blocker-Reminder-Remover.user.js index 2434de1..6887a50 100644 --- a/Youtube-Ad-blocker-Reminder-Remover.user.js +++ b/Youtube-Ad-blocker-Reminder-Remover.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Remove Adblock Thing // @namespace http://tampermonkey.net/ -// @version 5.5 +// @version 5.6 // @description Removes Adblock Thing // @author JoelMatic // @match https://www.youtube.com/* @@ -29,6 +29,9 @@ // Enable debug messages into the console const debugMessages = true; + // Fix timestamps in the youtube comments for new method + const fixTimestamps = true; + // Enable custom modal // Uses SweetAlert2 library (https://cdn.jsdelivr.net/npm/sweetalert2@11) for the update version modal. // When set to false, the default window popup will be used. And the library will not be loaded. @@ -73,6 +76,7 @@ if (adblocker) removeAds(); if (removePopup) popupRemover(); if (updateCheck) checkForUpdate(); + if (fixTimestamps) timestampFix(); // Remove Them pesski popups function popupRemover() { @@ -113,9 +117,10 @@ }, 1000); } + + // undetected adblocker method // undetected adblocker method - function removeAds() - { + function removeAds() { log("removeAds()"); window.navigation.addEventListener("navigate", (event) => { @@ -145,7 +150,14 @@ removePageAds(); } + // Fix for youtube shorts + if (window.location.href.includes("shorts")) { + log("Youtube shorts detected, ignoring..."); + return; + } + if (isVideoPlayerModified){ + removeAllDuplicateVideos(); return; } @@ -164,31 +176,48 @@ // Remove the current player // - if(!clearAllPlayers()){ + if (!clearAllPlayers()) { return; } + /** + * remove the "Ad blockers violate YouTube's Terms of Service" screen for safari + */ + let errorScreen = document.querySelector("#error-screen"); + if (errorScreen) { + errorScreen.remove(); + } + // - // Get the url + // Get the video ID from the URL // let videoID = ''; - const baseURL = 'https://www.youtube.com/watch?v='; - const startIndex = currentUrl.indexOf(baseURL); + let playList = ''; + let timeStamp = ''; + const url = new URL(window.location.href); + const urlParams = new URLSearchParams(url.search); + if (urlParams.has('v')) { + videoID = urlParams.get('v'); + } else { + const pathSegments = url.pathname.split('/'); + const liveIndex = pathSegments.indexOf('live'); + if (liveIndex !== -1 && liveIndex + 1 < pathSegments.length) { + videoID = pathSegments[liveIndex + 1]; + } + } - if (startIndex !== -1) { - // Extract the part of the URL after the base URL - const videoIDStart = startIndex + baseURL.length; - videoID = currentUrl.substring(videoIDStart); + if (urlParams.has('list')) { + playList = "&listType=playlist&list=" + urlParams.get('list'); + } - const ampersandIndex = videoID.indexOf('&'); - if (ampersandIndex !== -1) { - videoID = videoID.substring(0, ampersandIndex); - } + if (urlParams.has('t')) { + timeStamp = "&start=" + urlParams.get('t').replace('s', ''); + } - } else { - log("YouTube video URL not found.", "e") + if (!videoID) { + log("YouTube video URL not found.", "e"); return null; } @@ -199,9 +228,11 @@ // const startOfUrl = "https://www.youtube-nocookie.com/embed/"; - const endOfUrl = "?autoplay=1&modestbranding=1"; + + const endOfUrl = "?autoplay=1&modestbranding=1&rel=0"; const finalUrl = startOfUrl + videoID + endOfUrl; + const iframe = document.createElement('iframe'); iframe.setAttribute('src', finalUrl); @@ -219,7 +250,7 @@ iframe.style.top = '0'; iframe.style.left = '0'; iframe.style.zIndex = '9999'; - iframe.style.pointerEvents = 'all'; + iframe.style.pointerEvents = 'all'; const videoPlayerElement = document.querySelector('.html5-video-player'); videoPlayerElement.appendChild(iframe); @@ -233,6 +264,30 @@ // logic functionm // + function removeAllDuplicateVideos() { + const videos = document.querySelectorAll('video'); + + videos.forEach(video => { + if (video.src.includes('www.youtube.com')) { + video.muted = true; + video.pause(); + video.addEventListener('volumechange', function() { + if (!video.muted) { + video.muted = true; + video.pause(); + log("Video unmuted detected and remuted"); + } + }); + video.addEventListener('play', function() { + video.pause(); + log("Video play detected and repaused"); + }); + + log("Duplicate video found and muted"); + } + }); + } + function clearAllPlayers() { const videoPlayerElements = document.querySelectorAll('.html5-video-player'); @@ -304,6 +359,52 @@ log("Removed page ads (✔️)"); } + function changeTimestamp(timestamp) { + const videoPlayerElements = document.querySelectorAll('.html5-video-player'); + videoPlayerElements.forEach(videoPlayerElement => { + const iframes = videoPlayerElement.querySelectorAll('iframe'); + iframes.forEach(iframe => { + if (iframe.src.includes("&start=")) { + iframe.src = iframe.src.replace(/&start=\d+/, "&start=" + timestamp); + } else { + iframe.src += "&start=" + timestamp; + } + }); + }); + } + + function timestampFix() { + document.addEventListener('click', function(event) { + const target = event.target; + + if (target.classList.contains('yt-core-attributed-string__link') && target.href.includes('&t=')) { + event.preventDefault(); + const timestamp = target.href.split('&t=')[1].split('s')[0]; + log(`Timestamp link clicked: ${timestamp} seconds`); + changeTimestamp(timestamp); + } + }); + } + + function observerCallback(mutations) { + let isVideoAdded = mutations.some(mutation => + Array.from(mutation.addedNodes).some(node => node.tagName === 'VIDEO') + ); + + if (isVideoAdded) { + log("New video detected, checking for duplicates."); + // Ignore for youtube shorts + if (window.location.href.includes("shorts")) { + log("Youtube shorts detected, ignoring..."); + return; + } + removeAllDuplicateVideos(); + } + } + + const observer = new MutationObserver(observerCallback); + observer.observe(document.body, { childList: true, subtree: true }); + // // Update check //