|
| 1 | +import React, { useEffect, useRef } from 'react'; |
| 2 | +import styled from 'styled-components'; |
| 3 | +import { mediaQuery } from '../../lib/styles/media'; |
| 4 | +import gtag from '../../lib/gtag'; |
| 5 | +import { themedPalette } from '../../lib/styles/themes'; |
| 6 | +import { useTheme } from '../../lib/hooks/useTheme'; |
| 7 | + |
| 8 | +function init() { |
| 9 | + (function () { |
| 10 | + var size = '320x378', |
| 11 | + adunit = 'velog.io_320x378_native_DFP', |
| 12 | + childNetworkId = '22738196472', |
| 13 | + xmlhttp = new XMLHttpRequest(); |
| 14 | + xmlhttp.onreadystatechange = function () { |
| 15 | + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { |
| 16 | + var es = document.querySelectorAll("[data-id='" + adunit + "']"); |
| 17 | + var e = Array.from(es).filter(function (e) { |
| 18 | + return !e.hasAttribute('data-rendered'); |
| 19 | + }); |
| 20 | + if (e.length > 0) { |
| 21 | + e.forEach(function (el: any) { |
| 22 | + var iframe = el.contentWindow.document; |
| 23 | + iframe.open(); |
| 24 | + iframe.write(xmlhttp.responseText); |
| 25 | + iframe.close(); |
| 26 | + el.setAttribute('data-rendered', true); |
| 27 | + }); |
| 28 | + } |
| 29 | + } |
| 30 | + }; |
| 31 | + var child = childNetworkId.trim() ? ',' + childNetworkId.trim() : ''; |
| 32 | + xmlhttp.open( |
| 33 | + 'GET', |
| 34 | + 'https://pubads.g.doubleclick.net/gampad/adx?iu=/147246189' + |
| 35 | + child + |
| 36 | + '/' + |
| 37 | + adunit + |
| 38 | + '&sz=' + |
| 39 | + encodeURI(size) + |
| 40 | + '&t=Placement_type%3Dserving&' + |
| 41 | + Date.now(), |
| 42 | + true, |
| 43 | + ); |
| 44 | + xmlhttp.send(); |
| 45 | + })(); |
| 46 | +} |
| 47 | + |
| 48 | +function SetupAdFeed() { |
| 49 | + useEffect(() => { |
| 50 | + init(); |
| 51 | + }, []); |
| 52 | + |
| 53 | + return ( |
| 54 | + <Block> |
| 55 | + <iframe |
| 56 | + title="nativead" |
| 57 | + data-id="velog.io_320x378_native_DFP" |
| 58 | + frameBorder="0" |
| 59 | + scrolling="no" |
| 60 | + marginHeight={0} |
| 61 | + marginWidth={0} |
| 62 | + width="1" |
| 63 | + height="1" |
| 64 | + ></iframe> |
| 65 | + </Block> |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +const Block = styled.div` |
| 70 | + width: 20rem; |
| 71 | + margin: 1rem; |
| 72 | + min-height: 23.5625rem; |
| 73 | + height: auto; |
| 74 | + border-radius: 4px; |
| 75 | + box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.04); |
| 76 | + background: ${themedPalette.bg_element1}; |
| 77 | +
|
| 78 | + ${mediaQuery(1056)} { |
| 79 | + width: calc(50% - 2rem); |
| 80 | + } |
| 81 | + ${mediaQuery(767)} { |
| 82 | + margin: 0; |
| 83 | + width: 100%; |
| 84 | + margin-top: 1rem; |
| 85 | + margin-bottom: 1rem; |
| 86 | + min-height: 5rem; |
| 87 | + } |
| 88 | +`; |
| 89 | + |
| 90 | +export default SetupAdFeed; |
0 commit comments