index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import React from "react";
  2. import styled from "styled-components";
  3. const AdWrapper = styled.div`
  4. z-index: 1000;
  5. .sticky-js {
  6. display: flex;
  7. justify-content: center;
  8. z-index: 1000;
  9. position: relative;
  10. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  11. Cantarell, "Helvetica Neue", sans-serif;
  12. }
  13. #sticky-js._bsa_hide {
  14. display: none;
  15. }
  16. #sticky-js .native-hide {
  17. position: absolute;
  18. top: -6px;
  19. right: -6px;
  20. padding: 4px 5.42px;
  21. font-size: 12px;
  22. line-height: 1;
  23. cursor: pointer;
  24. border-radius: 50%;
  25. }
  26. #sticky-js {
  27. position: fixed;
  28. bottom: 60px;
  29. right: 10%;
  30. }
  31. #sticky-js .sticky-bar {
  32. display: flex;
  33. justify-content: space-between;
  34. align-items: center;
  35. padding: 15px 20px;
  36. max-width: 600px;
  37. text-decoration: none;
  38. border-radius: 10px;
  39. box-shadow: inset 0 0 2px hsla(0, 0%, 0%, 0.15);
  40. flex-flow: row nowrap;
  41. }
  42. #sticky-js .native-img {
  43. margin-right: 20px;
  44. line-height: 0;
  45. max-height: 40px;
  46. }
  47. #sticky-js .native-main {
  48. display: flex;
  49. justify-content: center;
  50. align-items: center;
  51. margin: 0 auto;
  52. flex-grow: 1;
  53. flex-flow: row nowrap;
  54. }
  55. #sticky-js .native-details {
  56. display: flex;
  57. margin-right: 20px;
  58. flex-flow: column nowrap;
  59. }
  60. #sticky-js .native-tagline {
  61. margin-bottom: 3px;
  62. font-size: 9px;
  63. font-weight: 600;
  64. line-height: 1;
  65. letter-spacing: 1.5px;
  66. text-transform: uppercase;
  67. }
  68. #sticky-js .native-desc {
  69. font-size: 12px;
  70. font-weight: 400;
  71. line-height: 1.4;
  72. max-width: 600px;
  73. letter-spacing: 1px;
  74. }
  75. #sticky-js .native-cta {
  76. padding: 10px 16px;
  77. font-size: 10px;
  78. font-weight: 600;
  79. line-height: 1;
  80. transition: all 0.3s ease-in-out;
  81. transform: translateY(-1px);
  82. white-space: nowrap;
  83. letter-spacing: 1px;
  84. text-transform: uppercase;
  85. border-radius: 3px;
  86. }
  87. #sticky-js .native-via {
  88. position: absolute;
  89. right: 0;
  90. bottom: 0;
  91. padding: 5px 10px;
  92. font-size: 8px;
  93. font-weight: 600;
  94. line-height: 1;
  95. text-decoration: none;
  96. letter-spacing: 0.7px;
  97. text-transform: uppercase;
  98. color: #444;
  99. border-top: 0;
  100. border-top-left-radius: 3px;
  101. background: repeating-linear-gradient(
  102. -45deg,
  103. transparent,
  104. transparent 5px,
  105. hsla(0, 0%, 0%, 0.025) 5px,
  106. hsla(0, 0%, 0%, 0.025) 10px
  107. )
  108. hsla(203, 11%, 95%, 0.4);
  109. }
  110. @media only screen and (min-width: 320px) and (max-width: 759px) {
  111. #sticky-js,
  112. #sticky-js .native-main {
  113. flex-flow: column nowrap;
  114. }
  115. #sticky-js .native-img,
  116. #sticky-js .native-details {
  117. margin: 0;
  118. }
  119. #sticky-js .native-img {
  120. display: none;
  121. }
  122. #sticky-js .native-company {
  123. letter-spacing: 1px;
  124. }
  125. #sticky-js .native-details {
  126. font-size: 14px;
  127. text-align: left;
  128. }
  129. #sticky-js .native-cta {
  130. display: none;
  131. }
  132. }
  133. `;
  134. const template = `${"`"}
  135. <a class="sticky-bar" style="background-color: ##backgroundColor##; color: ##textColor##" href="##link##" rel="sponsored noopener" target="_blank" title="##company## — ##tagline##">
  136. <div class="native-main">
  137. <img class="native-img" src="##logo##">
  138. <div class="native-details" style="color: ##textColor##">
  139. <span class="native-tagline">Sponsored by ##company##</span>
  140. <span class="native-desc">##description##</span>
  141. </div>
  142. <span class="native-cta" style="color: ##ctaTextColor##; background-color: ##ctaBackgroundColor##;">##callToAction##</span>
  143. </div>
  144. </a>
  145. <div class="native-hide" style="background-color: ##textColor##; color: ##backgroundColor##; border: solid 1px ##backgroundColor##;" onclick="_bsa.close('sticky-js')">✕</div>
  146. ${"`"}`;
  147. export const AdTest = () => {
  148. const ref = React.useRef<HTMLDivElement>(null!);
  149. React.useEffect(() => {
  150. if (window.innerWidth < 660) return;
  151. ref.current.innerHTML = "";
  152. const s = document.createElement("script");
  153. s.id = "_carbonads_js";
  154. s.innerHTML = `(function() {
  155. if (typeof _bsa !== 'undefined' && _bsa) {
  156. _bsa.init('custom', 'CWYD42JI', 'placement:jsoncrackcom', {
  157. target: '.sticky-js',
  158. id: 'sticky-js',
  159. template: ${template}
  160. });
  161. }
  162. })();`;
  163. ref.current.appendChild(s);
  164. }, []);
  165. return <AdWrapper ref={ref} className="sticky-js"></AdWrapper>;
  166. };