Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CatPieLeaf authored Jun 12, 2024
2 parents 913c133 + 04772da commit ea63a3f
Showing 1 changed file with 120 additions and 19 deletions.
139 changes: 120 additions & 19 deletions Youtube-Ad-blocker-Reminder-Remover.user.js
Original file line number Diff line number Diff line change
@@ -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/*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -73,6 +76,7 @@
if (adblocker) removeAds();
if (removePopup) popupRemover();
if (updateCheck) checkForUpdate();
if (fixTimestamps) timestampFix();

// Remove Them pesski popups
function popupRemover() {
Expand Down Expand Up @@ -113,9 +117,10 @@

}, 1000);
}

// undetected adblocker method
// undetected adblocker method
function removeAds()
{
function removeAds() {
log("removeAds()");

window.navigation.addEventListener("navigate", (event) => {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit ea63a3f

Please sign in to comment.