Skip to content
Myr

Fix double image request

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Use official framework for the "custom" ad design integration.

authored by Sayz Lim · committed by Sayz Lim · parent c9309e4 · Browse files · 4 files+59 added−224 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+59 added−224 removed

  • other:+59 added−224 removed

4 files+59 added−224 removed

modified:docs/_static/custom.css+20 added-25 removed
deleted:docs/_static/native.js-131 removed
1var _native = (function () {2 var _options = {}3 var _construct = function (e) {4 var defaultOptions = {5 carbonZoneKey: '',6 fallback: '',7 ignore: 'false',8 placement: '',9 prefix: 'native',10 targetClass: 'native-ad'11 }1213 if (typeof e === 'undefined') return defaultOptions14 Object.keys(defaultOptions).forEach((key, index) => {15 if (typeof e[key] === 'undefined') {16 e[key] = defaultOptions[key]17 }18 })19 return e20 }2122 var init = function (zone, options) {23 _options = _construct(options)2425 let jsonUrl = `https://srv.buysellads.com/ads/${zone}.json?callback=_native_go`26 if (_options['placement'] !== '') {27 jsonUrl += '&segment=placement:' + _options['placement']28 }29 if (_options['ignore'] === 'true') {30 jsonUrl += '&ignore=yes'31 }3233 let srv = document.createElement('script')34 srv.src = jsonUrl35 document.getElementsByTagName('head')[0].appendChild(srv)36 }3738 var carbon = function (e) {39 let srv = document.createElement('script')40 srv.src = '//cdn.carbonads.com/carbon.js?serve=' + e['carbonZoneKey'] + '&placement=' + e['placement']41 srv.id = '_carbonads_js'4243 return srv44 }4546 var sanitize = function (ads) {47 return ads48 .filter(ad => {49 return Object.keys(ad).length > 050 })51 .filter(ad => {52 return ad.hasOwnProperty('statlink')53 })54 }5556 var pixel = function (p, timestamp) {57 let c = ''58 if (p) {59 p.split('||').forEach((pixel, index) => {60 c += `<img src="${pixel.replace('[timestamp]', timestamp)}" style="display:none;" height="0" width="0" />`61 })62 }63 return c64 }6566 var options = function () {67 return _options68 }6970 return {71 carbon: carbon,72 init: init,73 options: options,74 pixel: pixel,75 sanitize: sanitize76 }77})({})7879var _native_go = function (json) {80 let options = _native.options()81 let ads = _native.sanitize(json['ads'])82 let selectedClass = document.querySelectorAll('.' + options['targetClass'])8384 if (ads.length < 1) {85 selectedClass.forEach((className, index) => {86 let selectedTarget = document.getElementsByClassName(options['targetClass'])[index]8788 if (options['fallback'] !== '' || options['carbonZoneKey'] !== '') selectedTarget.setAttribute('data-state', 'visible')89 selectedTarget.innerHTML = options['fallback']90 if (options['carbonZoneKey'] !== '') selectedTarget.appendChild(_native.carbon(options))91 })9293 // End at this line if no ads are found, avoiding unnecessary steps94 return95 }9697 selectedClass.forEach((className, index) => {98 let selectedTarget = document.getElementsByClassName(options['targetClass'])[index]99 let adElement = selectedTarget.innerHTML100 let prefix = options['prefix']101 let ad = ads[index]102103 if (ad && className) {104 let adInnerHtml = adElement105 .replace(new RegExp('#' + prefix + '_bg_color#', 'g'), ad['backgroundColor'])106 .replace(new RegExp('#' + prefix + '_bg_color_hover#', 'g'), ad['backgroundHoverColor'])107 .replace(new RegExp('#' + prefix + '_company#', 'g'), ad['company'])108 .replace(new RegExp('#' + prefix + '_cta#', 'g'), ad['callToAction'])109 .replace(new RegExp('#' + prefix + '_cta_bg_color#', 'g'), ad['ctaBackgroundColor'])110 .replace(new RegExp('#' + prefix + '_cta_bg_color_hover#', 'g'), ad['ctaBackgroundHoverColor'])111 .replace(new RegExp('#' + prefix + '_cta_color#', 'g'), ad['ctaTextColor'])112 .replace(new RegExp('#' + prefix + '_cta_color_hover#', 'g'), ad['ctaTextColorHover'])113 .replace(new RegExp('#' + prefix + '_desc#', 'g'), ad['description'])114 .replace(new RegExp('#' + prefix + '_index#', 'g'), prefix + '-' + ad['i'])115 .replace(new RegExp('#' + prefix + '_img#', 'g'), ad['image'])116 .replace(new RegExp('#' + prefix + '_small_img#', 'g'), ad['smallImage'])117 .replace(new RegExp('#' + prefix + '_link#', 'g'), ad['statlink'])118 .replace(new RegExp('#' + prefix + '_logo#', 'g'), ad['logo'])119 .replace(new RegExp('#' + prefix + '_color#', 'g'), ad['textColor'])120 .replace(new RegExp('#' + prefix + '_color_hover#', 'g'), ad['textColorHover'])121 .replace(new RegExp('#' + prefix + '_title#', 'g'), ad['title'])122123 selectedTarget.innerHTML = null124 selectedTarget.innerHTML += adInnerHtml + _native.pixel(ad['pixel'], ad['timestamp'])125 selectedTarget.setAttribute('data-state', 'visible')126 } else {127 selectedTarget.innerHTML = null128 selectedTarget.style.display = 'none'129 }130 })131}
modified:docs/_templates/hacks.html+38 added-31 removed
55 unmodified lines
56<!-- That was not a hack. That was art. -->5758<!-- Native CPC by BuySellAds -->5960<script src="{{ pathto('_static/', 1) }}/native.js"></script>61<script>62 _native.init("CK7D62JU", {63 targetClass: 'native-js'64 });65</script>60<script type="text/javascript" src="//m.servedby-buysellads.com/monetization.js"></script>6167<div class="native-js">68 <div class="native-sponsor">Sponsored Ad by #native_company# — Learn More</div>69 <a href="#native_link#" class="native-flex">62<div id="native-ribbon">63</div>6465<script>66_bsa.init('custom', 'CK7D62JU', 'placement:pythonrequestsorg',67 {68 target: '#native-ribbon',69 template: `70<div class="native-sponsor">Sponsored by ##company## — Learn More</div>71 <a href="##link##" class="native-flex">72 <style>71 .native-js {72 background: linear-gradient(-30deg, #native_bg_color#E5, #native_bg_color#E5 45%, #native_bg_color# 45%) #fff;73 }73 #native-ribbon #_custom_ {74 background: linear-gradient(-30deg, ##backgroundColor##E5, ##backgroundColor##E5 45%, ##backgroundColor## 45%) #fff;75 }7675 .native-details,76 .native-sponsor {77 color: #native_color# !important;78 }77 .native-details,78 .native-sponsor,79 .native-bsa {80 color: ##textColor## !important;81 }8280 .native-details:hover {81 color: #native_color_hover# !important;82 }83 .native-details:hover {84 color: ##textColorHover## !important;85 }8684 .native-cta {85 color: #native_cta_color#;86 background-color: #native_cta_bg_color#;87 }87 .native-cta {88 color: ##ctaTextColor##;89 background-color: ##ctaBackgroundColor##;90 }9189 .native-cta:hover {90 color: #native_cta_color_hover;91 background-color: #native_cta_bg_color_hover#;92 }92 .native-cta:hover {93 color: ##ctaTextColorHover##;94 background-color: ##ctaBackgroundColorHover##;95 }96 </style>97 <div class="native-main">95 <img class="native-img" src="#native_logo#">98 <img class="native-img" src="##logo##">99 <div class="native-details">97 <span class="native-company">#native_title#</span>98 <span class="native-desc">#native_desc#</span>100 <span class="native-company">##title##</span>101 <span class="native-desc">##description##</span>102 </div>100 <span class="native-cta">#native_cta#</span>103 </div>104 <span class="native-cta">##callToAction##</span>105 </a>106</div>107`108 }109 );110</script>
modified:docs/_templates/sidebarintro.html+1 added-37 removed
67 unmodified lines
68 <li><a href="http://it.python-requests.org/">Italian</a></li>69 <li><a href="http://es.python-requests.org/">Spanish</a></li>70</ul>7172<div class="native-js">73 <div class="native-sponsor">Sponsored by #native_company# — Learn More</div>74 <a href="#native_link#" class="native-flex">75 <style>76 .native-js {77 background: linear-gradient(-30deg, #native_bg_color#E5, #native_bg_color#E5 45%, #native_bg_color# 45%) #fff;78 }7980 .native-details,81 .native-sponsor,82 .native-bsa {83 color: #native_color# !important;84 }8586 .native-details:hover {87 color: #native_color_hover# !important;88 }8990 .native-cta {91 color: #native_cta_color#;92 background-color: #native_cta_bg_color#;93 }9495 .native-cta:hover {96 color: #native_cta_color_hover;97 background-color: #native_cta_bg_color_hover#;98 }99 </style>100 <div class="native-main">101 <img class="native-img" src="#native_logo#">102 <div class="native-details">103 <span class="native-company">#native_title#</span>104 <span class="native-desc">#native_desc#</span>105 </div>106 </div>107 <span class="native-cta">#native_cta#</span>108 </a>72<div id="native-ribbon">73</div>