Skip to content

Commit

Permalink
Add again feature to hide ads
Browse files Browse the repository at this point in the history
- refs PR sarbagyastha#350
- Add disclaimer in doc
  • Loading branch information
Rackor committed Oct 4, 2021
1 parent 16e6040 commit 064fbd8
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -33,6 +33,13 @@ class YoutubePlayerFlags {
///
/// Default is false.
final bool hideThumbnail;

/// Hides popover advertisments if true.
///
/// Default is false
///
/// DISCLAIMER: Enabling this option may violete YouTube's ToS. Use at your own risk!
final bool hideAds;

/// Disables seeking video position when dragging horizontally.
///
Expand Down Expand Up @@ -87,6 +94,7 @@ class YoutubePlayerFlags {
this.mute = false,
this.isLive = false,
this.hideThumbnail = false,
this.hideAds = false,
this.disableDragSeek = false,
this.enableCaption = true,
this.captionLanguage = 'en',
Expand All @@ -106,6 +114,7 @@ class YoutubePlayerFlags {
bool? showVideoProgressIndicator,
bool? isLive,
bool? hideThumbnail,
bool? hideAds,
bool? disableDragSeek,
bool? loop,
bool? enableCaption,
Expand All @@ -124,6 +133,7 @@ class YoutubePlayerFlags {
enableCaption: enableCaption ?? this.enableCaption,
hideControls: hideControls ?? this.hideControls,
hideThumbnail: hideThumbnail ?? this.hideThumbnail,
hideAds: hideAds ?? this.hideAds,
isLive: isLive ?? this.isLive,
loop: loop ?? this.loop,
mute: mute ?? this.mute,
Expand Down

0 comments on commit 064fbd8

Please sign in to comment.