-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
295 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,47 @@ | ||
function getVideoContainer() { | ||
const videoContainer = Array.from( | ||
document.getElementsByClassName("html5-video-container"), | ||
); | ||
return videoContainer.length > 0 ? videoContainer[0] : null; | ||
} | ||
|
||
function getVideoWrapper() { | ||
return getVideoContainer() ? getVideoContainer().parentNode : null; | ||
} | ||
|
||
function getVideoPlayer() { | ||
return getVideoContainer() ? getVideoContainer().firstChild : null; | ||
} | ||
|
||
function isAdShowing() { | ||
const wrapper = getVideoWrapper(); | ||
return wrapper !== null | ||
? wrapper !== undefined && String(wrapper.className).includes("ad-showing") | ||
: null; | ||
} | ||
|
||
function getSkipButton() { | ||
const skipAdButton = Array.from( | ||
document.getElementsByClassName("ytp-ad-skip-button ytp-button"), | ||
); | ||
return skipAdButton.length > 0 ? skipAdButton[0] : null; | ||
} | ||
|
||
function waitForPlayer() { | ||
if (getVideoPlayer()) { | ||
hookVideoPlayer(); | ||
} else { | ||
setTimeout(() => { | ||
waitForPlayer(); | ||
}, 200); | ||
} | ||
} | ||
|
||
function hookVideoPlayer() { | ||
const videoPlayer = getVideoPlayer(); | ||
videoPlayer.addEventListener("timeupdate", () => { | ||
getSkipButton()?.click(); | ||
const taimuRipu = async () => { | ||
await new Promise((resolve, _reject) => { | ||
const videoContainer = document.getElementById("movie_player"); | ||
|
||
const setTimeoutHandler = () => { | ||
const isAd = videoContainer?.classList.contains("ad-interrupting") || videoContainer?.classList.contains("ad-showing"); | ||
const skipLock = document.querySelector(".ytp-ad-preview-text")?.innerText; | ||
|
||
if (isAd && skipLock) { | ||
const videoPlayer = document.getElementsByClassName("video-stream")[0]; | ||
videoPlayer.currentTime = videoPlayer.duration - 0.1; | ||
// CLICK ON THE SKIP AD BTN | ||
document.querySelector(".ytp-ad-skip-button")?.click(); | ||
} | ||
|
||
const staticAds = [".ytd-companion-slot-renderer", ".ytd-action-companion-ad-renderer", // in-feed video ads | ||
".ytd-watch-next-secondary-results-renderer.sparkles-light-cta", ".ytd-unlimited-offer-module-renderer", // similar components | ||
".ytp-ad-overlay-image", ".ytp-ad-text-overlay", // deprecated overlay ads (04-06-2023) | ||
".ytd-display-ad-renderer", ".ytd-statement-banner-renderer", // homepage ads | ||
".ytd-banner-promo-renderer", ".ytd-video-masthead-ad-v3-renderer", ".ytd-primetime-promo-renderer" // subscribe for premium & youtube tv ads | ||
]; | ||
|
||
staticAds.forEach((ad) => { | ||
document.hideElementsBySelector(ad); | ||
}); | ||
|
||
resolve(); | ||
}; | ||
|
||
// RUN IT ONLY AFTER 100 MILLISECONDS | ||
setTimeout(setTimeoutHandler, 100); | ||
}); | ||
|
||
if (isAdShowing()) { | ||
videoPlayer.currentTime = videoPlayer.duration - 1; | ||
videoPlayer.pause(); | ||
videoPlayer.play(); | ||
} | ||
} | ||
|
||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
console.log(message) | ||
return true | ||
}); | ||
taimuRipu(); | ||
}; | ||
|
||
|
||
const init = async () => { | ||
Document.prototype.hideElementsBySelector = (selector) => | ||
[...document.querySelectorAll(selector)].forEach( | ||
(el) => (el.style.display = "none") | ||
); | ||
|
||
taimuRipu(); | ||
}; | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.