Open qw87rt opened 3 weeks ago
//can also be applied to
removeAds
function cuz not clearing them can lead to performance issues if many intervals are running simultaneously.
function removeAds() { log("removeAds()");
// Clear any existing interval
clearInterval(removeAdsInterval);
removeAdsInterval = setInterval(() => {
if (window.location.href !== currentUrl) {
currentUrl = window.location.href;
isVideoPlayerModified = false;
clearAllPlayers();
removePageAds();
}
if (isVideoPlayerModified){
return;
}
log("Video replacement started!");
//
// remove ad audio
//
var video = document.querySelector('video');
if (video) video.volume = 0;
if (video) video.pause();
if (video) video.remove();
//
// Remove the current player
//
if(!clearAllPlayers()){
return;
}
//
// Get the url
//
let videoID = '';
const baseURL = 'https://www.youtube.com/watch?v=';
const startIndex = currentUrl.indexOf(baseURL);
if (startIndex !== -1) {
// Extract the part of the URL after the base URL
const videoIDStart = startIndex + baseURL.length;
videoID = currentUrl.substring(videoIDStart);
const ampersandIndex = videoID.indexOf('&');
if (ampersandIndex !== -1) {
videoID = videoID.substring(0, ampersandIndex);
}
} else {
log("YouTube video URL not found.", "e")
return null;
}
log("Video ID: " + videoID);
//
// Create new frame for the video
//
const startOfUrl = "https://www.youtube-nocookie.com/embed/";
const endOfUrl = "?autoplay=1&modestbranding=1";
const finalUrl = startOfUrl + videoID + endOfUrl;
const iframe = document.createElement('iframe');
iframe.setAttribute('src', finalUrl);
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share');
iframe.setAttribute('allowfullscreen', true);
iframe.setAttribute('mozallowfullscreen', "mozallowfullscreen");
iframe.setAttribute('msallowfullscreen', "msallowfullscreen");
iframe.setAttribute('oallowfullscreen', "oallowfullscreen");
iframe.setAttribute('webkitallowfullscreen', "webkitallowfullscreen");
iframe.style.width = '100%';
iframe.style.height = '100%';
iframe.style.position = 'absolute';
iframe.style.top = '0';
iframe.style.left = '0';
iframe.style.zIndex = '9999';
iframe.style.pointerEvents = 'all';
const videoPlayerElement = document.querySelector('.html5-video-player');
videoPlayerElement.appendChild(iframe);
log("Finished");
isVideoPlayerModified = true;
}, 500);
removePageAds(); }
The
popupRemover
function runs every second & can cause performance issues if the process is slow and if therr are frequent popups. //can also be applied toremoveAds
function cuz not clearing them can lead to performance issues if many intervals are running simultaneously.isPopupBeingProcessed
isPopupBeingProcessed
is trueisPopupBeingProcessed
to true to indicate that a popup is being processed.isPopupBeingProcessed
to false.this should help mitigate potential performance issues.