Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide popover ads #350

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
width: 100%;
pointer-events: none;
}
</style>
<style id="yt-css">
.video-ads, .ytp-ad-module {
display: none !important;
}
</style>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'>
</head>
Expand Down Expand Up @@ -274,7 +279,16 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
'end': ${controller.flags.endAt}
},
events: {
onReady: function(event) { window.flutter_inappwebview.callHandler('Ready'); },
onReady: function(event) {
if (${controller.flags.hideAds}) {
var iframe = document.getElementsByTagName('iframe')[0].contentWindow.document;
var div = iframe.getElementsByTagName('div')[0];
var css = document.getElementById('yt-css');
div.parentNode.insertBefore(css, div);
}

window.flutter_inappwebview.callHandler('Ready');
},
onStateChange: function(event) { sendPlayerStateChange(event.data); },
onPlaybackQualityChange: function(event) { window.flutter_inappwebview.callHandler('PlaybackQualityChange', event.data); },
onPlaybackRateChange: function(event) { window.flutter_inappwebview.callHandler('PlaybackRateChange', event.data); },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class YoutubePlayerFlags {
/// Default is false.
final bool loop;

/// returns true when the player should show popover ads
///
/// default is false
final bool hideAds;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add doc regarding saying, Use this at your own risk as this might violate YouTube's TOS.?


/// Enabling causes closed captions to be shown by default.
///
/// Default is true.
Expand Down Expand Up @@ -80,6 +85,7 @@ class YoutubePlayerFlags {
this.captionLanguage = 'en',
this.loop = false,
this.forceHD = false,
this.hideAds = false,
this.startAt = 0,
this.endAt,
});
Expand Down