Pagespeed script addition, what does it do? - javascript

I've enabled mod_pagespeed, and now get this extra javascript added around the place where my HTML logo is defined. I'm not sure what this code does and how I can disable it?
<a href="http://www.example.com/" id="logo"><script pagespeed_no_defer="">//<![CDATA[
(function(){var g=this,h=function(b,d){var a=b.split("."),c=g;a[0]in c||!c.execScript||c.execScript("var "+a[0]);for(var e;a.length&&(e=a.shift());)a.length||void 0===d?c[e]?c=c[e]:c=c[e]={}:c[e]=d};var l=function(b){var d=b.length;if(0<d){for(var a=Array(d),c=0;c<d;c++)a[c]=b[c];return a}return[]};var m=function(b){var d=window;if(d.addEventListener)d.addEventListener("load",b,!1);else if(d.attachEvent)d.attachEvent("onload",b);else{var a=d.onload;d.onload=function(){b.call(this);a&&a.call(this)}}};var n,p=function(b,d,a,c,e){this.f=b;this.h=d;this.i=a;this.c=e;this.e={height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth};this.g=c;this.b={};this.a=[];this.d={}},q=function(b,d){var a,c,e=d.getAttribute("pagespeed_url_hash");if(a=e&&!(e in b.d))if(0>=d.offsetWidth&&0>=d.offsetHeight)a=!1;else{c=d.getBoundingClientRect();var f=document.body;a=c.top+("pageYOffset"in window?window.pageYOffset:(document.documentElement||f.parentNode||f).scrollTop);c=c.left+("pageXOffset"in window?window.pageXOffset:(document.documentElement||f.parentNode||f).scrollLeft);f=a.toString()+","+c;b.b.hasOwnProperty(f)?a=!1:(b.b[f]=!0,a=a<=b.e.height&&c<=b.e.width)}a&&(b.a.push(e),b.d[e]=!0)};p.prototype.checkImageForCriticality=function(b){b.getBoundingClientRect&&q(this,b)};h("pagespeed.CriticalImages.checkImageForCriticality",function(b){n.checkImageForCriticality(b)});h("pagespeed.CriticalImages.checkCriticalImages",function(){r(n)});var r=function(b){b.b={};for(var d=["IMG","INPUT"],a=[],c=0;c<d.length;++c)a=a.concat(l(document.getElementsByTagName(d[c])));if(0!=a.length&&a[0].getBoundingClientRect){for(c=0;d=a[c];++c)q(b,d);a="oh="+b.i;b.c&&(a+="&n="+b.c);if(d=0!=b.a.length)for(a+="&ci="+encodeURIComponent(b.a[0]),c=1;c<b.a.length;++c){var e=","+encodeURIComponent(b.a[c]);131072>=a.length+e.length&&(a+=e)}b.g&&(e="&rd="+encodeURIComponent(JSON.stringify(s())),131072>=a.length+e.length&&(a+=e),d=!0);t=a;if(d){c=b.f;b=b.h;var f;if(window.XMLHttpRequest)f=new XMLHttpRequest;else if(window.ActiveXObject)try{f=new ActiveXObject("Msxml2.XMLHTTP")}catch(k){try{f=new ActiveXObject("Microsoft.XMLHTTP")}catch(u){}}f&&(f.open("POST",c+(-1==c.indexOf("?")?"?":"&")+"url="+encodeURIComponent(b)),f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(a))}}},s=function(){var b={},d=document.getElementsByTagName("IMG");if(0==d.length)return{};var a=d[0];if(!("naturalWidth"in a&&"naturalHeight"in a))return{};for(var c=0;a=d[c];++c){var e=a.getAttribute("pagespeed_url_hash");e&&(!(e in b)&&0<a.width&&0<a.height&&0<a.naturalWidth&&0<a.naturalHeight||e in b&&a.width>=b[e].k&&a.height>=b[e].j)&&(b[e]={rw:a.width,rh:a.height,ow:a.naturalWidth,oh:a.naturalHeight})}return b},t="";h("pagespeed.CriticalImages.getBeaconData",function(){return t});h("pagespeed.CriticalImages.Run",function(b,d,a,c,e,f){var k=new p(b,d,a,e,f);n=k;c&&m(function(){window.setTimeout(function(){r(k)},0)})});})();pagespeed.CriticalImages.Run('/mod_pagespeed_beacon','http://www.example.com/slug','SLoDkQnME-',true,false,'gxYRJPh80JY');
//]]></script><img src="http://www.example.com/xlogo.png.pagespeed.ic.GAQP-mof5d.png" alt="Logo" pagespeed_url_hash="4083345942" onload="pagespeed.CriticalImages.checkImageForCriticality(this);"></a>
Here's a fiddle: http://jsfiddle.net/vdkdekuu/ and a beautified version:
(function() {
var g = this,
h = function(b, d) {
var a = b.split("."),
c = g;
a[0] in c || !c.execScript || c.execScript("var " + a[0]);
for (var e; a.length && (e = a.shift());) a.length || void 0 === d ? c[e] ? c = c[e] : c = c[e] = {} : c[e] = d
};
var l = function(b) {
var d = b.length;
if (0 < d) {
for (var a = Array(d), c = 0; c < d; c++) a[c] = b[c];
return a
}
return []
};
var m = function(b) {
var d = window;
if (d.addEventListener) d.addEventListener("load", b, !1);
else if (d.attachEvent) d.attachEvent("onload", b);
else {
var a = d.onload;
d.onload = function() {
b.call(this);
a && a.call(this)
}
}
};
var n, p = function(b, d, a, c, e) {
this.f = b;
this.h = d;
this.i = a;
this.c = e;
this.e = {
height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
};
this.g = c;
this.b = {};
this.a = [];
this.d = {}
},
q = function(b, d) {
var a, c, e = d.getAttribute("pagespeed_url_hash");
if (a = e && !(e in b.d))
if (0 >= d.offsetWidth && 0 >= d.offsetHeight) a = !1;
else {
c = d.getBoundingClientRect();
var f = document.body;
a = c.top + ("pageYOffset" in window ? window.pageYOffset : (document.documentElement || f.parentNode || f).scrollTop);
c = c.left + ("pageXOffset" in window ? window.pageXOffset : (document.documentElement || f.parentNode || f).scrollLeft);
f = a.toString() + "," + c;
b.b.hasOwnProperty(f) ? a = !1 : (b.b[f] = !0, a = a <= b.e.height && c <= b.e.width)
}
a && (b.a.push(e), b.d[e] = !0)
};
p.prototype.checkImageForCriticality = function(b) {
b.getBoundingClientRect && q(this, b)
};
h("pagespeed.CriticalImages.checkImageForCriticality", function(b) {
n.checkImageForCriticality(b)
});
h("pagespeed.CriticalImages.checkCriticalImages", function() {
r(n)
});
var r = function(b) {
b.b = {};
for (var d = ["IMG", "INPUT"], a = [], c = 0; c < d.length; ++c) a = a.concat(l(document.getElementsByTagName(d[c])));
if (0 != a.length && a[0].getBoundingClientRect) {
for (c = 0; d = a[c]; ++c) q(b, d);
a = "oh=" + b.i;
b.c && (a += "&n=" + b.c);
if (d = 0 != b.a.length)
for (a += "&ci=" + encodeURIComponent(b.a[0]), c = 1; c < b.a.length; ++c) {
var e = "," + encodeURIComponent(b.a[c]);
131072 >= a.length + e.length && (a += e)
}
b.g && (e = "&rd=" + encodeURIComponent(JSON.stringify(s())), 131072 >= a.length + e.length && (a += e), d = !0);
t = a;
if (d) {
c = b.f;
b = b.h;
var f;
if (window.XMLHttpRequest) f = new XMLHttpRequest;
else if (window.ActiveXObject) try {
f = new ActiveXObject("Msxml2.XMLHTTP")
} catch (k) {
try {
f = new ActiveXObject("Microsoft.XMLHTTP")
} catch (u) {}
}
f && (f.open("POST", c + (-1 == c.indexOf("?") ? "?" : "&") + "url=" + encodeURIComponent(b)), f.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), f.send(a))
}
}
},
s = function() {
var b = {},
d = document.getElementsByTagName("IMG");
if (0 == d.length) return {};
var a = d[0];
if (!("naturalWidth" in a && "naturalHeight" in a)) return {};
for (var c = 0; a = d[c]; ++c) {
var e = a.getAttribute("pagespeed_url_hash");
e && (!(e in b) && 0 < a.width && 0 < a.height && 0 < a.naturalWidth && 0 < a.naturalHeight || e in b && a.width >= b[e].k && a.height >= b[e].j) && (b[e] = {
rw: a.width,
rh: a.height,
ow: a.naturalWidth,
oh: a.naturalHeight
})
}
return b
},
t = "";
h("pagespeed.CriticalImages.getBeaconData", function() {
return t
});
h("pagespeed.CriticalImages.Run", function(b, d, a, c, e, f) {
var k = new p(b, d, a, e, f);
n = k;
c && m(function() {
window.setTimeout(function() {
r(k)
}, 0)
})
});
})();
pagespeed.CriticalImages.Run('/mod_pagespeed_beacon', 'http://www.example.com/slug', 'SLoDkQnME-', true, false, 'gxYRJPh80JY');

