Skip to content

Commit

Permalink
Hide popover ads sarbagyastha#350
Browse files Browse the repository at this point in the history
  • Loading branch information
tlueder committed May 8, 2021
1 parent fa53c2b commit 32a7cb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
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>
<body>
Expand Down Expand Up @@ -285,7 +290,15 @@ 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 @@ -29,6 +29,11 @@ class YoutubePlayerFlags {
/// Default is false.
final bool isLive;

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

/// Hides thumbnail if true.
///
/// Default is false.
Expand Down Expand Up @@ -86,6 +91,7 @@ class YoutubePlayerFlags {
this.autoPlay = true,
this.mute = false,
this.isLive = false,
this.hideAds = false,
this.hideThumbnail = false,
this.disableDragSeek = false,
this.enableCaption = true,
Expand All @@ -105,6 +111,7 @@ class YoutubePlayerFlags {
bool? mute,
bool? showVideoProgressIndicator,
bool? isLive,
bool? hideAds,
bool? hideThumbnail,
bool? disableDragSeek,
bool? loop,
Expand All @@ -122,6 +129,7 @@ class YoutubePlayerFlags {
captionLanguage: captionLanguage ?? this.captionLanguage,
disableDragSeek: disableDragSeek ?? this.disableDragSeek,
enableCaption: enableCaption ?? this.enableCaption,
hideAds: hideAds ?? this.hideAds,
hideControls: hideControls ?? this.hideControls,
hideThumbnail: hideThumbnail ?? this.hideThumbnail,
isLive: isLive ?? this.isLive,
Expand Down

0 comments on commit 32a7cb8

Please sign in to comment.