deno.land / x / mongoose@6.7.5 / docs / js / native.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';var _native = { construct: function(e) { var default_options = { display: "block", fallback: "", placement: "", prefix: "native", targetClass: "native-ad", visibleClass: "native-show" };
if (typeof e == "undefined") return default_options; Object.keys(default_options).forEach((key, index) => { if (typeof e[key] == "undefined") { e[key] = default_options[key]; } }); return e; }, init: function(zone, options) { options = this.construct(options); this.className = options["targetClass"]; this.displayStyle = options["display"]; this.fallback = options["fallback"]; this.visibleClassName = options["visibleClass"]; this.prefix = options["prefix"]; this.placement = options["placement"];
let jsonUrl = `https://srv.buysellads.com/ads/${zone}.json?callback=_native_go`; if (options["placement"] !== "") { jsonUrl += "&segment=placement:" + options["placement"]; }
let srv = document.createElement("script"); srv.src = jsonUrl; document.getElementsByTagName("head")[0].appendChild(srv); }, sanitize: function(ads) { return ads .filter(ad => { return Object.keys(ad).length > 0; }) .filter(ad => { return ad.hasOwnProperty("statlink"); }); }, pixel: function(p, timestamp) { let c = ""; if (p) p.split("||").forEach((pixel, index) => { c += '<img src="' + pixel.replace("[timestamp]", timestamp) + '" style="display:none;" height="0" width="0" />'; }); return c; }};
var _native_go = function(json) { let ads = _native.sanitize(json["ads"]);
if (ads.length < 1) { document.querySelectorAll("." + _native.className).forEach((className, index) => { document.getElementsByClassName(_native.className)[index].innerHTML = _native.fallback; if (_native.fallback !== "") document.getElementsByClassName(_native.className)[index].className += " " + _native.visibleClassName; });
return "No ads found"; }
document.querySelectorAll("." + _native.className).forEach((className, index) => { if (ads[index] && className) { let adElement = document.getElementsByClassName(_native.className)[index].innerHTML;
let ad = adElement .replace(new RegExp("#" + _native.prefix + "_bg_color#", "g"), ads[index]["backgroundColor"]) .replace(new RegExp("#" + _native.prefix + "_bg_color_hover#", "g"), ads[index]["backgroundHoverColor"]) .replace(new RegExp("#" + _native.prefix + "_company#", "g"), ads[index]["company"]) .replace(new RegExp("#" + _native.prefix + "_cta#", "g"), ads[index]["callToAction"]) .replace(new RegExp("#" + _native.prefix + "_cta_bg_color#", "g"), ads[index]["ctaBackgroundColor"]) .replace(new RegExp("#" + _native.prefix + "_cta_bg_color_hover#", "g"), ads[index]["ctaBackgroundHoverColor"]) .replace(new RegExp("#" + _native.prefix + "_cta_color#", "g"), ads[index]["ctaTextColor"]) .replace(new RegExp("#" + _native.prefix + "_cta_color_hover#", "g"), ads[index]["ctaTextColorHover"]) .replace(new RegExp("#" + _native.prefix + "_desc#", "g"), ads[index]["description"]) .replace(new RegExp("#" + _native.prefix + "_index#", "g"), _native.prefix + "-" + ads[index]["i"]) .replace(new RegExp("#" + _native.prefix + "_img#", "g"), ads[index]["image"]) .replace(new RegExp("#" + _native.prefix + "_link#", "g"), ads[index]["statlink"]) .replace(new RegExp("#" + _native.prefix + "_logo#", "g"), ads[index]["logo"]) .replace(new RegExp("#" + _native.prefix + "_color#", "g"), ads[index]["textColor"]) .replace(new RegExp("#" + _native.prefix + "_color_hover#", "g"), ads[index]["textColorHover"]) .replace(new RegExp("#" + _native.prefix + "_title#", "g"), ads[index]["title"]);
document.getElementsByClassName(_native.className)[index].innerHTML = null; document.getElementsByClassName(_native.className)[index].innerHTML += ad + _native.pixel(ads[index]["pixel"], ads[index]["timestamp"]); document.getElementsByClassName(_native.className)[index].style.display = _native.displayStyle; if (_native.className !== "") document.getElementsByClassName(_native.className)[index].className += " " + _native.visibleClassName; } else { document.getElementsByClassName(_native.className)[index].innerHTML = null; document.getElementsByClassName(_native.className)[index].style.display = "none"; } });};
mongoose

Version Info

Tagged at
a year ago