dont run ads on channel page
This commit is contained in:
parent
30cd0644fa
commit
f012ba7d73
1 changed files with 131 additions and 131 deletions
|
@ -77,137 +77,137 @@ function ChannelContent(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if passed element is fully visible on screen
|
// returns true if passed element is fully visible on screen
|
||||||
function isScrolledIntoView(el) {
|
// function isScrolledIntoView(el) {
|
||||||
const rect = el.getBoundingClientRect();
|
// const rect = el.getBoundingClientRect();
|
||||||
const elemTop = rect.top;
|
// const elemTop = rect.top;
|
||||||
const elemBottom = rect.bottom;
|
// const elemBottom = rect.bottom;
|
||||||
|
//
|
||||||
// Only completely visible elements return true:
|
// // Only completely visible elements return true:
|
||||||
const isVisible = elemTop >= 0 && elemBottom <= window.innerHeight;
|
// const isVisible = elemTop >= 0 && elemBottom <= window.innerHeight;
|
||||||
return isVisible;
|
// return isVisible;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
React.useEffect(() => {
|
// React.useEffect(() => {
|
||||||
if (isAuthenticated || !SHOW_ADS) {
|
// if (isAuthenticated || !SHOW_ADS) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
// const urlParams = new URLSearchParams(window.location.search);
|
||||||
const viewType = urlParams.get('view');
|
// const viewType = urlParams.get('view');
|
||||||
|
//
|
||||||
// only insert ad if it's a content view
|
// // only insert ad if it's a content view
|
||||||
if (viewType !== 'content') return;
|
// if (viewType !== 'content') return;
|
||||||
|
//
|
||||||
(async function () {
|
// (async function () {
|
||||||
// test if adblock is enabled
|
// // test if adblock is enabled
|
||||||
let adBlockEnabled = false;
|
// let adBlockEnabled = false;
|
||||||
const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
// const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
||||||
try {
|
// try {
|
||||||
await fetch(new Request(googleAdUrl)).catch((_) => {
|
// await fetch(new Request(googleAdUrl)).catch((_) => {
|
||||||
adBlockEnabled = true;
|
// adBlockEnabled = true;
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
adBlockEnabled = true;
|
// adBlockEnabled = true;
|
||||||
} finally {
|
// } finally {
|
||||||
if (!adBlockEnabled) {
|
// if (!adBlockEnabled) {
|
||||||
// select the cards on page
|
// // select the cards on page
|
||||||
let cards = document.getElementsByClassName('card claim-preview--tile');
|
// let cards = document.getElementsByClassName('card claim-preview--tile');
|
||||||
|
//
|
||||||
// eslint-disable-next-line no-inner-declarations
|
// // eslint-disable-next-line no-inner-declarations
|
||||||
function checkFlag() {
|
// function checkFlag() {
|
||||||
if (cards.length === 0) {
|
// if (cards.length === 0) {
|
||||||
window.setTimeout(checkFlag, 100);
|
// window.setTimeout(checkFlag, 100);
|
||||||
} else {
|
// } else {
|
||||||
// find the last fully visible card
|
// // find the last fully visible card
|
||||||
let lastCard;
|
// let lastCard;
|
||||||
|
//
|
||||||
// width of browser window
|
// // width of browser window
|
||||||
const windowWidth = window.innerWidth;
|
// const windowWidth = window.innerWidth;
|
||||||
|
//
|
||||||
// on small screens, grab the second item
|
// // on small screens, grab the second item
|
||||||
if (windowWidth <= 900) {
|
// if (windowWidth <= 900) {
|
||||||
lastCard = cards[1];
|
// lastCard = cards[1];
|
||||||
} else {
|
// } else {
|
||||||
// otherwise, get the last fully visible card
|
// // otherwise, get the last fully visible card
|
||||||
for (const card of cards) {
|
// for (const card of cards) {
|
||||||
const isFullyVisible = isScrolledIntoView(card);
|
// const isFullyVisible = isScrolledIntoView(card);
|
||||||
if (!isFullyVisible) break;
|
// if (!isFullyVisible) break;
|
||||||
lastCard = card;
|
// lastCard = card;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// clone the last card
|
// // clone the last card
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
const clonedCard = lastCard.cloneNode(true);
|
// const clonedCard = lastCard.cloneNode(true);
|
||||||
|
//
|
||||||
// insert cloned card
|
// // insert cloned card
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
lastCard.parentNode.insertBefore(clonedCard, lastCard);
|
// lastCard.parentNode.insertBefore(clonedCard, lastCard);
|
||||||
|
//
|
||||||
// delete last card so that it doesn't mess up formatting
|
// // delete last card so that it doesn't mess up formatting
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
// lastCard.remove();
|
// // lastCard.remove();
|
||||||
|
//
|
||||||
// change the appearance of the cloned card
|
// // change the appearance of the cloned card
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('.claim__menu-button').remove();
|
// clonedCard.querySelector('.claim__menu-button').remove();
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('.truncated-text').innerHTML = __(
|
// clonedCard.querySelector('.truncated-text').innerHTML = __(
|
||||||
'Hate these? Login to Odysee for an ad free experience'
|
// 'Hate these? Login to Odysee for an ad free experience'
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('.claim-tile__info').remove();
|
// clonedCard.querySelector('.claim-tile__info').remove();
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('[role="none"]').removeAttribute('href');
|
// clonedCard.querySelector('[role="none"]').removeAttribute('href');
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('.claim-tile__header').firstChild.href = '/$/signin';
|
// clonedCard.querySelector('.claim-tile__header').firstChild.href = '/$/signin';
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('.claim-tile__title').firstChild.removeAttribute('aria-label');
|
// clonedCard.querySelector('.claim-tile__title').firstChild.removeAttribute('aria-label');
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('.claim-tile__title').firstChild.removeAttribute('title');
|
// clonedCard.querySelector('.claim-tile__title').firstChild.removeAttribute('title');
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard.querySelector('.claim-tile__header').firstChild.removeAttribute('aria-label');
|
// clonedCard.querySelector('.claim-tile__header').firstChild.removeAttribute('aria-label');
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
clonedCard
|
// clonedCard
|
||||||
.querySelector('.media__thumb')
|
// .querySelector('.media__thumb')
|
||||||
.replaceWith(document.getElementsByClassName('homepageAdContainer')[0]);
|
// .replaceWith(document.getElementsByClassName('homepageAdContainer')[0]);
|
||||||
|
//
|
||||||
// show the homepage ad which is not displayed at first
|
// // show the homepage ad which is not displayed at first
|
||||||
document.getElementsByClassName('homepageAdContainer')[0].style.display = 'block';
|
// document.getElementsByClassName('homepageAdContainer')[0].style.display = 'block';
|
||||||
|
//
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
const imageHeight = window.getComputedStyle(lastCard.querySelector('.media__thumb')).height;
|
// const imageHeight = window.getComputedStyle(lastCard.querySelector('.media__thumb')).height;
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
const imageWidth = window.getComputedStyle(lastCard.querySelector('.media__thumb')).width;
|
// const imageWidth = window.getComputedStyle(lastCard.querySelector('.media__thumb')).width;
|
||||||
|
//
|
||||||
const styles = `#av-container, #AVcontent, #aniBox {
|
// const styles = `#av-container, #AVcontent, #aniBox {
|
||||||
height: ${imageHeight} !important;
|
// height: ${imageHeight} !important;
|
||||||
width: ${imageWidth} !important;
|
// width: ${imageWidth} !important;
|
||||||
}`;
|
// }`;
|
||||||
|
//
|
||||||
const styleSheet = document.createElement('style');
|
// const styleSheet = document.createElement('style');
|
||||||
styleSheet.type = 'text/css';
|
// styleSheet.type = 'text/css';
|
||||||
styleSheet.id = 'customAniviewStyling';
|
// styleSheet.id = 'customAniviewStyling';
|
||||||
styleSheet.innerText = styles;
|
// styleSheet.innerText = styles;
|
||||||
// $FlowFixMe
|
// // $FlowFixMe
|
||||||
document.head.appendChild(styleSheet);
|
// document.head.appendChild(styleSheet);
|
||||||
|
//
|
||||||
window.dispatchEvent(new CustomEvent('scroll'));
|
// window.dispatchEvent(new CustomEvent('scroll'));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
checkFlag();
|
// checkFlag();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
})();
|
// })();
|
||||||
}, []);
|
// }, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
|
|
Loading…
Reference in a new issue