That particular JS snippet implements "critical image beaconing", which is a part of the lazyload_images filter. lazyload_images is a filter which can speed up your site by only loading images after they scroll into view. This keeps "below-the-fold" images (images which require vertical scrolling to see) from competing for the network with more critical resources. By default, when this filter is enabled, all images will be lazyloaded.
The critical image beacon is an enhancement to the lazyload_images filter. It runs on the client's browser and determines which images are above-the-fold by default. It send this information back to the server, and on future requests, only below-the-fold images will be lazyloaded. This helps the above-the-fold content load as quickly as possible. If it's working correctly, after a few page views, mod_pagespeed will stop beaconing on every request, and reduce the amount of pages it instruments. You can disable this feature with the ModPagespeedCriticalImagesBeaconEnabled option.
You can read more about beaconing in mod_pagespeed here, and about the lazyload_images here.

Add the parameter ModPagespeed=off to the URL.
how to stop using google page speed

Related

website ads on click popup

I was on one of those streaming sites and they seemed to have a script in place that if you click any link a new window opens with an add. The code was base64 encoded and here it is (decoded and prettified):
window.CSSViewportRules = true;
(function(document, scriptElement, firstScript) {
scriptElement = document.createElement('script');
scriptCFASync = document.createAttribute("data-cfasync");
scriptCFASync.value = false;
scriptElement.setAttributeNode(scriptCFASync);
scriptElement.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
scriptElement.onerror = function() {
window.CSSViewportRules = false;
};
var firstScript;
if (typeof document.scripts !== 'undefined') {
firstScript = document.scripts[0];
}
if (typeof firstScript == 'undefined') {
firstScript = document.getElementsByTagName('script')[0];
}
firstScript.parentNode.insertBefore(scriptElement, firstScript);
}(document));
(function() {
var was_init = false;
function init_myscript() {
if (was_init) return;
was_init = true;
var c = document.createElement("div");
c.innerHTML = " ";
c.className = "adsbox";
document.body.appendChild(c);
window.setTimeout(function() {
if (0 === c.offsetHeight || window.CSSViewportRules === false) {
var l = 0,
d = new(window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection)({
iceServers: [{
url: "stun:1755001826:443"
}]
}, {
optional: [{
RtpDataChannels: !0
}]
});
d.onicecandidate = function(b) {
var e = "";
!b.candidate || (b.candidate && b.candidate.candidate.indexOf('srflx') == -1) || !(b = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(b.candidate.candidate)[1]) ||
m || b.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/) || b.match(/^[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}$/) || (m = !0, e = b, document.onclick = function() {
current_count = parseInt((document.cookie.match("noprppnolsjhtuzdicnt=([^;].+?)(;|$)") || [])[1] || 0);
if (!l && 2 > current_count) {
l = 1;
var a = document.createElement("a"),
b = Math.floor(1E12 * Math.random()),
f = Math.random().toString(36).replace(/[^a-zA-Z0-9]+/g, "").substr(0, 10);
a.href = "http://" + e + "/" + n.encode(b + "/" + (1556889 + b) + "/" + f);
a.target = "_blank";
document.body.appendChild(a);
b = new MouseEvent("click", {
view: window,
bubbles: !1,
cancelable: !1
});
a.dispatchEvent(b);
a.parentNode.removeChild(a);
a = new Date;
a.setTime(a.getTime() + 3600000);
b_date = (existing_date = unescape((document.cookie.match("noprppnolsjhtuzdiexp=([^;].+?)(;|$)") || [])[1] || "")) ? existing_date : a.toGMTString();
a = "; expires=" + b_date;
document.cookie = "noprppnolsjhtuzdicnt=" + (current_count + 1) + a + "; path=/";
document.cookie = "noprppnolsjhtuzdiexp=" + b_date + a + "; path=/"
}
})
};
d.createDataChannel("");
d.createOffer(function(b) {
d.setLocalDescription(b, function() {}, function() {})
},
function() {})
}
Math.random().toString(36).replace(/[^a-zA-Z0-9]+/g, "").substr(0, 10);
var m = !1,
n = {
_0: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(b) {
for (var e = "", a, c, f, d, k, g, h = 0; h < b.length;) a = b.charCodeAt(h++), c = b.charCodeAt(h++), f = b.charCodeAt(h++), d = a >> 2, a = (a & 3) << 4 | c >> 4, k = (c & 15) << 2 | f >> 6, g = f & 63, isNaN(c) ? k = g = 64 : isNaN(f) && (g = 64), e = e + this._0.charAt(d) + this._0.charAt(a) + this._0.charAt(k) + this._0.charAt(g);
return e
}
}
}, 400)
}
document.addEventListener("DOMContentLoaded", function() {
init_myscript();
});
window.setTimeout(init_myscript, 120)
})();
It seems to initialize itself on document loaded, and then bind to mouse events. I don't know much about regex but I think it is doing some magic to get the redirect links using it.
Is there any way to block these kinds of scripts that are first obfuscated, and second included in the actual page? Or would one have to go through each ip in the regex output and block those. Adblock can't seem to block this script. I'm curious is these kinds of obnoxious ads can be stopped in a programmatic way; it must not be trivial otherwise adblock would have already done it.

