Skip to content

Commit

Permalink
feat: added tab muter for youtube ads (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: anandsummer28 <[email protected]>
  • Loading branch information
anandsummer28 and anandsummer28 authored Oct 10, 2024
1 parent b03e65c commit 22980d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ You can customize the behavior of the extension by modifying the following files

1. [www.jiocinema.com](www.jiocinema.com)
2. [www.hotstar.com](www.hotstar.com)
3. [www.youtube.com](www.youtube.com)

## Feedback

Expand Down
20 changes: 16 additions & 4 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Check if the current site is "hotstar" or "jiocinema"
// Check if the current site is "hotstar" or "jiocinema"
// Check if the current site is "hotstar" or "jiocinema" or "youtube"
const hostname = window.location.hostname;
const isHotstar = hostname.includes('hotstar.com');
const isJioCinema = hostname.includes('jiocinema.com');
const isYoutube = hostname.includes('youtube.com');

if (isHotstar || isJioCinema) {
if (isHotstar || isJioCinema || isYoutube) {
const observer = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach((mutation) => {
if (mutation.type === 'childList') {
Expand All @@ -22,6 +22,13 @@ if (isHotstar || isJioCinema) {
console.log('Hotstar Tab muted!');
});
}

// for Youtube
if (isYoutube && node.nodeType === Node.ELEMENT_NODE && node.classList.contains('ytp-ad-player-overlay-layout')) {
chrome.runtime.sendMessage({ action: 'muteTabVolume' }, (response) => {
console.log('Youtube Tab muted!');
});
}
});

mutation.removedNodes.forEach((node) => {
Expand All @@ -33,7 +40,12 @@ if (isHotstar || isJioCinema) {
// for hotstar
if (isHotstar && node.getAttribute && node.getAttribute('data-testid') === 'ad-details') {
setTimeout(() => {chrome.runtime.sendMessage({action: 'restoreTabVolume'}, (response) => console.log('HotStar Tab unmuted!'))}, 0);
}
}

// for Youtube
if (isYoutube && node.nodeType === Node.ELEMENT_NODE && node.classList.contains('ytp-ad-player-overlay-layout')) {
setTimeout(() => {chrome.runtime.sendMessage({action: 'restoreTabVolume'}, (response) => console.log('Youtube Tab unmuted!'))}, 0);
}
});
}
});
Expand Down

0 comments on commit 22980d2

Please sign in to comment.