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

Commit

Permalink
Fix Profile and Notifications and unpausing Issue's
Browse files Browse the repository at this point in the history
Thanks to @angelapuzzle for fixing the 2 main problems with the old code.

I've just made the code less nested with out changing any functionality.
  • Loading branch information
TheRealJoelmatic authored Oct 10, 2023
1 parent 2695dd6 commit f93d509
Showing 1 changed file with 48 additions and 71 deletions.
119 changes: 48 additions & 71 deletions Youtube-Ad-blocker-Reminder-Remover
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

let unpausedAfterSkip = 0; //This is used to check if the video has been unpaused already

if (debug) console.log("Script started");
if (debug) console.log("Remove Adblock Thing: Script started");

// Old variable but could work in some cases
window.__ytplayer_adblockDetected = false;
Expand All @@ -36,6 +36,10 @@
setInterval(() =>
{
const popup = document.querySelector("body > ytd-app > ytd-popup-container > tp-yt-paper-dialog");

const video1 = document.querySelector("#movie_player > video.html5-main-video");
const video2 = document.querySelector("#movie_player > .html5-video-container > video");

if (popup)
{
if (debug) console.log("Remove Adblock Thing: Popup detected, removing...");
Expand All @@ -45,59 +49,19 @@
}

// Check if the video is paused after removing the popup
if (unpausedAfterSkip > 0)
if (!unpausedAfterSkip > 0) return;


if (video1)
{
console.log("pong");
const video1 = document.querySelector("#movie_player > video.html5-main-video");
const video2 = document.querySelector("#movie_player > .html5-video-container > video");
if (video1)
{
if (video1.paused)
{
// Simulate pressing the "k" key to unpause the video
const keyEvent = new KeyboardEvent("keydown",
{
key: "k",
code: "KeyK",
keyCode: 75,
which: 75,
bubbles: true,
cancelable: true,
view: window
});
document.dispatchEvent(keyEvent);
unpausedAfterSkip = 0;
if (debug) console.log("Remove Adblock Thing: Unpaused video using 'k' key");
}
else if (unpausedAfterSkip > 0)
{
unpausedAfterSkip--;
}
}
if (video2)
{
if (video2.paused)
{
// Simulate pressing the "k" key to unpause the video
const keyEvent = new KeyboardEvent("keydown",
{
key: "k",
code: "KeyK",
keyCode: 75,
which: 75,
bubbles: true,
cancelable: true,
view: window
});
document.dispatchEvent(keyEvent);
unpausedAfterSkip = 0;
if (debug) console.log("Remove Adblock Thing: Unpaused video using 'k' key");
}
else if (unpausedAfterSkip > 0)
{
unpausedAfterSkip--;
}
}
// UnPause The Video
if (video1.paused) UnPauseVideo();
else if (unpausedAfterSkip > 0) unpausedAfterSkip--;
}
if (video2)
{
if (video2.paused) UnPauseVideo();
else if (unpausedAfterSkip > 0) unpausedAfterSkip--;
}

}, 1000);
Expand All @@ -114,30 +78,43 @@
};
observer.observe(document.body, observerConfig);

function UnPauseVideo()
{
// Simulate pressing the "k" key to unpause the video
const keyEvent = new KeyboardEvent("keydown",{
key: "k",
code: "KeyK",
keyCode: 75,
which: 75,
bubbles: true,
cancelable: true,
view: window
});
document.dispatchEvent(keyEvent);
unpausedAfterSkip = 0;
if (debug) console.log("Remove Adblock Thing: Unpaused video using 'k' key");
}
function removeJsonPaths(domains, jsonPaths)
{
const currentDomain = window.location.hostname;
if (domains.includes(currentDomain))
{
jsonPaths.forEach(jsonPath =>
if (!domains.includes(currentDomain)) return;

jsonPaths.forEach(jsonPath =>{
const pathParts = jsonPath.split('.');
let obj = window;
for (const part of pathParts)
{
const pathParts = jsonPath.split('.');
let obj = window;
for (const part of pathParts)
if (obj.hasOwnProperty(part))
{
if (obj.hasOwnProperty(part))
{
obj = obj[part];
}
else
{
break;
}
obj = obj[part];
}
obj = undefined;
});
}
else
{
break;
}
}
obj = undefined;
});
}


})();

0 comments on commit f93d509

Please sign in to comment.