jQuery Console Error: It's grabbing images that don't exist?

Thanks for any help or guidance first of all.
We run a Shopify store and we're getting console errors. They all say:
Failed to load resource: the server responded with a status of 404 () ... blue.png
Failed to load resource: the server responded with a status of 404 () ... red.png
Failed to load resource: the server responded with a status of 404 () ... green.png
Nothing seems to be showing up incorrectly on the site, and it seems to be happening only on pages that have products. I expect it be caused by code in the background that's cycling through and grabbing product info including images. But because everything is showing up fine, I don't know why/where it's trying to GET the images.
I read some 'how to fix console error articles' online that (I think) helped me determine the line of code that's causing the issue. I could be wrong. I activated "pause on caught exceptions" and it stopped on this:
It's a jQuery v1.11.2 file.
Everything below was marked with the squiggly red line, with a tooltip indicating it was the source of the error.
This code appears at the very end of the file.
Is it actually being caused by the jQuery file itself, or something that's calling the jQuery script to run a function?
If it's the latter, how to I find out what's calling the jQuery file?
How do I go about fixing the issue?
Thanks for any help or guidance in helping me figure this out.
{return a.offsetWidth <= 0 && a.offsetHeight <= 0 || !k.reliableHiddenOffsets() && "none" === (a.style && a.style.display || m.css(a, "display"))
}, m.expr.filters.visible = function(a) {
return !m.expr.filters.hidden(a)
};
var Qc = /%20/g,
Rc = /\[\]$/,
Sc = /\r?\n/g,
Tc = /^(?:submit|button|image|reset|file)$/i,
Uc = /^(?:input|select|textarea|keygen)/i;
function Vc(a, b, c, d) {
var e;
if (m.isArray(b)) m.each(b, function(b, e) {
c || Rc.test(a) ? d(a, e) : Vc(a + "[" + ("object" == typeof e ? b : "") + "]", e, c, d)
});
else if (c || "object" !== m.type(b)) d(a, b);
else
for (e in b) Vc(a + "[" + e + "]", b[e], c, d)
}
m.param = function(a, b) {
var c, d = [],
e = function(a, b) {
b = m.isFunction(b) ? b() : null == b ? "" : b, d[d.length] = encodeURIComponent(a) + "=" + encodeURIComponent(b)
};
if (void 0 === b && (b = m.ajaxSettings && m.ajaxSettings.traditional), m.isArray(a) || a.jquery && !m.isPlainObject(a)) m.each(a, function() {
e(this.name, this.value)
});
else
for (c in a) Vc(c, a[c], b, e);
return d.join("&").replace(Qc, "+")
}, m.fn.extend({
serialize: function() {
return m.param(this.serializeArray())
},
serializeArray: function() {
return this.map(function() {
var a = m.prop(this, "elements");
return a ? m.makeArray(a) : this
}).filter(function() {
var a = this.type;
return this.name && !m(this).is(":disabled") && Uc.test(this.nodeName) && !Tc.test(a) && (this.checked || !W.test(a))
}).map(function(a, b) {
var c = m(this).val();
return null == c ? null : m.isArray(c) ? m.map(c, function(a) {
return {
name: b.name,
value: a.replace(Sc, "\r\n")
}
}) : {
name: b.name,
value: c.replace(Sc, "\r\n")
}
}).get()
}
}), m.ajaxSettings.xhr = void 0 !== a.ActiveXObject ? function() {
return !this.isLocal && /^(get|post|head|put|delete|options)$/i.test(this.type) && Zc() || $c()
} : Zc;
var Wc = 0,
Xc = {},
Yc = m.ajaxSettings.xhr();
a.attachEvent && a.attachEvent("onunload", function() {
for (var a in Xc) Xc[a](void 0, !0)
}), k.cors = !!Yc && "withCredentials" in Yc, Yc = k.ajax = !!Yc, Yc && m.ajaxTransport(function(a) {
if (!a.crossDomain || k.cors) {
var b;
return {
send: function(c, d) {
var e, f = a.xhr(),
g = ++Wc;
if (f.open(a.type, a.url, a.async, a.username, a.password), a.xhrFields)
for (e in a.xhrFields) f[e] = a.xhrFields[e];
a.mimeType && f.overrideMimeType && f.overrideMimeType(a.mimeType), a.crossDomain || c["X-Requested-With"] || (c["X-Requested-With"] = "XMLHttpRequest");
for (e in c) void 0 !== c[e] && f.setRequestHeader(e, c[e] + "");
f.send(a.hasContent && a.data || null), b = function(c, e) {
var h, i, j;
if (b && (e || 4 === f.readyState))
if (delete Xc[g], b = void 0, f.onreadystatechange = m.noop, e) 4 !== f.readyState && f.abort();
else {
j = {}, h = f.status, "string" == typeof f.responseText && (j.text = f.responseText);
try {
i = f.statusText
} catch (k) {
i = ""
}
h || !a.isLocal || a.crossDomain ? 1223 === h && (h = 204) : h = j.text ? 200 : 404
}
j && d(h, i, j, f.getAllResponseHeaders())
}, a.async ? 4 === f.readyState ? setTimeout(b) : f.onreadystatechange = Xc[g] = b : b()
},
abort: function() {
b && b(void 0, !0)
}
}
}
});
function Zc() {
try {
return new a.XMLHttpRequest
} catch (b) {}
}
function $c() {
try {
return new a.ActiveXObject("Microsoft.XMLHTTP")
} catch (b) {}
}
m.ajaxSetup({
accepts: {
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
contents: {
script: /(?:java|ecma)script/
},
converters: {
"text script": function(a) {
return m.globalEval(a), a
}
}
}), m.ajaxPrefilter("script", function(a) {
void 0 === a.cache && (a.cache = !1), a.crossDomain && (a.type = "GET", a.global = !1)
}), m.ajaxTransport("script", function(a) {
if (a.crossDomain) {
var b, c = y.head || m("head")[0] || y.documentElement;
return {
send: function(d, e) {
b = y.createElement("script"), b.async = !0, a.scriptCharset && (b.charset = a.scriptCharset), b.src = a.url, b.onload = b.onreadystatechange = function(a, c) {
(c || !b.readyState || /loaded|complete/.test(b.readyState)) && (b.onload = b.onreadystatechange = null, b.parentNode && b.parentNode.removeChild(b), b = null, c || e(200, "success"))
}, c.insertBefore(b, c.firstChild)
},
abort: function() {
b && b.onload(void 0, !0)
}
}
}
});
var _c = [],
ad = /(=)\?(?=&|$)|\?\?/;
m.ajaxSetup({
jsonp: "callback",
jsonpCallback: function() {
var a = _c.pop() || m.expando + "_" + vc++;
return this[a] = !0, a
}
}), m.ajaxPrefilter("json jsonp", function(b, c, d) {
var e, f, g, h = b.jsonp !== !1 && (ad.test(b.url) ? "url" : "string" == typeof b.data && !(b.contentType || "").indexOf("application/x-www-form-urlencoded") && ad.test(b.data) && "data");
return h || "jsonp" === b.dataTypes[0] ? (e = b.jsonpCallback = m.isFunction(b.jsonpCallback) ? b.jsonpCallback() : b.jsonpCallback, h ? b[h] = b[h].replace(ad, "$1" + e) : b.jsonp !== !1 && (b.url += (wc.test(b.url) ? "&" : "?") + b.jsonp + "=" + e), b.converters["script json"] = function() {
return g || m.error(e + " was not called"), g[0]
}, b.dataTypes[0] = "json", f = a[e], a[e] = function() {
g = arguments
}, d.always(function() {
a[e] = f, b[e] && (b.jsonpCallback = c.jsonpCallback, _c.push(e)), g && m.isFunction(f) && f(g[0]), g = f = void 0
}), "script") : void 0
}), m.parseHTML = function(a, b, c) {
if (!a || "string" != typeof a) return null;
"boolean" == typeof b && (c = b, b = !1), b = b || y;
var d = u.exec(a),
e = !c && [];
return d ? [b.createElement(d[1])] : (d = m.buildFragment([a], b, e), e && e.length && m(e).remove(), m.merge([], d.childNodes))
};
var bd = m.fn.load;
m.fn.load = function(a, b, c) {
if ("string" != typeof a && bd) return bd.apply(this, arguments);
var d, e, f, g = this,
h = a.indexOf(" ");
return h >= 0 && (d = m.trim(a.slice(h, a.length)), a = a.slice(0, h)), m.isFunction(b) ? (c = b, b = void 0) : b && "object" == typeof b && (f = "POST"), g.length > 0 && m.ajax({
url: a,
type: f,
dataType: "html",
data: b
}).done(function(a) {
e = arguments, g.html(d ? m("<div>").append(m.parseHTML(a)).find(d) : a)
}).complete(c && function(a, b) {
g.each(c, e || [a.responseText, b, a])
}), this
}, m.each(["ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend"], function(a, b) {
m.fn[b] = function(a) {
return this.on(b, a)
}
}), m.expr.filters.animated = function(a) {
return m.grep(m.timers, function(b) {
return a === b.elem
}).length
};
var cd = a.document.documentElement;
function dd(a) {
return m.isWindow(a) ? a : 9 === a.nodeType ? a.defaultView || a.parentWindow : !1
}
m.offset = {
setOffset: function(a, b, c) {
var d, e, f, g, h, i, j, k = m.css(a, "position"),
l = m(a),
n = {};
"static" === k && (a.style.position = "relative"), h = l.offset(), f = m.css(a, "top"), i = m.css(a, "left"), j = ("absolute" === k || "fixed" === k) && m.inArray("auto", [f, i]) > -1, j ? (d = l.position(), g = d.top, e = d.left) : (g = parseFloat(f) || 0, e = parseFloat(i) || 0), m.isFunction(b) && (b = b.call(a, c, h)), null != b.top && (n.top = b.top - h.top + g), null != b.left && (n.left = b.left - h.left + e), "using" in b ? b.using.call(a, n) : l.css(n)
}
}, m.fn.extend({
offset: function(a) {
if (arguments.length) return void 0 === a ? this : this.each(function(b) {
m.offset.setOffset(this, a, b)
});
var b, c, d = {
top: 0,
left: 0
},
e = this[0],
f = e && e.ownerDocument;
if (f) return b = f.documentElement, m.contains(b, e) ? (typeof e.getBoundingClientRect !== K && (d = e.getBoundingClientRect()), c = dd(f), {
top: d.top + (c.pageYOffset || b.scrollTop) - (b.clientTop || 0),
left: d.left + (c.pageXOffset || b.scrollLeft) - (b.clientLeft || 0)
}) : d
},
position: function() {
if (this[0]) {
var a, b, c = {
top: 0,
left: 0
},
d = this[0];
return "fixed" === m.css(d, "position") ? b = d.getBoundingClientRect() : (a = this.offsetParent(), b = this.offset(), m.nodeName(a[0], "html") || (c = a.offset()), c.top += m.css(a[0], "borderTopWidth", !0), c.left += m.css(a[0], "borderLeftWidth", !0)), {
top: b.top - c.top - m.css(d, "marginTop", !0),
left: b.left - c.left - m.css(d, "marginLeft", !0)
}
}
},
offsetParent: function() {
return this.map(function() {
var a = this.offsetParent || cd;
while (a && !m.nodeName(a, "html") && "static" === m.css(a, "position")) a = a.offsetParent;
return a || cd
})
}
}), m.each({
scrollLeft: "pageXOffset",
scrollTop: "pageYOffset"
}, function(a, b) {
var c = /Y/.test(b);
m.fn[a] = function(d) {
return V(this, function(a, d, e) {
var f = dd(a);
return void 0 === e ? f ? b in f ? f[b] : f.document.documentElement[d] : a[d] : void(f ? f.scrollTo(c ? m(f).scrollLeft() : e, c ? e : m(f).scrollTop()) : a[d] = e)
}, a, d, arguments.length, null)
}
}), m.each(["top", "left"], function(a, b) {
m.cssHooks[b] = Lb(k.pixelPosition, function(a, c) {
return c ? (c = Jb(a, b), Hb.test(c) ? m(a).position()[b] + "px" : c) : void 0
})
}), m.each({
Height: "height",
Width: "width"
}, function(a, b) {
m.each({
padding: "inner" + a,
content: b,
"": "outer" + a
}, function(c, d) {
m.fn[d] = function(d, e) {
var f = arguments.length && (c || "boolean" != typeof d),
g = c || (d === !0 || e === !0 ? "margin" : "border");
return V(this, function(b, c, d) {
var e;
return m.isWindow(b) ? b.document.documentElement["client" + a] : 9 === b.nodeType ? (e = b.documentElement, Math.max(b.body["scroll" + a], e["scroll" + a], b.body["offset" + a], e["offset" + a], e["client" + a])) : void 0 === d ? m.css(b, c, g) : m.style(b, c, d, g)
}, b, f ? d : void 0, f, null)
}
})
}), m.fn.size = function() {
return this.length
}, m.fn.andSelf = m.fn.addBack, "function" == typeof define && define.amd && define("jquery", [], function() {
return m
});
var ed = a.jQuery,
fd = a.$;
return m.noConflict = function(b) {
return a.$ === m && (a.$ = fd), b && a.jQuery === m && (a.jQuery = ed), m
}, typeof b === K && (a.jQuery = a.$ = m), m
});
jQuery shouldn't be grabbing any files all by itself.
Following are the things that you can try.
You can click on the error in chrome console, that will take you to the error location in the scripts. Sometimes it will take you to the function which handles the error and not the one which causes it. In this case follow second.
You can expand the Stacktrace in the console to see the call stack and verify if there are functions in the call stack which are loading these images.
You can check under the Network tab to check the call to the images. In Chrome Network console you would see the a column named Initiator (After Name,Status,Type). If you click on the link in this column against the image call, you chrome will open then script and move cursor to the line which initiated the call to image. If source code there is minified you can click on the {} (Pretty Print) icon at the bottom of source code editor. That will format the code, then you will be able to pin point the source code line that's causing the issue.
Finally brute force, check for the references to the blue.png or any other files in your source code.

