Homepage-Following: insert instead of replace when ad-blocker is detected (#1092)

* Homepage-Following: insert instead of replace when ad-blocker is detected.

`window.odysee_ad_blocker_detected` was not meant to be used outside of `<Ads>`, since it wouldn't spark a GUI update. But since homepages are rendered several times, perhaps it doesn't matter and we can skip adding to redux for now.

* Handle uBlock origin

If refreshed via "Clear Cache and Hard Reload", the detection method fails, but it does perform an internal redirect, so treat that as a failure.
This commit is contained in:
infinite-persistence 2022-03-14 11:25:51 -07:00 committed by GitHub
parent 63f19b278d
commit de29e323a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -99,7 +99,12 @@ function HomePage(props: Props) {
hasSource hasSource
prefixUris={getLivestreamUris(activeLivestreams, options.channelIds)} prefixUris={getLivestreamUris(activeLivestreams, options.channelIds)}
pinUrls={pinUrls} pinUrls={pinUrls}
injectedItem={index === 0 && { node: <Ads small type="video" tileLayout />, replace: true }} injectedItem={
index === 0 && {
node: <Ads small type="video" tileLayout />,
replace: window.odysee_ad_blocker_detected === false,
}
}
/> />
); );

View file

@ -73,8 +73,8 @@ function Ads(props: Props) {
const GOOGLE_AD_URL = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; const GOOGLE_AD_URL = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
fetch(GOOGLE_AD_URL) fetch(GOOGLE_AD_URL)
.then(() => { .then((response) => {
window.odysee_ad_blocker_detected = false; window.odysee_ad_blocker_detected = response.redirected === true;
}) })
.catch(() => { .catch(() => {
window.odysee_ad_blocker_detected = true; window.odysee_ad_blocker_detected = true;