@@ -2,29 +2,75 @@ import React, { useEffect, useRef } from 'react';
22import { useColorMode } from '@docusaurus/theme-common' ;
33import OriginalDocSidebar from '@theme-original/DocSidebar' ;
44
5+ async function shouldUseFallback ( ) {
6+ return true ; // Temporarily disable EthicalAds
7+
8+ while ( typeof ethicalads === 'undefined' ) {
9+ await new Promise ( ( resolve ) => setTimeout ( resolve , 300 ) ) ;
10+ }
11+
12+ const placements = await ethicalads . wait ;
13+
14+ return ! placements . length || placements [ 0 ] . response . campaign_type !== 'paid' ;
15+ }
16+
17+ function createEthicalAdsBlock ( root ) {
18+ const banner = document . createElement ( 'div' ) ;
19+
20+ banner . className = 'eab flat horizontal'
21+ banner . id = 'bwndw' ;
22+ banner . setAttribute ( 'data-ea-publisher' , 'react-chartjs-2jsorg' ) ;
23+ banner . setAttribute ( 'data-ea-type' , 'image' ) ;
24+
25+ root ?. appendChild ( banner ) ;
26+
27+ if ( typeof ethicalads !== 'undefined' ) {
28+ ethicalads . reload ( ) ;
29+ }
30+
31+ return banner ;
32+ }
33+
34+ function createCarbonAdsBlock ( root ) {
35+ const banner = document . createElement ( 'div' ) ;
36+ const script = document . createElement ( 'script' ) ;
37+
38+ banner . className = 'crbn' ;
39+ banner . id = 'bwndw' ;
40+
41+ script . src = '//cdn.carbonads.com/carbon.js?serve=CWBDT53N&placement=react-chartjs-2jsorg&format=cover' ;
42+ script . id = '_carbonads_js' ;
43+ script . async = true ;
44+
45+ banner . appendChild ( script ) ;
46+ root ?. appendChild ( banner ) ;
47+
48+ return banner ;
49+ }
50+
51+ function setColorMode ( banner , colorMode ) {
52+ banner ?. classList . toggle ( 'dark' , colorMode === 'dark' ) ;
53+ }
54+
555export default function DocSidebar ( props ) {
656 const bannerRef = useRef ( ) ;
757 const { colorMode } = useColorMode ( ) ;
858
959 useEffect ( ( ) => {
10- if ( ! document . getElementById ( 'eab' ) ) {
11- const banner = document . createElement ( 'div' ) ;
12-
13- bannerRef . current = banner ;
14- banner . className = 'flat horizontal'
15- banner . id = 'eab' ;
16- banner . setAttribute ( 'data-ea-publisher' , 'react-chartjs-2jsorg' ) ;
17- banner . setAttribute ( 'data-ea-type' , 'image' ) ;
18- document . querySelector ( '.theme-doc-sidebar-menu' ) ?. parentElement ?. appendChild ( banner ) ;
19-
20- if ( typeof ethicalads !== 'undefined' ) {
21- ethicalads . reload ( ) ;
22- }
60+ if ( ! document . getElementById ( 'bwndw' ) ) {
61+ shouldUseFallback ( ) . then ( ( useFallback ) => {
62+ if ( ! document . getElementById ( 'bwndw' ) ) {
63+ const root = document . querySelector ( '.theme-doc-sidebar-menu' ) ?. parentElement ;
64+
65+ bannerRef . current = useFallback ? createCarbonAdsBlock ( root ) : createEthicalAdsBlock ( root ) ;
66+ setColorMode ( bannerRef . current , colorMode ) ;
67+ }
68+ } ) ;
2369 }
2470 } , [ ] ) ;
2571
2672 useEffect ( ( ) => {
27- bannerRef . current ?. classList . toggle ( 'dark' , colorMode === 'dark' ) ;
73+ setColorMode ( bannerRef . current , colorMode ) ;
2874 } , [ colorMode ] ) ;
2975
3076 return (
0 commit comments