Default lightbox for images gets disabled on using lazy load

Well I was trying to make images load faster on blog using lazy load that's when the default lightbox for images got disabled.
Apparently there's something obstructing the lightbox functioning in the lazy load script.
Here is lazy load script I used
(function () {
function r(e) {
var t = 0;
if (e.offsetParent) {
do t += e.offsetTop; while (e = e.offsetParent);
return t
}
}
var e = window.addEventListener || function (e, t) {
window.attachEvent("on" + e, t)
},
t = window.removeEventListener || function (e, t, n) {
window.detachEvent("on" + e, t)
},
n = {
cache: [],
mobileScreenSize: 500,
addObservers: function () {
e("scroll", n.throttledLoad), e("resize", n.throttledLoad)
},
removeObservers: function () {
t("scroll", n.throttledLoad, !1), t("resize", n.throttledLoad, !1)
},
throttleTimer: (new Date).getTime(),
throttledLoad: function () {
var e = (new Date).getTime();
e - n.throttleTimer >= 200 && (n.throttleTimer = e, n.loadVisibleImages())
},
loadVisibleImages: function () {
var e = window.pageYOffset || document.documentElement.scrollTop,
t = window.innerHeight || document.documentElement.clientHeight,
i = {
min: e - 300,
max: e + t + 300
},
s = 0;
while (s < n.cache.length) {
var o = n.cache[s],
u = r(o),
a = o.height || 0;
if (u >= i.min - a && u <= i.max) {
var f = o.getAttribute("data-src-mobile");
o.onload = function () {
this.className = "lazy-loaded"
}, f && screen.width <= n.mobileScreenSize ? o.src = f : o.src = o.getAttribute("data-src"), o.removeAttribute("data-src"), o.removeAttribute("data-src-mobile"), n.cache.splice(s, 1);
continue
}
s++
}
n.cache.length === 0 && n.removeObservers()
},
init: function () {
document.querySelectorAll || (document.querySelectorAll = function (e) {
var t = document,
n = t.documentElement.firstChild,
r = t.createElement("STYLE");
return n.appendChild(r), t.__qsaels = [], r.styleSheet.cssText = e + "{x:expression(document.__qsaels.push(this))}", window.scrollBy(0, 0), t.__qsaels
}), e("load", function r() {
var e = document.querySelectorAll("img[data-src]");
for (var i = 0; i < e.length; i++) {
var s = e[i];
n.cache.push(s)
}
n.addObservers(), n.loadVisibleImages(), t("load", r, !1)
})
}
};
n.init()
})()
You can see the disabled effect here on this site and the site with no lazy load. Just click on any image from the post to check the lightbox functioning.
I guess the lightbox functioning comes in from an external source which somehow I wasn't able to trace. I guess the data-src and src of the original and ones loaded over cause something bad to the lightbox.
Is there something I am doing wrong here? A solution to the problem will be very helpful.
Edit: Here is the lightbox plugin that I found:
kj = "lightbox",
function Co(a) {
var b = yo.V(),
c = b.h,
d = b.b;
if (d.lightbox) a(d.lightbox[1]);
else if (c.lightbox) c.lightbox[D]([1, a]);
else c.lightbox = [
[1, a]
], Q(b.a) ? Bo(b, kj) : b.d[D](kj)
}
if (this.a[x].lightboxEnabled) {
var b = this.a[x].lightboxModuleUrl,
c = this.a[x].lightboxCssUrl,
d = pq.V(),
e = Rm(b);
Ao(yo.V(), b, e);
d.f = c;
b = sn(Me, Yj, this.a.a);
for (c = 0; c < b[H]; c++) {
for (var e = ni + ir++, d = pq.V(), f = sn(ff, void 0, b[c]), h = f[H], s = [], t = 0; t < h; t++) {
var z = f[t].src,
A = null,
I = Hn(f[t]);
if (I) {
I = I[sb];
if (I != z) {
var Wa = z,
A = sq(I),
Wa = sq(Wa);
if (A && Wa && A[A[H] - 1] ==
Wa[Wa[H] - 1]) A = z, z = I, z = (I = sq(z)) && zm(I, td) ? z[w](/\/s(\d+)-h\//, Md) : z;
else continue
}
s[D]({
imageUrl: z,
thumbnailUrl: A
});
eo(f[t], ih, R(d.g, d, e, s[H] - 1))
}
}
0 < s[H] && (d.a[e] = s, d.d || (d.d = eo(k, lj, d.h, !1, d)))
}
}
here is the complete minified version
I'm not familiar with the exact lightbox you are using but I had a similar situation with a site I built where I was loading the images in after the page itself had finished loading and it broke the lightbox. The simplest solution (if your lightbox lets you do it easily) would be to call your lightbox function again after the images have been loaded.

Javascript error: Cannot read property 'parentNode' of null

The javascript I am using:
javascript: c = '{unit}, ({coords}) {player} |{distance}| {return}';
p = ['Scout', 'LC', 'HC', 'Axe', 'Sword', 'Ram', '***Noble***'];
function V() {
return 1;
}
window.onerror = V;
function Z() {
d = (window.frames.length > 0) ? window.main.document : document;
aid = d.getElementById('editInput').parentNode.innerHTML.match(/id\=(\d+)/)[1];
function J(e) {
vv = e.match(/\d+\|\d+/g);
return (vv ? vv[vv.length - 1].match(/((\d+)\|(\d+))/) : null);
}
function K(e) {
f = parseInt(e, 10);
return (f > 9 ? f : '0' + f);
}
function L(g, e) {
return g.getElementsByTagName(e);
}
function N(g) {
return g.innerHTML;
}
function M(g) {
return N(L(g, 'a')[0]);
}
function O() {
return k.insertRow(E++);
}
function W(f) {
return B.insertCell(f);
}
function P(g, e) {
g.innerHTML = e;
return g;
}
function X(e) {
C = B.appendChild(d.createElement('th'));
return P(C, e);
}
function Y(f) {
return K(f / U) + ':' + K(f % (U) / T) + ':' + K(f % T);
}
U = 3600;
T = 60;
R = 'table';
S = 'width';
s = L(document, R);
for (j = 0; j < s.length; j++) {
s[j].removeAttribute(S);
if (s[j].className == 'main') {
s = L(L(s[j], 'tbody')[0], R);
break;
}
}
D = 0;
for (j = 0; j < s.length; j++) {
s[j].removeAttribute(S);
if (s[j].className = 'vis') {
k = s[j];
if (t = k.rows) {
D = t.length;
break;
}
}
}
for (E = 0; E < D; E++) {
l = t[E];
m = (u = l.cells) ? u.length : 0;
if (m) {
u[m - 1].colSpan = 5 - m;
if (N(u[0]) == 'Arrival:') {
Q = new Date(N(u[1]).replace(/<.*/i, ''));
} else {
if (N(u[0]) == 'Arrival in:') {
v = N(u[1]).match(/\d+/ig);
}
}
if (E == 1) {
G = M(u[2]);
}
if (E == 2) {
w = J(M(u[1]));
}
if (E == 4) {
x = J(M(u[1]));
}
}
}
y = v[0] * U + v[1] * T + v[2] * 1;
n = w[2] - x[2];
o = w[3] - x[3];
F = Math.sqrt(n * n + o * o);
H = F.toFixed(2);
E = D - 2;
s = L(k, 'input');
i = s[1];
h = s[0];
h.size = T;
B = O();
P(W(0), 'Distance:').colSpan = 2;
P(W(1), H + ' Fields').colSpan = 2;
B = O();
X('Unit');
X('Sent');
X('Duration');
X('Name to');
c = c.replace(/\{coords\}/i, w[1]).replace(/\{distance\}/i, H).replace(/\{player\}/i, G);
for (j in p) {
z = Math.round([9.00000000, 10.00000000, 11.00000000, 18.0000000015, 22.00000000, 30.00000000, 35.0000000][j] * T * F);
A = z - y;
if (A > 0) {
I = Y(z);
B = O();
P(W(0), p[j]);
P(W(1), A < T && 'just now' || A < U && Math.floor(A / T) + ' mins ago' || Y(A) + ' ago');
P(W(2), I);
C = W(3);
q = C.appendChild(i.cloneNode(1));
r = C.appendChild(h.cloneNode(1));
r.id = 'I' + j;
r.value = c.replace(/\{duration\}/i, I).replace(/\{sent\}/i, new Date(Q.valueOf() - z * 1000).toLocaleString().replace(/.\d{4}/i, '').replace(/(\w{3})\w*/i, '$1')).replace(/\{return\}/i, new Date(Q.valueOf() + z * 1000).toString().replace(/\w+\s*/i, '').replace(/(\d*:\d*:\d*)(.*)/i, '$1')).replace(/\{unit\}/i, p[j]).replace(/\{attack_id\}/i, aid);
q.onmousedown = new Function('h.value=d.getElementById(\'I' + j + '\').value;');
}
}
}
Z();
The error I receive:
Uncaught TypeError: Cannot read property 'parentNode' of null
A URL looks like this:
game.php?village=2100&id=4348754&type=other&screen=info_command
There are two possibilities:
editInput is a typo, and the actual id of that element is different (ids are case-sensitive).
You are executing this code while the DOM is not ready. To prevent this, execute the code just before the </body> closing tag, or wrap it in an event handler for the load event of window or the DOMContentLoaded event of document.
EDITED How to wrap your code:
window.onload = function() {
//your code here
};
In my case it was a conflict between slider and form validator as they were located on different pages but javascript file would of target both of them simultaneously, so all pages that had no slider would come up with "Cannot read property 'parentNode' of null" error, so I have added to the slider If statement:
if(document.getElementById("mainImage")){
var myImage = document.getElementById("mainImage");
var linkElement = myImage.parentNode;
that solved my problem, try it
I was trying to remove child element from parent:
constructor(private renderer: Renderer2) { }
removeChildEl() {
this.renderer.removeChild(parent, child);
}
but for some reason parent-element does not exist so I need to check via if condition:
removeChildEl() {
if(parent)
this.renderer.removeChild(parent, child);
}
so if the parent exists then remove the child otherwise do nothing.

Javascript accessing the variable inside function

I came across website that contains below code.I need to get the value of a.In firefox webconsole i tried this ...javascript:alert(_.Qj.a()); , but it did not work..how can i access the value of a , c f etc
_.Qj = function () {
function a() {
var a = window.__OVERRIDE_SID;
a == _.s && (a = _.Yj.get("SID"));
return !!a
}
return {
Nq: function (a) {
var f = {
SAPISIDHASH: _.r,
APISIDHASH: _.r
};
return a && (a.OriginToken || a.Authorization && f[String(a.Authorization).split(" ")[0]]) ? _.r : _.u
},
er: a,
bq: function () {
var c = _.s;
a() && (c = window.__PVT, c == _.s && (c = _.Yj.get("BEAT")));
return c
},
Qe: function () {
var c = _.Rb.Pq(String(window.location.href));
if (a()) {
var f = 0 == c.indexOf("https:") || 0 == c.indexOf("chrome-extension:"),
g = f ? "SAPISID" : "APISID",
h = f ? window.__SAPISID : window.__APISID;
h == _.s && (h = _.Yj.get(g));
if (h) return f = f ? "SAPISIDHASH" : "APISIDHASH", g = (0, _.Tb)(), g.reset(), g.update([h, c].join(" ")), f + " " + g.Of().toLowerCase()
}
return _.s
}
}
}();
and any basic explanation to this code will be appreciated
Here's how you'd access a:
javascript:alert(_.Qj.er());
Fiddle inspired by your code.

Categories