PageSourceSearch

http://newevangelization.net/js/parentd052.js

js newevangelization.net collected 2026-09-28 03:46:09 UTC 13,118 bytes, 394 lines download raw bytes

1document.addEventListener("DOMContentLoaded", () => {
2  waitforiFrameResize = setInterval(function () {
3    if (typeof iFrameResize == "undefined") {
4      //console.log('waiting for iframe resize');
5      return;
6    }
7    //console.log('iframe resize ready');
8    clearInterval(waitforiFrameResize);
9    // iFrameResize();
10    var polllist = {};
11    window.addEventListener("message", receiveMessage, false);
12    if (Sgpolls.jsOptions.jspollsSeparate) {
13      sgSeparate();
14    }
15    let pud = localStorage.getItem("permutive-id");
16    let survey_url = localStorage.getItem("new-survey-url");
17    if (
18      typeof permutive != "undefined" &&
19      typeof permutive.context != "undefined" &&
20      typeof permutive.context.user_id != "undefined"
21    ) {
22      pud = permutive.context.user_id;
23      localStorage.setItem("permutive-id", pud);
24      localStorage.setItem("nsmspollspud", pud);
25    }
26
27    if (pud && !survey_url) {
28      // console.log('pud value is : ');
29      // console.log(pud);
30
31      for (var i in Sgpolls.polls) {
32        buildIframe(Sgpolls.polls[0] + "?permutive_user_id=" + pud, i);
33      }
34    } else if(pud && survey_url) {
35
36      buildIframe(survey_url + "?permutive_user_id=" + pud, i);
37      
38    } else {
39      //console.log('here..');
40      for (var i in Sgpolls.polls) {
41        buildIframe(Sgpolls.polls[0], i);
42      }
43    }
44
45    function buildIframe(block, ifid) {
46      if (jQuery("#Sgpollsputhere").not(":first").length) {
47        jQuery("#Sgpollsputhere").not(":first").remove();
48      }
49      if (typeof block != "string") {
50        return;
51      }
52      polllist[block] = {
53        index: Sgpolls.polls.indexOf(block),
54        src: block,
55      };
56      // alert(ifid);
57      var iframeblock =
58        '<iframe class="polls-iframe" src="' +
59        block +
60        '&r=true" scrolling="no" frameborder="0" width="100%" id="iframeid-' +
61        ifid +
62        '"></iframe>';
63      jQuery("#pollstoshow").append(
64        '<li data-src="' + block + '&r=true">' + block + "&r=true</li>"
65      );
66
67      jQuery("#Sgpollsputhere").append(iframeblock);
68      //  jQuery('#Sgpollsputhere').css('height', '20%');
69      jQuery("#Sgpollscstyle").remove();
70    }
71
72    // Function to get user's IP address
73    async function getUserIP() {
74      try {
75          const response = await fetch('https://api.ipify.org/?format=json');
76          const data = await response.json();
77          return data.ip;
78      } catch (error) {
79          console.error('Error fetching IP:', error);
80          return null;
81      }
82    }
83
84    // Utility function to set a cookie
85    function setCookie(name, value, days) {
86      const date = new Date();
87      date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
88      document.cookie = `${name}=${JSON.stringify(value)};expires=${date.toUTCString()};path=/`;
89    }
90
91    // Utility function to get a cookie
92    function getCookie(name) {
93      const cookies = document.cookie.split("; ");
94      for (let cookie of cookies) {
95        const [key, value] = cookie.split("=");
96        if (key === name) {
97          return JSON.parse(value);
98        }
99      }
100      return null;
101    }
102
103    // Function to handle survey logic
104    async function handleSurvey() {
105      try {
106        // Fetch user's IP address
107        const userIP = await getUserIP();
108        if (!userIP) {
109          console.error("Unable to fetch user IP");
110          return;
111        }
112
113        // Get the current survey ID
114        let surveyBlock = Sgpolls.polls[0];
115        // Check if the survey URL is already stored in localStorage
116        let get_survey_url = localStorage.getItem("new-survey-url");
117        if(get_survey_url){
118          surveyBlock = get_survey_url;
119        }
120        //console.log("current survey: "+surveyBlock);
121        const surveyId = surveyBlock.split("index-838.html")[1].split("index.html")[0];
122
123        // Check if cookie exists
124        let surveyData = getCookie("surveyData");
125
126        if (!surveyData) {
127          // Initialize cookie if not present
128          surveyData = { ip: userIP, surveyId: surveyId, visitCount: 0 };
129        }
130
131        // Check if the user has already visited this survey
132        if (surveyData.ip === userIP && surveyData.surveyId === surveyId) {
133          surveyData.visitCount += 1;
134          if (surveyData.visitCount > 2) {
135            // Update to the next survey ID
136            console.log(Sgpolls.polls);
137            const nextSurveyIndex = Sgpolls.polls.indexOf(surveyBlock) + 1;
138            console.log("next survey: "+nextSurveyIndex + " total length: "+Sgpolls.polls.length);
139            if (nextSurveyIndex < Sgpolls.polls.length) {
140              //alert("Surveyindex"+nextSurveyIndex+"its entering the if part if visit count is greater than 2");
141              surveyData.surveyId = Sgpolls.polls[nextSurveyIndex].split("index-838.html")[1].split("index.html")[0];
142              // Build iframe with updated survey ID
143              const updatedSurveyURL = `${Sgpolls.polls.find((poll) =>
144                poll.includes(surveyData.surveyId)
145              )}?permutive_user_id=${localStorage.getItem("permutive-id") || ""}`;
146              const nextSurveyURL = `${Sgpolls.polls.find((poll) =>
147                poll.includes(surveyData.surveyId)
148              )}`;
149              localStorage.setItem("new-survey-url", nextSurveyURL);
150              surveyData.visitCount = 0;
151            } else {
152              console.log("No more surveys available.");
153              return;
154            }
155          }
156        } else {
157          // Reset visit count for a new survey
158          surveyData.surveyId = surveyId;
159          surveyData.visitCount = 1;
160        }
161
162        // Update the cookie
163        setCookie("surveyData", surveyData, 7);
164        //console.log("next survey:"+updatedSurveyURL);
165        //buildIframe(updatedSurveyURL, surveyData.surveyId);
166      } catch (error) {
167        console.error("Error handling survey:", error);
168      }
169    }
170
171    handleSurvey();
172  // johan - code changes starts here
173  // listen for data from the alchemer content for iframe content height
174  window.addEventListener("message", (event) => {
175    if (
176      event.origin === "https://survey.alchemer.eu" ||
177      event.origin === "https://www.surveygizmo.eu/"
178    ) {
179      if (event.data.height) {
180        
181        const iframePolls = document.querySelectorAll(".polls-iframe"); // select the iframe
182
183        iframePolls &&
184          iframePolls.forEach((elem, index) => {
185            if (index === 0) {
186              elem.height = event.data.height + 30; // since the first frame is only visible we are taking the first to set height
187              const sgPolls = document.getElementById("Sgpollsputhere"); // setting height for the outer container
188              sgPolls.style = `${event.data.height + 30}px`;
189              if (!event.data["isLastPage"]) {
190                jQuery("#Sgpollsputhere iframe").css("height", elem.height);
191              }
192            } else {
193              elem.style.visibility = "hidden";
194            }
195          });
196      }
197    }
198  });
199
200    // johan code changes ends here
201
202
203    // intEnsureIsResized = setInterval(function () {
204    //     if (!jQuery('.sgloaded').length) {
205    //         //console.log('waiting for .sgloaded');
206    //         return;
207    //     }
208    //     if (jQuery('.sgloaded').height() > 0) {
209    //         //console.log('sgloaded ok');
210    //         clearInterval(intEnsureIsResized);
211    //         return;
212    //     }
213    //     //console.log(jQuery('.sgloaded').height());
214    //     var src = jQuery('.sgloaded').eq(0).attr('src');
215    //     // console.log('src ' + src + ' not loaded');
216    //     // console.log('reloading');
217    //     jQuery('.sgloaded').removeAttr('src');
218    //     jQuery('.sgloaded').attr('src', src);
219    //     iFrameResize();
220    // }, 3000);
221    intOrdering = setInterval(function () {
222      qty = 7;
223      parts = [
224        ".entry-content",
225        ".c-post-single__content",
226        ".article-body .cell:last-of-type",
227      ];
228      for (var i in parts) {
229        if (!jQuery(parts[i]).length) {
230          continue;
231        }
232        part = jQuery(parts[i]).eq(0);
233        if (part.find(">p").length < qty) {
234          qty = part.find(">p").length + 1;
235        } else {
236          /*console.log(part.find('>p').length);*/
237        }
238      }
239      if (typeof part != "undefined") {
240        part.find(">p").eq(qty).after(jQuery("#Sgpollsputhere"));
241        clearInterval(intOrdering);
242      }
243    }, 2000);
244    intDupeRemove = setInterval(function () {
245      jQuery('p>iframe[src*="surveygizmo"]').remove();
246      jQuery("#Sgpollsputhere").not(":first").remove();
247    }, 2000);
248    intIfrWait = setInterval(function () {
249      if (jQuery(".sgloaded").length) {
250        var loadedpoll = {
251          src: jQuery(".sgloaded").attr("src"),
252          answers: "false",
253        };
254        jQuery("#Sgpollscstyle").remove();
255        if (Sgpolls.jsOptions.jspollsCalc == "1") {
256          permutiveSend(loadedpoll);
257          //console.log('counted');
258        } else {
259          //console.log('not counted');
260          jQuery(".sgloaded").eq(0).attr("id", "sgPollIframe");
261        }
262        clearInterval(intIfrWait);
263      }
264    }, 3500);
265    function receiveMessage(event) {
266      if (event.data == "formsubmit") {
267        jQuery(".sgloaded").css("visibility", "hidden");
268      } else {
269        setTimeout(function () {
270          jQuery(".sgloaded").css("visibility", "visible");
271          // jQuery(".sgloaded").css("height", "100%");
272        }, 2000);
273      }
274      if (typeof event.data["sg"] === "undefined") {
275        return;
276      }
277      surveysrc = event.data["sg"];
278      // console.log('received message from ' + surveysrc);
279      //polllist[surveysrc].message = true;
280      iframesrc = '#Sgpollsputhere iframe[src="' + surveysrc + '"]';
281      jQuery(iframesrc).addClass("sgloaded");
282      jQuery(iframesrc).attr("id", "tmpClass");
283      sendMessage("tmpClass");
284      jQuery(iframesrc).removeAttr("id");
285      iframeDisplay();
286      if (event.data["isLastPage"]) {
287        permutiveSend({ src: surveysrc, answers: event.data.submissions });
288      }
289      sgreport(polllist);
290    }
291    function iframeDisplay() {
292      if (typeof idisplay != "undefined") {
293        clearTimeout(idisplay);
294      }
295      idisplay = setTimeout(function () {
296        jQuery("#Sgpollsputhere iframe")
297          .not(".sgloaded")
298          .each(function () {
299            $src = jQuery(this).attr("src");
300            //polllist[$src].hidden = true;
301            jQuery(this).remove();
302          });
303        jQuery("#Sgpollsputhere .sgloaded")
304          .not(":first")
305          .each(function () {
306            $src = jQuery(this).attr("src");
307            //polllist[$src].hidden = true;
308            jQuery(this).remove();
309          });
310        // iFrameResize();
311      }, 3500);
312    }
313    function sgreport(list) {
314      if (typeof sgreporttimeout != "undefined") {
315        clearTimeout(sgreporttimeout);
316      }
317      sgreporttimeout = setTimeout(function () {
318        var report = {};
319        for (var i in Sgpolls.polls) {
320          report[i] = list[Sgpolls.polls[i]];
321        }
322        //console.log(report);
323      }, 5000);
324    }
325    function sendMessage(id) {
326      let css = Sgpolls.css.replace(/\\(.)/gm, "$1");
327      css = css.replace("__LOGO__", jQuery('img[itemprop="logo"]').attr("src"));
328      if (typeof Sgpolls.css != "string") {
329        return;
330      }
331      if (!jQuery("#" + id).length) {
332        return;
333      }
334      var targetFrame = document.getElementById(id).contentWindow;
335      targetFrame.postMessage({ css: css }, "*");
336      window.pollframe = targetFrame;
337    }
338
339    function permutiveSend(survey) {
340      if (typeof permutive == "undefined") {
341        //console.log('Permutive not found');
342        return;
343      }
344      var options = {
345        success: function (event) {},
346        error: function (errors) {
347          //console.log(errors);
348        },
349      };
350      var date = new Date();
351      var evalues = {
352        sg: Sgpolls.options,
353      };
354
355      evalues.sg.title = document.title;
356      evalues.sg.time = date.toISOString();
357      evalues.sg.answers = survey.answers;
358      evalues.sg.source = survey.src;
359      //delete evalues.sg.css;
360      permutive.track("sgPoll", evalues, options);
361    }
362  }, 100);
363});
364
365function sgSeparate() {
366  let pollsnotseparated = { odd: [], even: [] };
367  let pollsseparated = [];
368  checkpatt = /all-sites|all-websites|t-t-poll/;
369  for (i = 0; i <= Sgpolls.polls.length; i++) {
370    if (typeof Sgpolls.polls[i] == "undefined") {
371      continue;
372    }
373    poll = Sgpolls.polls[i].toLowerCase();
374    if (checkpatt.test(poll)) {
375      key = "odd";
376    } else {
377      key = "even";
378    }
379    pollsnotseparated[key].push(Sgpolls.polls[i]);
380  }
381  // console.log(pollsnotseparated);
382  keys = ["even", "odd"];
383  while (
384    pollsnotseparated[keys[0]].length > 0 ||
385    pollsnotseparated[keys[1]].length > 0
386  ) {
387    keys = keys.reverse();
388    if (pollsnotseparated[keys[0]].length > 0) {
389      pollsseparated.push(pollsnotseparated[keys[0]].pop());
390    }
391  }
392  Sgpolls.polls = pollsseparated;
393}
394// 2.0b

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.