1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | function injectSnippet(scriptURL, backupScriptURL) {
|
7 | (function (w, d, s, c, f, n, t, g, a, b, l) {
|
8 |
|
9 |
|
10 | w.PactSafeObject = n;
|
11 | w[n] = w[n] || function () {
|
12 | (w[n].q = w[n].q || []).push(arguments);
|
13 | }, w[n].on = function () {
|
14 |
|
15 | (w[n].e = w[n].e || []).push(arguments);
|
16 | }, w[n].once = function () {
|
17 | (w[n].eo = w[n].eo || []).push(arguments);
|
18 | }, w[n].off = function () {
|
19 | (w[n].o = w[n].o || []).push(arguments);
|
20 | }, w[n].t = 1 * new Date(), w[n].l = 0;
|
21 |
|
22 |
|
23 | a = d.createElement(s);
|
24 | b = d.getElementsByTagName(s)[0];
|
25 | a.async = 1;
|
26 | a.src = c;
|
27 |
|
28 |
|
29 | a.onload = a.onreadystatechange = function () {
|
30 | w[n].l = 1;
|
31 | };
|
32 | a.onerror = a.onabort = function () {
|
33 | w[n].l = 0;
|
34 | };
|
35 |
|
36 |
|
37 | if (b) {
|
38 | b.parentNode.insertBefore(a, b);
|
39 | } else {
|
40 | document.body.appendChild(a);
|
41 | }
|
42 |
|
43 |
|
44 | setTimeout(function () {
|
45 | if (!w[n].l && !w[n].loaded) {
|
46 | w[n].error = 1;
|
47 | a = d.createElement(s);
|
48 | a.async = 1;
|
49 | a.src = f;
|
50 | a.onload = a.onreadystatechange = function () {
|
51 | w[n].l = 1;
|
52 | };
|
53 | a.onerror = a.onabort = function () {
|
54 | w[n].l = 0;
|
55 | };
|
56 | b.parentNode.insertBefore(a, b);
|
57 |
|
58 |
|
59 | l = function l(u, e) {
|
60 | try {
|
61 | e = d.createElement("img");
|
62 | e.src = "https://d3r8bdci515tjv.cloudfront.net/error.gif?t=" + w[n].t + "&u=" + encodeURIComponent(u);
|
63 | d.getElementsByTagName("body")[0].appendChild(e);
|
64 | } catch (x) {}
|
65 | };
|
66 | l(c);
|
67 |
|
68 |
|
69 | setTimeout(function () {
|
70 | if (!w[n].l && !w[n].loaded) {
|
71 | w[n].error = 1;
|
72 | if (g && "function" == typeof g) {
|
73 | g.call(this);
|
74 | }
|
75 | l(f);
|
76 | }
|
77 | }, t);
|
78 | }
|
79 | }, t);
|
80 | })(window, document, "script", scriptURL, backupScriptURL, "_ps", 4000, function optionalErrorCallback() {
|
81 | console.log("Unable to load the PactSafe PS.JS Library.");
|
82 | });
|
83 | }
|
84 |
|
85 | function isSnippetLoaded(psScriptURL) {
|
86 | var scripts = document.getElementsByTagName('script');
|
87 | if (window._ps && window._ps.loaded && window._ps.realThang === 317) return true;
|
88 | for (var i = 0; i < scripts.length; i += 1) {
|
89 | if (scripts[i].src.indexOf(psScriptURL) !== -1) {
|
90 | return true;
|
91 | }
|
92 | }
|
93 | return false;
|
94 | }
|
95 |
|
96 | module.exports = {
|
97 | injectSnippet: injectSnippet,
|
98 | isSnippetLoaded: isSnippetLoaded
|
99 | }; |
\ | No newline at end of file |