mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-06-04 23:37:46 +02:00
Update Layout.js
This commit is contained in:
parent
e3cb7e460e
commit
bb4e6d28f4
@ -9,54 +9,55 @@ export default function CustomLayout(props) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Проверяем, находимся ли мы на странице документации
|
// Проверяем, находимся ли мы на странице документации
|
||||||
if (!location.pathname.startsWith('/docs/')) {
|
if (!location.pathname.startsWith('/docs/')) {
|
||||||
return; // Если нет, не добавляем блоки
|
return; // Если нет, не добавляем блок
|
||||||
}
|
}
|
||||||
|
|
||||||
// Удаляем скрипт Яндекс.Директа, если он уже был добавлен
|
// Удаляем предыдущий блок и скрипт, если они существуют
|
||||||
const existingScript = document.querySelector('script[src="https://yandex.ru/ads/system/context.js"]');
|
const existingAdContainer = document.getElementById('yandex_rtb_R-A-12294791-5');
|
||||||
if (existingScript) {
|
if (existingAdContainer) {
|
||||||
existingScript.remove();
|
existingAdContainer.innerHTML = ''; // Очищаем контейнер перед перерендерингом
|
||||||
}
|
}
|
||||||
|
|
||||||
// Удаляем все контейнеры рекламы
|
// Создаем контейнер для второго рекламного блока, если он не существует
|
||||||
const existingAdContainers = document.querySelectorAll('[id^="yandex_rtb_R-A-12294791"]');
|
let adContainer = existingAdContainer;
|
||||||
existingAdContainers.forEach((container) => container.remove());
|
if (!adContainer) {
|
||||||
|
adContainer = document.createElement('div');
|
||||||
|
adContainer.id = 'yandex_rtb_R-A-12294791-5';
|
||||||
|
adContainer.style.marginTop = '20px'; // Добавим отступ для красоты
|
||||||
|
|
||||||
// Создаем контейнер для второго рекламного блока
|
// Находим элемент кнопок "Previous" и "Next" и вставляем перед ним
|
||||||
const adContainer = document.createElement('div');
|
const paginationElement = document.querySelector('.pagination-nav');
|
||||||
adContainer.id = 'yandex_rtb_R-A-12294791-5';
|
if (paginationElement) {
|
||||||
adContainer.style.marginTop = '20px'; // Добавим отступ для красоты
|
paginationElement.parentNode.insertBefore(adContainer, paginationElement);
|
||||||
|
} else {
|
||||||
// Находим элемент кнопок "Previous" и "Next" и вставляем перед ним
|
// Если кнопок нет, добавляем контейнер в конец body
|
||||||
const paginationElement = document.querySelector('.pagination-nav');
|
document.body.appendChild(adContainer);
|
||||||
if (paginationElement) {
|
}
|
||||||
paginationElement.parentNode.insertBefore(adContainer, paginationElement);
|
|
||||||
} else {
|
|
||||||
// Если кнопок нет, добавляем контейнер в конец body
|
|
||||||
document.body.appendChild(adContainer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем и добавляем скрипт Яндекс.Директа
|
// Создаем скрипт для рендеринга рекламы
|
||||||
const yandexScript = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
yandexScript.src = 'https://yandex.ru/ads/system/context.js';
|
script.innerHTML = `
|
||||||
yandexScript.async = true;
|
|
||||||
document.head.appendChild(yandexScript);
|
|
||||||
|
|
||||||
// Запускаем рендеринг рекламных блоков, как только скрипт загрузится
|
|
||||||
yandexScript.onload = () => {
|
|
||||||
window.yaContextCb.push(() => {
|
window.yaContextCb.push(() => {
|
||||||
|
Ya.Context.AdvManager.destroy('yandex_rtb_R-A-12294791-5'); // Удаляем предыдущий экземпляр блока
|
||||||
|
Ya.Context.AdvManager.render({
|
||||||
|
"blockId": "R-A-12294791-3",
|
||||||
|
"type": "floorAd",
|
||||||
|
"platform": "touch"
|
||||||
|
});
|
||||||
|
|
||||||
Ya.Context.AdvManager.render({
|
Ya.Context.AdvManager.render({
|
||||||
blockId: 'R-A-12294791-5',
|
"blockId": "R-A-12294791-5",
|
||||||
renderTo: 'yandex_rtb_R-A-12294791-5'
|
"renderTo": "yandex_rtb_R-A-12294791-5"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
`;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
|
||||||
// Удаляем элементы при размонтировании компонента
|
// Удаляем элементы при размонтировании компонента
|
||||||
return () => {
|
return () => {
|
||||||
yandexScript.remove();
|
script.remove();
|
||||||
adContainer.remove();
|
adContainer.innerHTML = ''; // Очищаем контейнер при размонтировании
|
||||||
};
|
};
|
||||||
}, [location.pathname]); // Перезапуск эффекта при изменении пути
|
}, [location.pathname]); // Перезапуск эффекта при изменении пути
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ export default function CustomLayout(props) {
|
|||||||
<script>
|
<script>
|
||||||
window.yaContextCb = window.yaContextCb || [];
|
window.yaContextCb = window.yaContextCb || [];
|
||||||
</script>
|
</script>
|
||||||
|
<script src="https://yandex.ru/ads/system/context.js" async></script>
|
||||||
</Head>
|
</Head>
|
||||||
<Layout {...props} />
|
<Layout {...props} />
|
||||||
</>
|
</>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user