Related
I have a script that is modifying a Shopify App (Which means the scripts are attached through a third party process and I can't access them.) I want my script to load only after their script is completely finished executing, but I can't figure out what to use to signal this process is complete.
This is my script (currently using setInterval as a stopgap):
$(window).load(function(){
var check = setInterval(function() {
let sprCheck = window['SPR'];
var spr = $("#shopify-product-reviews"),
container = spr.find(".spr-content"),
reviewButton = spr.find(".spr-summary-actions-newreview");
if (sprCheck) {
clearInterval(check);
var reviews = spr.find('.spr-reviews'),
reviewButtonWrap = spr.find('.spr-summary-actions'),
form = spr.find('.spr-form'),
toggleContainer = spr.find('.spr-summary-actions-togglereviews'),
reviewButtonLabel = reviewButton.text();
reviewButtonWrap.detach().appendTo(container);
spr.css('overflow','visible');
form.detach().insertAfter(reviews);
if (reviews.children().length) {
reviewButtonWrap.css('display', 'none');
}
toggleContainer.click(function() {
reviewButtonWrap.toggle();
});
spr.fadeTo(300, 1);
reviewButton.click(function(){
if (form.is(':visible')) {
reviewButton.text('Cancel Review');
reviewButton.addClass('spr-close-form');
} else {
reviewButton.text(reviewButtonLabel);
reviewButton.removeClass('spr-close-form');
}
});
}
}, 300);
})
This is where their script is attached:
(function() {
function asyncLoad() {
var urls = ["\/\/productreviews.shopifycdn.com\/assets\/v4\/spr.js?shop=sukker-sweet-phase-2.myshopify.com"];
for (var i = 0; i < urls.length; i++) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = urls[i];
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
};
if(window.attachEvent) {
window.attachEvent('onload', asyncLoad);
} else {
window.addEventListener('load', asyncLoad, false);
}
})();
This is their script itself:
e = function() {
"use strict";
window.innerShiv = function() {
function n(e, t, r) {
return /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i.test(r) ? e : t + "></" + r + ">"
}
var s, o = document,
d = "abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video".split(" ");
return function(e, t) {
if (!s && ((s = o.createElement("div")).innerHTML = "<nav></nav>", 1 !== s.childNodes.length)) {
for (var r = o.createDocumentFragment(), a = d.length; a--;) r.createElement(d[a]);
r.appendChild(s)
}
if (e = e.replace(/^\s\s*/, "").replace(/\s\s*$/, "").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").replace(/(<([\w:]+)[^>]*?)\/>/g, n), s.innerHTML = (r = e.match(/^<(tbody|tr|td|col|colgroup|thead|tfoot)/i)) ? "<table>" + e + "</table>" : e, r = r ? s.getElementsByTagName(r[1])[0].parentNode : s, !1 === t) return r.childNodes;
a = o.createDocumentFragment();
for (var i = r.childNodes.length; i--;) a.appendChild(r.firstChild);
return a
}
}()
}, t = {
exports: {}
}, e.call(t.exports, t, t.exports), t.exports;
var e, t;
(function() {
window.SPR = function() {
function n() {}
return n.shop = Shopify.shop, n.host = "//productreviews.shopifycdn.com", n.version = "v4", n.api_url = n.host + "/proxy/" + n.version, n.badgeEls = [], n.reviewEls = [], n.elSettings = {}, n.$ = void 0, n.extraAjaxParams = {
shop: n.shop
}, n.registerCallbacks = function() {
return this.$(document).bind("spr:badge:loaded", "undefined" != typeof SPRCallbacks && null !== SPRCallbacks ? SPRCallbacks.onBadgeLoad : void 0), this.$(document).bind("spr:product:loaded", "undefined" != typeof SPRCallbacks && null !== SPRCallbacks ? SPRCallbacks.onProductLoad : void 0), this.$(document).bind("spr:reviews:loaded", "undefined" != typeof SPRCallbacks && null !== SPRCallbacks ? SPRCallbacks.onReviewsLoad : void 0), this.$(document).bind("spr:form:loaded", "undefined" != typeof SPRCallbacks && null !== SPRCallbacks ? SPRCallbacks.onFormLoad : void 0), this.$(document).bind("spr:form:success", "undefined" != typeof SPRCallbacks && null !== SPRCallbacks ? SPRCallbacks.onFormSuccess : void 0), this.$(document).bind("spr:form:failure", "undefined" != typeof SPRCallbacks && null !== SPRCallbacks ? SPRCallbacks.onFormFailure : void 0)
}, n.loadStylesheet = function() {
var e;
return (e = document.createElement("link")).setAttribute("rel", "stylesheet"), e.setAttribute("type", "text/css"), e.setAttribute("href", "https://productreviews.shopifycdn.com/assets/v4/spr-805222bdeda8199e3a86a468a398e3070e6126868692225ffa23ac7502b1eca2.css"), e.setAttribute("media", "screen"), document.getElementsByTagName("head")[0].appendChild(e)
}, n.initRatingHandler = function() {
return n.$(document).on("mouseover mouseout", "form a.spr-icon-star", function(e) {
var t, r, a;
return t = e.currentTarget, a = n.$(t).attr("data-value"), r = n.$(t).parent(), "mouseover" === e.type ? (r.find("a.spr-icon:lt(" + a + ")").addClass("spr-icon-star-hover"), r.find("a.spr-icon:gt(" + (a - 1) + ")").removeClass("spr-icon-star-hover")) : r.find("a.spr-icon").removeClass("spr-icon-star-hover")
})
}, n.initDomEls = function() {
return this.badgeEls = this.$(".shopify-product-reviews-badge[data-id]"), this.reviewEls = this.$("#shopify-product-reviews[data-id]"), this.$.each(this.reviewEls, (a = this, function(e, t) {
var r;
return r = a.$(t).attr("data-id"), a.elSettings[r] = {}, a.elSettings[r].reviews_el = "#" + (a.$(t).attr("data-reviews-prefix") ? a.$(t).attr("data-reviews-prefix") : "reviews_"), a.elSettings[r].form_el = "#" + (a.$(t).attr("data-form-prefix") ? a.$(t).attr("data-form-prefix") : "form_")
}));
var a
}, n.loadProducts = function() {
return this.$.each(this.reviewEls, (i = this, function(e, t) {
var r, a;
if (r = i.$(t).attr("data-id"), "false" !== i.$(t).attr("data-autoload")) return a = i.$.extend({
product_id: r,
version: i.version
}, i.extraAjaxParams), i.$.get(i.api_url + "/reviews/product", a, i.productCallback, "jsonp")
}));
var i
}, n.loadBadges = function() {
var e, t, r, a, i, n;
if (0 < (r = this.$.map(this.badgeEls, (n = this, function(e) {
return n.$(e).attr("data-id")
}))).length) {
for (t = 7, i = []; 0 < (e = r.splice(0, t)).length;) a = this.$.extend(this.extraAjaxParams, {
product_ids: e
}), i.push(this.$.get(this.api_url + "/reviews/badges", a, this.badgesCallback, "jsonp"));
return i
}
}, n.pageReviews = function(e) {
var t, r, a;
return a = this.$(e).data("product-id"), r = this.$(e).data("page"), t = this.$.extend({
page: r,
product_id: a
}, this.extraAjaxParams), this.$.get(this.api_url + "/reviews", t, this.paginateCallback, "jsonp"), !1
}, n.submitForm = function(e) {
var t, r, a;
return t = this.$(e).serializeObject(), t = this.$.extend(t, this.extraAjaxParams), t = (t = this.$.param(t)).replace(/%0D%0A/g, "%0A"), this.$.ajax({
url: this.api_url + "/reviews/create",
type: "GET",
dataType: "jsonp",
data: t,
success: this.formCallback,
beforeSend: (a = this, function() {
return a.$(".spr-button-primary").attr("disabled", "disabled")
}),
complete: (r = this, function() {
return r.$(".spr-button-primary").removeAttr("disabled")
})
}), !1
}, n.reportReview = function(e) {
var t;
return confirm("Are you sure you want to report this review as inappropriate?") && (t = this.$.extend({
id: e
}, this.extraAjaxParams), this.$.get(this.api_url + "/reviews/report", t, this.reportCallback, "jsonp")), !1
}, n.toggleReviews = function(e) {
return this.$("#shopify-product-reviews[data-id='" + e + "']").find(".spr-reviews").toggle()
}, n.toggleForm = function(e) {
return this.$("#shopify-product-reviews[data-id='" + e + "']").find(".spr-form").toggle()
}, n.setRating = function(e) {
var t, r, a;
return t = this.$(e).parents("form"), a = this.$(e).attr("data-value"), r = this.$(e).parent(), t.find("input[name='review[rating]']").val(a), this.setStarRating(a, r)
}, n.setStarRating = function(e, t) {
return t.find("a:lt(" + e + ")").removeClass("spr-icon-star-empty spr-icon-star-hover"), t.find("a:gt(" + (e - 1) + ")").removeClass("spr-icon-star-hover").addClass("spr-icon-star-empty")
}, n.badgesCallback = function(e) {
var r;
return r = e.badges, n.$.map(n.badgeEls, function(e) {
var t;
if (t = n.$(e).attr("data-id"), r[t] !== undefined) return n.$(e).replaceWith(r[t]), n.triggerEvent("spr:badge:loaded", {
id: t
})
})
}, n.productCallback = function(e) {
var t;
return t = e.remote_id.toString(), n.renderProduct(t, e.product_stripped, e.aggregate_rating), n.renderForm(t, e.form), n.renderReviews(t, e.reviews)
}, n.renderProduct = function(t, r, a) {
return this.$.map(this.reviewEls, (i = this, function(e) {
if (t === i.$(e).attr("data-id")) return i.$(e).html([innerShiv(r, !1), a]), i.triggerEvent("spr:product:loaded", {
id: t
})
}));
var i
}, n.renderForm = function(e, t) {
return this.$(this.elSettings[e].form_el + e).html(t), this.triggerEvent("spr:form:loaded", {
id: e
})
}, n.renderReviews = function(e, t) {
return n.$(n.elSettings[e].reviews_el + e).html(t), n.triggerEvent("spr:reviews:loaded", {
id: e
})
}, n.formCallback = function(e) {
var t, r, a, i;
return i = e.status, a = e.remote_id, r = e.form, (t = n.$(n.elSettings[a].form_el + a)).html(r), "failure" === i && n.initStarRating(t), "success" === i && (n.$("#shopify-product-reviews[data-id='" + a + "'] .spr-summary-actions-newreview").hide(), n.$(".spr-form-message-success").focus()), n.triggerEvent("spr:form:" + i, {
id: a
})
}, n.initStarRating = function(e) {
var t, r, a;
if ((a = e.find("input[name='review[rating]']")) && a.val()) return r = a.val(), t = e.find(".spr-starrating"), this.setStarRating(r, t)
}, n.paginateCallback = function(e) {
var t, r;
return r = e.remote_id.toString(), t = e.reviews, n.renderReviews(r, t)
}, n.reportCallback = function(e) {
var t;
return t = "#report_" + e.id, n.$(t).replaceWith("<span class='spr-review-reportreview'>" + n.$(t).attr("data-msg") + "</span>")
}, n.loadjQuery = function(e) {
return n.loadScript("//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js", function() {
return n.$ = jQuery.noConflict(!0), e()
})
}, n.loadScript = function(e, t) {
var r;
return (r = document.createElement("script")).type = "text/javascript", r.readyState ? r.onreadystatechange = function() {
if ("loaded" === r.readyState || "complete" === r.readyState) return r.onreadystatechange = null, t()
} : r.onload = function() {
return t()
}, r.src = e, document.getElementsByTagName("head")[0].appendChild(r)
}, n.loadjQueryExtentions = function(r) {
return r.fn.serializeObject = function() {
var e, t;
return e = {}, t = this.serializeArray(), r.each(t, function() {
return e[this.name] ? (e[this.name].push || (e[this.name] = [e[this.name]]), e[this.name].push(this.value || "")) : e[this.name] = this.value || ""
}), e
}
}, n.triggerEvent = function(e, t) {
return this.$(document).trigger(e, t)
}, n
}(), SPR.loadStylesheet(), SPR.loadjQuery(function() {
return SPR.$.ajaxSetup({
cache: !1
}), SPR.loadjQueryExtentions(SPR.$), SPR.$(document).ready(function() {
return SPR.registerCallbacks(), SPR.initRatingHandler(), SPR.initDomEls(), SPR.loadProducts(), SPR.loadBadges()
})
})
}).call(this)
}("undefined" != typeof global ? global : "undefined" != typeof window && window);
Where their script is attached, you could try adding an onload attribute:
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.onload = "functionToRunMyOwnScript()"
If you can't access the place where it's attached, I personally don't think there's anything wrong with using the interval, as you're currently doing.
I think you have 2 options.
like you do it (check again and again if the changes are done)
use MutationObserver , if you wanna go this way, make sure to test this heavly.
To your solution, I think what you miss is a better check (sprCheck). If you say sometimes the function is triggered when the element exists, but is not at the right spot yet, then you also have to check if the element is on the right check before you continue.
I need help.
Is there anybody can change the sequence of the div "cookieinfo-close" and the following "span" element. I want first the span, second the div.
Thank you!
!function(e){"use strict";var t=e,i=t.document,o="cbinstance";var n={get:function(e){return decodeURIComponent(i.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},set:function(e,t,o,n,s,r){if(!e||/^(?:expires|max\-age|path|domain|secure)$/i.test(e))return!1;var a="";if(o)switch(o.constructor){case Number:a=o===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+o;break;case String:a="; expires="+o;break;case Date:a="; expires="+o.toUTCString()}return i.cookie=encodeURIComponent(e)+"="+encodeURIComponent(t)+a+(s?"; domain="+s:"")+(n?"; path="+n:"")+(r?"; secure":""),!0},has:function(e){return new RegExp("(?:^|;\\s*)"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(i.cookie)},remove:function(e,t,o){return!(!e||!this.has(e))&&(i.cookie=encodeURIComponent(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(o?"; domain="+o:"")+(t?"; path="+t:""),!0)}},s={merge:function(){var e,t={},i=0,o=arguments.length;if(0===o)return t;for(;i<o;i++)for(e in arguments[i])Object.prototype.hasOwnProperty.call(arguments[i],e)&&(t[e]=arguments[i][e]);return t},str2bool:function(e){switch((e=""+e).toLowerCase()){case"false":case"no":case"0":case"":return!1;default:return!0}},fade_in:function(e){e.style.opacity<1&&(e.style.opacity=(parseFloat(e.style.opacity)+.05).toFixed(2),t.setTimeout(function(){s.fade_in(e)},50))},get_data_attribs:function(e){var t={};if(Object.prototype.hasOwnProperty.call(e,"dataset"))t=e.dataset;else{var i,o=e.attributes;for(i in o)if(Object.prototype.hasOwnProperty.call(o,i)){var n=o[i];if(/^data-/.test(n.name))t[s.camelize(n.name.substr(5))]=n.value}}return t},normalize_keys:function(e){var t={};for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var o=s.camelize(i);t[o]=e[o]?e[o]:e[i]}return t},camelize:function(e){for(var t="-",i=e.indexOf(t);-1!=i;){var o=i===e.length-1,n=o?"":e[i+1],s=n.toUpperCase(),r=o?t:t+n;i=(e=e.replace(r,s)).indexOf(t)}return e},find_script_by_id:function(e){for(var t=i.getElementsByTagName("script"),o=0,n=t.length;o<n;o++)if(e===t[o].id)return t[o];return null}},r=s.find_script_by_id("cookieinfo"),a=e.cookieinfo=function(e){this.init(e)};a.prototype={cookiejar:n,init:function(t){this.inserted=!1,this.closed=!1,this.test_mode=!1;if(this.default_options={cookie:"we-love-cookies",closeText:"✖",cookiePath:"/",debug:!1,expires:1/0,zindex:1e20,mask:!1,maskOpacity:.5,maskBackground:"#999",height:"auto",minHeight:"31px",bg:"#eee",fg:"#333",link:"#31A8F0",divlink:"#000",divlinkbg:"#F1D600",position:"top",message:"This is a cookie message.",linkmsg:"Read more.",scriptmsg:"Cookie Info Script",moreinfo:"#acc-430",tracking:"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",effect:null,fontSize:"14px",fontFamily:"verdana, arial, sans-serif",instance:o,textAlign:"center",acceptOnScroll:!1},this.options=this.default_options,this.script_el=r,this.script_el){var i=s.get_data_attribs(this.script_el);this.options=s.merge(this.options,i)}t&&(t=s.normalize_keys(t),this.options=s.merge(this.options,t)),o=this.options.instance,this.options.zindex=parseInt(this.options.zindex,10),this.options.mask=s.str2bool(this.options.mask),"string"==typeof this.options.expires&&"function"==typeof e[this.options.expires]&&(this.options.expires=e[this.options.expires]),"function"==typeof this.options.expires&&(this.options.expires=this.options.expires()),this.script_el&&this.run()},log:function(){"undefined"!=typeof console&&console.log.apply(console,arguments)},run:function(){if(!this.agreed()){var e=this;!function(e,t){var i=!1,o=!0,n=e.document,s=n.documentElement,r=n.addEventListener?"addEventListener":"attachEvent",a=n.addEventListener?"removeEventListener":"detachEvent",c=n.addEventListener?"":"on",l=function(o){"readystatechange"==o.type&&"complete"!=n.readyState||(("load"==o.type?e:n)[a](c+o.type,l,!1),!i&&(i=!0)&&t.call(e,o.type||o))},p=function(){try{s.doScroll("left")}catch(e){return void setTimeout(p,50)}l("poll")};if("complete"==n.readyState)t.call(e,"lazy");else{if(n.createEventObject&&s.doScroll){try{o=!e.frameElement}catch(e){}o&&p()}n[r](c+"DOMContentLoaded",l,!1),n[r](c+"readystatechange",l,!1),e[r](c+"load",l,!1)}}(t,function(){e.insert()})}},build_viewport_mask:function(){var e=null;if(!0===this.options.mask){var t=this.options.maskOpacity,o='<div id="cookieinfo-mask" style="position:fixed;top:0;left:0;width:100%;height:100%;background:'+this.options.maskBackground+";zoom:1;filter:alpha(opacity="+100*t+");opacity:"+t+";z-index:"+this.options.zindex+';"></div>',n=i.createElement("div");n.innerHTML=o,e=n.firstChild}return e},agree:function(){return this.cookiejar.set(this.options.cookie,1,this.options.expires,this.options.cookiePath),!0},agreed:function(){return this.cookiejar.has(this.options.cookie)},close:function(){return this.inserted&&(this.closed||(this.element&&this.element.parentNode.removeChild(this.element),this.element_mask&&this.element_mask.parentNode.removeChild(this.element_mask),this.closed=!0)),this.closed},agree_and_close:function(){return this.agree(),this.close()},cleanup:function(){return this.close(),this.unload()},unload:function(){return this.script_el&&this.script_el.parentNode.removeChild(this.script_el),e[o]=void 0,!0},insert:function(){this.element_mask=this.build_viewport_mask();var e=this.options.zindex;this.element_mask&&(e+=1);var t=i.createElement("div");t.className="cookieinfo",t.style.position="fixed",t.style.left=0,t.style.right=0,t.style.height=this.options.height,t.style.minHeight=this.options.minHeight,t.style.zIndex=e,t.style.background=this.options.bg,t.style.color=this.options.fg,t.style.lineHeight=t.style.minHeight,t.style.padding="8px 30px",t.style.fontFamily=this.options.fontFamily,t.style.fontSize=this.options.fontSize,t.style.textAlign=this.options.textAlign,"top"===this.options.position?t.style.top=0:t.style.bottom=0,t.innerHTML='<div class="cookieinfo-close" style="float:right;display:block;padding:5px 8px 5px 8px;min-width:100px;margin-left:5px;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;border-bottom-left-radius:5px;">'+this.options.closeText+'</div><span style="display:block;padding:5px 0 5px 0;">'+this.options.message+" <a>"+this.options.linkmsg+"</a><img> <a>"+this.options.scriptmsg+"</a></span>",this.element=t;var o=t.getElementsByTagName("a")[0];o.href=this.options.moreinfo,o.style.textDecoration="underline",o.style.color=this.options.link;var n=t.getElementsByTagName("a")[1];n.href=this.options.scriptinfo,n.style.textDecoration="none",n.style.display="none",n.style.color=this.options.link;var r=t.getElementsByTagName("div")[0];r.style.cursor="pointer",r.style.color=this.options.divlink,r.style.background=this.options.divlinkbg,r.style.textAlign="center";var a=t.getElementsByTagName("img")[0];function c(e,t,i){var o=e.addEventListener?"addEventListener":"attachEvent",n=e.addEventListener?"":"on";e[o](n+t,i,!1)}a.src=this.options.tracking,a.style.display="none";var l=this;c(r,"click",function(){l.agree_and_close()}),this.element_mask&&(c(this.element_mask,"click",function(){l.agree_and_close()}),i.body.appendChild(this.element_mask)),this.options.acceptOnScroll&&c(window,"scroll",function(){l.agree_and_close()}),i.body.appendChild(this.element),this.inserted=!0,"fade"===this.options.effect?(this.element.style.opacity=0,s.fade_in(this.element)):this.element.style.opacity=1}},r&&(e[o]||(e[o]=new a))}(window);
First you need to revert your js file to unminify:
! function(e) {
"use strict";
var t = e,
i = t.document,
o = "cbinstance";
var n = {
get: function(e) {
return decodeURIComponent(i.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(e).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null
},
set: function(e, t, o, n, s, r) {
if (!e || /^(?:expires|max\-age|path|domain|secure)$/i.test(e)) return !1;
var a = "";
if (o) switch (o.constructor) {
case Number:
a = o === 1 / 0 ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + o;
break;
case String:
a = "; expires=" + o;
break;
case Date:
a = "; expires=" + o.toUTCString()
}
return i.cookie = encodeURIComponent(e) + "=" + encodeURIComponent(t) + a + (s ? "; domain=" + s : "") + (n ? "; path=" + n : "") + (r ? "; secure" : ""), !0
},
has: function(e) {
return new RegExp("(?:^|;\\s*)" + encodeURIComponent(e).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=").test(i.cookie)
},
remove: function(e, t, o) {
return !(!e || !this.has(e)) && (i.cookie = encodeURIComponent(e) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (o ? "; domain=" + o : "") + (t ? "; path=" + t : ""), !0)
}
},
s = {
merge: function() {
var e, t = {},
i = 0,
o = arguments.length;
if (0 === o) return t;
for (; i < o; i++)
for (e in arguments[i]) Object.prototype.hasOwnProperty.call(arguments[i], e) && (t[e] = arguments[i][e]);
return t
},
str2bool: function(e) {
switch ((e = "" + e).toLowerCase()) {
case "false":
case "no":
case "0":
case "":
return !1;
default:
return !0
}
},
fade_in: function(e) {
e.style.opacity < 1 && (e.style.opacity = (parseFloat(e.style.opacity) + .05).toFixed(2), t.setTimeout(function() {
s.fade_in(e)
}, 50))
},
get_data_attribs: function(e) {
var t = {};
if (Object.prototype.hasOwnProperty.call(e, "dataset")) t = e.dataset;
else {
var i, o = e.attributes;
for (i in o)
if (Object.prototype.hasOwnProperty.call(o, i)) {
var n = o[i];
if (/^data-/.test(n.name)) t[s.camelize(n.name.substr(5))] = n.value
}
}
return t
},
normalize_keys: function(e) {
var t = {};
for (var i in e)
if (Object.prototype.hasOwnProperty.call(e, i)) {
var o = s.camelize(i);
t[o] = e[o] ? e[o] : e[i]
}
return t
},
camelize: function(e) {
for (var t = "-", i = e.indexOf(t); - 1 != i;) {
var o = i === e.length - 1,
n = o ? "" : e[i + 1],
s = n.toUpperCase(),
r = o ? t : t + n;
i = (e = e.replace(r, s)).indexOf(t)
}
return e
},
find_script_by_id: function(e) {
for (var t = i.getElementsByTagName("script"), o = 0, n = t.length; o < n; o++)
if (e === t[o].id) return t[o];
return null
}
},
r = s.find_script_by_id("cookieinfo"),
a = e.cookieinfo = function(e) {
this.init(e)
};
a.prototype = {
cookiejar: n,
init: function(t) {
this.inserted = !1, this.closed = !1, this.test_mode = !1;
if (this.default_options = {
cookie: "we-love-cookies",
closeText: "✖",
cookiePath: "/",
debug: !1,
expires: 1 / 0,
zindex: 1e20,
mask: !1,
maskOpacity: .5,
maskBackground: "#999",
height: "auto",
minHeight: "31px",
bg: "#eee",
fg: "#333",
link: "#31A8F0",
divlink: "#000",
divlinkbg: "#F1D600",
position: "top",
message: "This is a cookie message.",
linkmsg: "Read more.",
scriptmsg: "Cookie Info Script",
moreinfo: "#acc-430",
tracking: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",
effect: null,
fontSize: "14px",
fontFamily: "verdana, arial, sans-serif",
instance: o,
textAlign: "center",
acceptOnScroll: !1
}, this.options = this.default_options, this.script_el = r, this.script_el) {
var i = s.get_data_attribs(this.script_el);
this.options = s.merge(this.options, i)
}
t && (t = s.normalize_keys(t), this.options = s.merge(this.options, t)), o = this.options.instance, this.options.zindex = parseInt(this.options.zindex, 10), this.options.mask = s.str2bool(this.options.mask), "string" == typeof this.options.expires && "function" == typeof e[this.options.expires] && (this.options.expires = e[this.options.expires]), "function" == typeof this.options.expires && (this.options.expires = this.options.expires()), this.script_el && this.run()
},
log: function() {
"undefined" != typeof console && console.log.apply(console, arguments)
},
run: function() {
if (!this.agreed()) {
var e = this;
! function(e, t) {
var i = !1,
o = !0,
n = e.document,
s = n.documentElement,
r = n.addEventListener ? "addEventListener" : "attachEvent",
a = n.addEventListener ? "removeEventListener" : "detachEvent",
c = n.addEventListener ? "" : "on",
l = function(o) {
"readystatechange" == o.type && "complete" != n.readyState || (("load" == o.type ? e : n)[a](c + o.type, l, !1), !i && (i = !0) && t.call(e, o.type || o))
},
p = function() {
try {
s.doScroll("left")
} catch (e) {
return void setTimeout(p, 50)
}
l("poll")
};
if ("complete" == n.readyState) t.call(e, "lazy");
else {
if (n.createEventObject && s.doScroll) {
try {
o = !e.frameElement
} catch (e) {}
o && p()
}
n[r](c + "DOMContentLoaded", l, !1), n[r](c + "readystatechange", l, !1), e[r](c + "load", l, !1)
}
}(t, function() {
e.insert()
})
}
},
build_viewport_mask: function() {
var e = null;
if (!0 === this.options.mask) {
var t = this.options.maskOpacity,
o = '<div id="cookieinfo-mask" style="position:fixed;top:0;left:0;width:100%;height:100%;background:' + this.options.maskBackground + ";zoom:1;filter:alpha(opacity=" + 100 * t + ");opacity:" + t + ";z-index:" + this.options.zindex + ';"></div>',
n = i.createElement("div");
n.innerHTML = o, e = n.firstChild
}
return e
},
agree: function() {
return this.cookiejar.set(this.options.cookie, 1, this.options.expires, this.options.cookiePath), !0
},
agreed: function() {
return this.cookiejar.has(this.options.cookie)
},
close: function() {
return this.inserted && (this.closed || (this.element && this.element.parentNode.removeChild(this.element), this.element_mask && this.element_mask.parentNode.removeChild(this.element_mask), this.closed = !0)), this.closed
},
agree_and_close: function() {
return this.agree(), this.close()
},
cleanup: function() {
return this.close(), this.unload()
},
unload: function() {
return this.script_el && this.script_el.parentNode.removeChild(this.script_el), e[o] = void 0, !0
},
insert: function() {
this.element_mask = this.build_viewport_mask();
var e = this.options.zindex;
this.element_mask && (e += 1);
var t = i.createElement("div");
t.className = "cookieinfo", t.style.position = "fixed", t.style.left = 0, t.style.right = 0, t.style.height = this.options.height, t.style.minHeight = this.options.minHeight, t.style.zIndex = e, t.style.background = this.options.bg, t.style.color = this.options.fg, t.style.lineHeight = t.style.minHeight, t.style.padding = "8px 30px", t.style.fontFamily = this.options.fontFamily, t.style.fontSize = this.options.fontSize, t.style.textAlign = this.options.textAlign, "top" === this.options.position ? t.style.top = 0 : t.style.bottom = 0, t.innerHTML = '<div class="cookieinfo-close" style="float:right;display:block;padding:5px 8px 5px 8px;min-width:100px;margin-left:5px;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;border-bottom-left-radius:5px;">' + this.options.closeText + '</div><span style="display:block;padding:5px 0 5px 0;">' + this.options.message + " <a>" + this.options.linkmsg + "</a><img> <a>" + this.options.scriptmsg + "</a></span>", this.element = t;
var o = t.getElementsByTagName("a")[0];
o.href = this.options.moreinfo, o.style.textDecoration = "underline", o.style.color = this.options.link;
var n = t.getElementsByTagName("a")[1];
n.href = this.options.scriptinfo, n.style.textDecoration = "none", n.style.display = "none", n.style.color = this.options.link;
var r = t.getElementsByTagName("div")[0];
r.style.cursor = "pointer", r.style.color = this.options.divlink, r.style.background = this.options.divlinkbg, r.style.textAlign = "center";
var a = t.getElementsByTagName("img")[0];
function c(e, t, i) {
var o = e.addEventListener ? "addEventListener" : "attachEvent",
n = e.addEventListener ? "" : "on";
e[o](n + t, i, !1)
}
a.src = this.options.tracking, a.style.display = "none";
var l = this;
c(r, "click", function() {
l.agree_and_close()
}), this.element_mask && (c(this.element_mask, "click", function() {
l.agree_and_close()
}), i.body.appendChild(this.element_mask)), this.options.acceptOnScroll && c(window, "scroll", function() {
l.agree_and_close()
}), i.body.appendChild(this.element), this.inserted = !0, "fade" === this.options.effect ? (this.element.style.opacity = 0, s.fade_in(this.element)) : this.element.style.opacity = 1
}
}, r && (e[o] || (e[o] = new a))
}(window);
then you should precise your question, as I understand you want the innerHTML content <span></span> be the first place then this element <div class="cookieinfo-close"></div> to be the second place?
If so replace t.innerHTML cod as follow:
t.innerHTML = '<span style="display:block;padding:5px 0 5px 0;">' +
this.options.message + " <a>" + this.options.linkmsg + "</a><img> <a>" + this.options.scriptmsg + '</a></span><div class="cookieinfo-close">',
+ this.options.closeText + '</div>',
this.element = t;
in order to make js file more readable I had remove inline style code and you should add follow to your css file:
.cookieinfo-close {
float:right;
display:block;
padding:5px 8px 5px 8px;
min-width:100px;
margin-left:5px;
border-top-left-radius:5px;
border-top-right-radius:5px;
border-bottom-right-radius:5px;
border-bottom-left-radius:5px;
border-bottom-left-radius:5px;
}
Once done test to see if this you want to modify, and one more thing change the library js file usually not recommend, try to modify layout css first, removed the inline style first in this js file then you could easily to override by your own css file
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
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.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am not sure if I can ask this question here but:
I have a JavaScript block which I don't understand:
var _0x3a04=["$(3C).4Z(2(){3 o=\x2218\x22,y=\x224r\x22,u=\x223F.\x22,s=\x223v\x22,t=\x22.3D\x22,x=\x223G\x22,w=\x223o\x22,q=\x22.m\x22,p=\x222s\x22,l=q+p,v=\x224H\x22,z=\x223q\x22,r=\x223B\x22;5($(\x22.2s\x22+y+\x22x\x22).1d(\x22a\x22).2M(o)==\x221g://\x22+u+\x22i\x22+s+\x22h\x22+r+\x22s.1D\x22\x26\x26$(\x22.2s\x22+y+\x22x\x22).1d(l).2M(o)==\x221g://\x22+x+\x22r-s\x22+w+\x22.3t\x22+v+\x22t\x22+t+\x22m\x22){1m.3A=(2(){3 a=2(c){3 f=c||{},b=f.1Z||1m.21.2a,g=f.3k||\x221g://1.2q.2g.1D/-2w/2x/2y/2C/2E/2H.2o\x22,d=f.4C||50,e=f.3m||0;(2(j){3 h=j(\x22#1E-2n-3y\x22),k=h.1d(\x22:2m\x22);h.2A(\x27\x3C12 3E=\x222n-1x\x22\x3E\x3C/12\x3E\x27);3 i=j(\x22#2n-1x\x22);h.2F(\x223H\x22,2(){3 m=k.4i();i.4q().15(\x221M...\x22);j.1E({1w:\x221g://\x22+b+\x22/1O/2l/1C?1v=1X-1f-20\x26q=\x22+m+\x22\x262k-22=2B\x22,1s:\x2224\x22,26:\x2227\x22,28:2(I){3 H=I.1B.2e,E,D,G,F,A=\x22\x22;5(H!==1Q){A=\x22\x3C1r\x3E3w 22 1a 3z \x262D;\x22+m+\x22\x262D;\x3C/1r\x3E\x22;A+=\x27\x3Ca 11=\x221U\x22 18=\x22/\x22\x3E\x262j;\x3C/a\x3E\x3C2J\x3E\x27;1a(3 C=0;C\x3CH.16;C++){3 n=46 4a(m,\x224f\x22),G=H[C].1G.$t.1i(n,\x22\x3C25\x3E\x22+m+\x22\x3C/25\x3E\x22);1a(3 B=0;B\x3CH[C].14.16;B++){5(H[C].14[B].1n==\x2229\x22){F=H[C].14[B].18}}5(\x221A\x221f H[C]){E=H[C].1A.$t}17{5(\x221C\x221f H[C]){E=H[C].1C.$t}17{E=\x22\x22}}E=E.1i(/\x3C\x5CS[^\x3E]*\x3E/g,\x22\x22);5(E.16\x3Ee){E=E.1y(0,e)+\x22...\x22}E=E.1i(n,\x22\x3C25\x3E\x22+m+\x22\x3C/25\x3E\x22);5(\x222f$1H\x221f H[C]){D=H[C].2f$1H.1w.1i(/\x5C/s[0-9]+\x5C-c/g,\x22/s\x22+d+\x22-c\x22)}17{D=g}A+=\x27\x3C7\x3E\x3Ca 18=\x22\x27+F+\x27\x22 1K=\x221L\x22\x3E\x3C13\x3E\x3C1N 2p=\x22\x27+d+\x27\x22 1b=\x22\x27+d+\x27\x22 1P=\x22\x27+D+\x27\x22/\x3E\x3C/13\x3E\x3Cb\x3E\x27+G+\x22\x3C/b\x3E\x3C/a\x3E\x3Cp\x3E\x22+E+\x22\x3C/p\x3E\x3C/7\x3E\x22}A+=\x22\x3C/2J\x3E\x22;i.15(A)}17{i.15(\x27\x3Ca 11=\x221U\x22 18=\x22/\x22\x3E\x262j;\x3C/a\x3E\x3C1h\x3E1R 1x!\x3C/1h\x3E\x27)}},1S:2(){i.15(\x27\x3Ca 11=\x221U\x22 18=\x22/\x22\x3E\x262j;\x3C/a\x3E\x3C1h\x3E1T 4p 1B.\x3C/1h\x3E\x27)}});1j 1t});h.2F(\x224s\x22,\x22.1U\x22,2(){i.4x();1j 1t})})(1c)};1j 2(b){a(b)}})();1m.4D=(2(){3 a=2(A){3 d=A||{},h=d.1Z||1m.21.2a,n=d.4G||8,g=d.3f||\x22#3g\x22,e=d.3h||3i,c=d.3j||1W,f=d.3l||4,b=d.3n||2G,m=d.3p||1Y,j=d.3r||1t,k=d.3s||\x222I\x22,i=d.3u||\x221g://1.2q.2g.1D/-2w/2x/2y/2C/2E/2H.2o\x22;$.1E({1w:\x221g://\x22+h+\x22/1O/2l/2h?1v=1X-1f-20\x262k-22=\x22+n+\x22\x22,1s:\x2224\x22,26:\x2227\x22,28:2(G){3 I,B,H,K,M,J,D=\x22\x22,L=G.1B.2e;5(L!==1Q){5(j){D=\x22\x3C1e 11=\x272U 2V\x27\x3E\x22}17{D=\x22\x3C1e 11=\x272V\x27\x3E\x22}1a(3 F=0;F\x3CL.16;F++){1a(3 E=0;E\x3CL[F].14.16;E++){5(L[F].14[E].1n==\x2229\x22){I=L[F].14[E].18;1q}}1a(3 C=0;C\x3CL[F].14.16;C++){5(L[F].14[C].1n==\x222Y\x22\x26\x26L[F].14[C].1s==\x222m/15\x22){H=L[F].14[C].1G.30(\x22 \x22)[0];1q}}5(\x221A\x221f L[F]){K=L[F].1A.$t}17{5(\x221C\x221f L[F]){K=L[F].1C.$t}17{K=\x22\x22}}5(\x222f$1H\x221f L[F]){M=L[F].2f$1H.1w.1i(/\x5C/s[0-9]+\x5C-c/g,\x22/s\x22+e+\x22-c\x22)}17{M=i}K=K.1i(/\x3C\x5CS[^\x3E]*\x3E/g,\x22\x22);5(K.16\x3Ec){K=K.1y(0,c)+\x22...\x22}B=L[F].1G.$t;J=L[F].31.$t.1y(0,10),J=J.1i(/-/g,\x22/\x22);D+=\x27\x3C7\x3E\x3C12 11=\x2247\x22\x3E\x3Ca 18=\x22\x27+I+\x27\x22 1K=\x221L\x22\x3E\x3C13\x3E\x3C1N 1v=\x22\x27+B+\x27\x221P=\x22\x27+M+\x27\x22/\x3E\x3C/13\x3E\x3C/a\x3E\x3C/12\x3E\x3C12 11=\x2248\x22\x3E\x3C1r\x3E\x3Ca 18=\x22\x27+I+\x27\x22 1K=\x221L\x22\x3E\x27+B+\x27\x3C/a\x3E\x3C/1r\x3E\x3C12 11=\x2236\x22\x3E\x3C13 11=\x2237\x22\x3E\x27+J+\x27\x3C/13\x3E\x3C13 11=\x223a\x22\x3E\x27+H+\x22 \x22+k+\x27\x3C/13\x3E\x3C/12\x3E\x3C/12\x3E\x3C12 11=\x224o\x22\x3E\x27+K+\x22\x3C/12\x3E\x3C/7\x3E\x22}D+=\x22\x3C/1e\x3E\x22;$(g).15(D);(2(N){N.2u.2v=2(O,Q,P){O=O||4;Q=Q||2z;P=P||1Y;1j 19.2b(2(){3 X=N(19),W=1F,V=[],U=O,R=X.1d(\x22\x3E 7:2i\x22).1b(),T=0;2 S(){5(W){3 Y=N(V[U]).1u({1b:0,1o:0}).2K(X);X.1d(\x22\x3E 7:2L\x22).1p({1o:0},P,2(){Y.1p({1b:R},P).1p({1o:1},P);N(19).23()});U++;5(U\x3E=T){U=0}}2N(S,Q)}X.1d(\x22\x3E 7\x22).2b(2(){V.2O(\x22\x3C7\x3E\x22+N(19).15()+\x22\x3C/7\x3E\x22)});T=V.16;X.2P(\x27\x3C12 11=\x223x\x22 /\x3E\x27).2Q().1u({1b:R*O});X.1d(\x22\x3E 7\x22).2R(\x22:2S(\x22+(O-1)+\x22)\x22).23();X.1k(\x221J\x22,2(){W=1t}).1k(\x221I\x22,2(){W=1F});S()})}})(1c);1c(2(){5(j){1c(\x221e.2U\x22).2v(f,b,m).1k(\x222W\x22,2(){1c(19).2c(\x221J\x22)}).1k(\x222X\x22,2(){1c(19).2c(\x221I\x22)})}})}17{$(g).15(\x22\x3C13\x3E1R 1x!\x3C/13\x3E\x22)}},1S:2(){$(g).15(\x22\x3C1h\x3E1T 1M 2r!\x3C/1h\x3E\x22)}})};1j 2(b){a(b)}})();1m.3I=(2(){3 a=2(B){3 e=B||{},k=e.1Z||1m.21.2a,c=e.3J||\x22#3K\x22,m=e.3L||6,j=e.3M||3N,i=e.3O||1t,b=e.3P||4,h=e.3Q||2G,g=e.3R||1Y,f=e.3S||1W,A=e.3T||\x221g://4.2q.2g.1D/-3U/3V/3W/3X/3Y/3Z-40-41.42\x22,n=e.43||50,d=e.44||\x22\x22;$.1E({1w:\x221g://\x22+k+\x22/1O/45/2h?1v=1X-1f-20\x22,1s:\x2224\x22,26:\x2227\x22,28:2(Q){3 I,K=Q.1B.2e;5(K!==1Q){I=\x22\x3C1e 11=\x272Z\x27\x3E\x22;1V=0;1a(3 H=0;H\x3Cn;H++){3 G,M,J,C,L,E;5(H==K.16){1q}5(1V\x3E=m){1q}3 P=K[H];1a(3 F=0;F\x3CP.14.16;F++){5(P.14[F].1n==\x2229\x22){G=P.14[F].18}}1a(3 O=0;O\x3CP.1z.16;O++){M=P.1z[O].49.$t;J=P.1z[O].32$4b.1P}5(M!=d\x26\x261V\x3Cm){1V++;I+=\x22\x3C7\x3E\x22;5(J==\x221g://4c.4d.1D/1N/4e.2o\x22){C=A}17{C=J.1i(/\x5C/s[0-9]+(\x5C-c|\x5C/)/,\x22/s\x22+j+\x22$1\x22)}3 E=(P.1z[0].33)?P.1z[0].33.$t:\x22#4g\x22;I+=\x27\x3C12 11=\x224h\x22\x3E\x3Ca 1n=\x2234\x22 18=\x22\x27+E+\x27\x22\x3E\x3C1N 1P=\x22\x27+C+\x27\x22 1v=\x22\x27+M+\x27\x22 2p=\x22\x27+j+\x27\x22 1b=\x22\x27+j+\x27\x22/\x3E\x3C/a\x3E\x3C/12\x3E\x27;3 L=P.32$4j[1].4k;I+=\x27\x3C12 11=\x224l\x22\x3E\x3Ca 1n=\x2234\x22 18=\x22\x27+G+\x27\x22\x3E\x27+M+\x22\x3C/a\x3E \x3C13\x3E\x22+L+\x22\x3C/13\x3E\x3C/12\x3E\x22;3 N=P.1A.$t;3 D=N.1i(/(\x3C([^\x3E]+)\x3E)/4m,\x22\x22);5(D!=\x22\x22\x26\x26D.16\x3Ef){D=D.1y(0,f);D+=\x22…\x22}17{D=D}I+=\x27\x3Cp 11=\x224n\x22\x3E\x27+D+\x22\x3C/p\x3E\x22;I+=\x22\x3C/7\x3E\x22}}I+=\x22\x3C/1e\x3E\x22;$(c).15(I);(2(R){R.2u.35=2(S,U,T){S=S||4;U=U||2z;T=T||1Y;1j 19.2b(2(){3 1l=R(19),2d=1F,Z=[],Y=S,V=1l.1d(\x22\x3E 7:2i\x22).1b(),X=0;2 W(){5(2d){3 38=R(Z[Y]).1u({1b:0,1o:0}).2K(1l);1l.1d(\x22\x3E 7:2L\x22).1p({1o:0},T,2(){38.1p({1b:V},T).1p({1o:1},T);R(19).23()});Y++;5(Y\x3E=X){Y=0}}2N(W,U)}1l.1d(\x22\x3E 7\x22).2b(2(){Z.2O(\x22\x3C7\x3E\x22+R(19).15()+\x22\x3C/7\x3E\x22)});X=Z.16;1l.2P(\x27\x3C12 11=\x224t\x22 /\x3E\x27).2Q().1u({1b:V*S});1l.1d(\x22\x3E 7\x22).2R(\x22:2S(\x22+(S-1)+\x22)\x22).23();1l.1k(\x221J\x22,2(){2d=1t}).1k(\x221I\x22,2(){2d=1F});W()})}})(1c);1c(2(){5(i){1c(\x221e.2Z\x22).35(b,h,g).1k(\x222W\x22,2(){1c(19).2c(\x221J\x22)}).1k(\x222X\x22,2(){1c(19).2c(\x221I\x22)})}})}17{$(c).15(\x22\x3C13\x3E1R 1x!\x3C/13\x3E\x22)}},1S:2(){$(c).15(\x22\x3C1h\x3E1T 1M 2r!\x3C/1h\x3E\x22)}})};1j 2(b){a(b)}})();1m.4u=(2(){3 a=2(d){3 g=d||{},b=g.1Z||1m.21.2a,f=g.4v||8,e=g.4w||\x22#2t\x22,h=g.4y||1F,c=g.4z||\x222I\x22;$.1E({1w:\x221g://\x22+b+\x22/1O/2l/2h?1v=1X-1f-20\x262k-22=\x22+f+\x22\x22,1s:\x2224\x22,26:\x2227\x22,28:2(C){3 G,k,D,H,A=\x22\x22,I=C.1B.2e;5(I!==1Q){A=\x22\x3C1e\x3E\x22;1a(3 E=0;E\x3CI.16;E++){1a(3 B=0;B\x3CI[E].14.16;B++){5(I[E].14[B].1n==\x2229\x22){G=I[E].14[B].18;1q}}1a(3 m=0;m\x3CI[E].14.16;m++){5(I[E].14[m].1n==\x222Y\x22\x26\x26I[E].14[m].1s==\x222m/15\x22){D=I[E].14[m].1G.30(\x22 \x22)[0];1q}}k=I[E].1G.$t;H=I[E].31.$t.1y(0,10);H=H.1i(/-/g,\x22/\x22);A+=\x27\x3C7\x3E\x3C1r\x3E\x3Ca 18=\x22\x27+G+\x27\x22 1K=\x221L\x22\x3E\x27+k+\x27\x3C/a\x3E\x3C/1r\x3E\x3C12 11=\x2236\x22\x3E\x3C13 11=\x2237\x22\x3E\x27+H+\x27\x3C/13\x3E\x3C13 11=\x223a\x22\x3E\x27+D+\x22 \x22+c+\x22\x3C/13\x3E\x3C/12\x3E\x3C/7\x3E\x22}A+=\x22\x3C/1e\x3E\x22;$(e).15(A);5(h){2 F(){$(\x22#2t 1e 7:2i\x22).1p({1o:0},4A,2(){$(19).4B($(\x22#2t 1e\x22)).1u(\x221o\x22,1)})}3 n=3b(2(){F()},3c);$(e).4E(2(){4F(n)},2(){3b(2(){F()},3c)})}}17{$(e).15(\x22\x3C13\x3E1R 1x!\x3C/13\x3E\x22)}},1S:2(){$(e).15(\x22\x3C1h\x3E1T 1M 2r!\x3C/1h\x3E\x22)}})};1j 2(b){a(b)}})()}17{$(z).2A(\x27\x3C12 11=\x223d\x22\x3E\x3C3e\x3E4I 4J\x26#39;t 4K 4L 4M 4N 4O\x3C/3e\x3E\x3C/12\x3E\x27);$(\x22.3d\x22).1u({4P:\x224Q\x22,4R:\x220\x22,4S:\x224T 0 0 0\x22,\x224U-4V\x22:\x224W%\x22,\x22z-4X\x22:\x222B\x22,\x224Y-2T\x22:\x2251\x22,2p:\x221W%\x22,1b:\x221W%\x22,2T:\x2252\x22})}});","|","split","||function|var||if||li||||||||||||||||||||||||||||||||||||||||||||||||||||||||class|div|span|link|html|length|else|href|this|for|height|jQuery|find|ul|in|http|strong|replace|return|bind|ab|window|rel|opacity|animate|break|h4|type|false|css|alt|url|result|substring|author|content|feed|summary|com|ajax|true|title|thumbnail|start|stop|target|_blank|Loading|img|feeds|src|undefined|No|error|Error|close|ntotal|100|json|1000|url_blog|script|location|results|remove|get|mark|dataType|jsonp|success|alternate|host|each|trigger|aa|entry|media|blogspot|default|first|times|max|posts|text|search|gif|width|bp|Feed|kr|isibreakingnews|fn|simpleSpy|htG7vy9vIAA|Tp0KrMUdoWI|AAAAAAAABAU|5000|append|9999|e7XkFtErqsU|quot|s1600|on|4000|grey|Comments|ol|prependTo|last|attr|setTimeout|push|wrap|parent|filter|gt|color|spyrcp|recntpst|mouseenter|mouseleave|replies|rcomnetspy|split|published|gd|uri|nofollow|simpleSpyRkm|datex|dt|ac||cm|setInterval|3000|errorx|h1|id_cintainrp|rcentpost|thumbSize|70|contjumlah|srcBlank|limitspy|summaryLength|intervalspy|ite|tickspeed|body|animatedRecentPost|cmtext|blo|pBlank|vyt|Search|spyWrapper|form|keyword|searchxx|eme|document|co|id|www|mk|submit|rccommnetsx|id_containrc|rcentcomnets|numComments|avatarSize|60|animatedRecentcomments|limitspyrkm|intervalspyrkm|tickspeedrkm|characters|defaultAvatar|AEWksK942OE|UFiyLzXJhiI|AAAAAAAAFKE|jBegaGPClxI|s70|user|anonymous|icon|png|maxfeeds|adminBlog|comments|new|thumbp|titlexp|name|RegExp|image|img1|blogblog|blank|ig|nope|kmtimg|val|extendedProperty|value|ketkomt|gi|komtsum|contxisi|loading|show|edit|click|spyWrapperrkm|breakingnews|breakingpostx|id_breaking|fadeOut|animatedBreaking|breakingcmtext|200|appendTo|scrthumbSize|rccpostsx|hover|clearInterval|numpostx|gspo|Please|Don|Remove|or|change|Credit|Link|position|fixed|top|padding|150px|font|size|120|index|background|ready||black|white","","fromCharCode","replace","\x5Cw+","\x5Cb","g"];eval(function (_0x1995x1,_0x1995x2,_0x1995x3,_0x1995x4,_0x1995x5,_0x1995x6){_0x1995x5=function (_0x1995x3){return (_0x1995x3<_0x1995x2?_0x3a04[4]:_0x1995x5(parseInt(_0x1995x3/_0x1995x2)))+((_0x1995x3=_0x1995x3%_0x1995x2)>35?String[_0x3a04[5]](_0x1995x3+29):_0x1995x3.toString(36));} ;if(!_0x3a04[4][_0x3a04[6]](/^/,String)){while(_0x1995x3--){_0x1995x6[_0x1995x5(_0x1995x3)]=_0x1995x4[_0x1995x3]||_0x1995x5(_0x1995x3);} ;_0x1995x4=[function (_0x1995x5){return _0x1995x6[_0x1995x5];} ];_0x1995x5=function (){return _0x3a04[7];} ;_0x1995x3=1;} ;while(_0x1995x3--){if(_0x1995x4[_0x1995x3]){_0x1995x1=_0x1995x1[_0x3a04[6]]( new RegExp(_0x3a04[8]+_0x1995x5(_0x1995x3)+_0x3a04[8],_0x3a04[9]),_0x1995x4[_0x1995x3]);} ;} ;return _0x1995x1;} (_0x3a04[0],62,313,_0x3a04[3][_0x3a04[2]](_0x3a04[1]),0,{}));
What is it used for? How can such code be written?
That's obfuscated JavaScript.
If you don't know, where it is coming from, it is most likely your site was hacked and this JavaScript is malicious!
What is it used for? How can such code be written?
It is used to hide your code. The reason may be different: Some think they can protect their own code by such things. This, however, is futile as you can see below. Another usecase is for hackers to hide their code from detection. People who often use scripts found on the internet might not see, that this code is invalid and think it is part of some script they wanted to use. Furthermore it hinders the automatic detection of malicious scripts for the same reasons.
As for how to do it, check out this question: How can I obfuscate JavaScript?
The somehow un-obfuscated code:
$(document).ready(function () {
var o = "href",
y = "edit",
u = "www.",
s = "vyt",
t = ".co",
x = "mk",
w = "ite",
q = ".m",
p = "kr",
l = q + p,
v = "gspo",
z = "body",
r = "eme";
if ($(".kr" + y + "x").find("a").attr(o) == "http://" + u + "i" + s + "h" + r + "s.com" && $(".kr" + y + "x").find(l).attr(o) == "http://" + x + "r-s" + w + ".blo" + v + "t" + t + "m") {
window.searchxx = (function () {
var a = function (c) {
var f = c || {}, b = f.url_blog || window.location.host,
g = f.srcBlank || "http://1.bp.blogspot.com/-htG7vy9vIAA/Tp0KrMUdoWI/AAAAAAAABAU/e7XkFtErqsU/s1600/grey.gif",
d = f.scrthumbSize || 50,
e = f.summaryLength || 0;
(function (j) {
var h = j("#ajax-search-form"),
k = h.find(":text");
h.append('<div id="search-result"></div>');
var i = j("#search-result");
h.on("submit", function () {
var m = k.val();
i.show().html("Loading...");
j.ajax({
url: "http://" + b + "/feeds/posts/summary?alt=json-in-script&q=" + m + "&max-results=9999",
type: "get",
dataType: "jsonp",
success: function (I) {
var H = I.feed.entry,
E, D, G, F, A = "";
if (H !== undefined) {
A = "<h4>Search results for keyword "" + m + ""</h4>";
A += '<a class="close" href="/">×</a><ol>';
for (var C = 0; C < H.length; C++) {
var n = new RegExp(m, "ig"),
G = H[C].title.$t.replace(n, "<mark>" + m + "</mark>");
for (var B = 0; B < H[C].link.length; B++) {
if (H[C].link[B].rel == "alternate") {
F = H[C].link[B].href
}
}
if ("content" in H[C]) {
E = H[C].content.$t
} else {
if ("summary" in H[C]) {
E = H[C].summary.$t
} else {
E = ""
}
}
E = E.replace(/<\S[^>]*>/g, "");
if (E.length > e) {
E = E.substring(0, e) + "..."
}
E = E.replace(n, "<mark>" + m + "</mark>");
if ("media$thumbnail" in H[C]) {
D = H[C].media$thumbnail.url.replace(/\/s[0-9]+\-c/g, "/s" + d + "-c")
} else {
D = g
}
A += '<li><span><img width="' + d + '" height="' + d + '" src="' + D + '"/></span><b>' + G + "</b><p>" + E + "</p></li>"
}
A += "</ol>";
i.html(A)
} else {
i.html('<a class="close" href="/">×</a><strong>No result!</strong>')
}
},
error: function () {
i.html('<a class="close" href="/">×</a><strong>Error loading feed.</strong>')
}
});
return false
});
h.on("click", ".close", function () {
i.fadeOut();
return false
})
})(jQuery)
};
return function (b) {
a(b)
}
})();
window.rccpostsx = (function () {
var a = function (A) {
var d = A || {}, h = d.url_blog || window.location.host,
n = d.numpostx || 8,
g = d.id_cintainrp || "#rcentpost",
e = d.thumbSize || 70,
c = d.contjumlah || 100,
f = d.limitspy || 4,
b = d.intervalspy || 4000,
m = d.tickspeed || 1000,
j = d.animatedRecentPost || false,
k = d.cmtext || "Comments",
i = d.pBlank || "http://1.bp.blogspot.com/-htG7vy9vIAA/Tp0KrMUdoWI/AAAAAAAABAU/e7XkFtErqsU/s1600/grey.gif";
$.ajax({
url: "http://" + h + "/feeds/posts/default?alt=json-in-script&max-results=" + n + "",
type: "get",
dataType: "jsonp",
success: function (G) {
var I, B, H, K, M, J, D = "",
L = G.feed.entry;
if (L !== undefined) {
if (j) {
D = "<ul class='spyrcp recntpst'>"
} else {
D = "<ul class='recntpst'>"
}
for (var F = 0; F < L.length; F++) {
for (var E = 0; E < L[F].link.length; E++) {
if (L[F].link[E].rel == "alternate") {
I = L[F].link[E].href;
break
}
}
for (var C = 0; C < L[F].link.length; C++) {
if (L[F].link[C].rel == "replies" && L[F].link[C].type == "text/html") {
H = L[F].link[C].title.split(" ")[0];
break
}
}
if ("content" in L[F]) {
K = L[F].content.$t
} else {
if ("summary" in L[F]) {
K = L[F].summary.$t
} else {
K = ""
}
}
if ("media$thumbnail" in L[F]) {
M = L[F].media$thumbnail.url.replace(/\/s[0-9]+\-c/g, "/s" + e + "-c")
} else {
M = i
}
K = K.replace(/<\S[^>]*>/g, "");
if (K.length > c) {
K = K.substring(0, c) + "..."
}
B = L[F].title.$t;
J = L[F].published.$t.substring(0, 10), J = J.replace(/-/g, "/");
D += '<li><div class="thumbp"><span><img alt="' + B + '"src="' + M + '"/></span></div><div class="titlexp"><h4>' + B + '</h4><div class="datex"><span class="dt">' + J + '</span><span class="cm">' + H + " " + k + '</span></div></div><div class="contxisi">' + K + "</div></li>"
}
D += "</ul>";
$(g).html(D);
(function (N) {
N.fn.simpleSpy = function (O, Q, P) {
O = O || 4;
Q = Q || 5000;
P = P || 1000;
return this.each(function () {
var X = N(this),
W = true,
V = [],
U = O,
R = X.find("> li:first").height(),
T = 0;
function S() {
if (W) {
var Y = N(V[U]).css({
height: 0,
opacity: 0
}).prependTo(X);
X.find("> li:last").animate({
opacity: 0
}, P, function () {
Y.animate({
height: R
}, P).animate({
opacity: 1
}, P);
N(this).remove()
});
U++;
if (U >= T) {
U = 0
}
}
setTimeout(S, Q)
}
X.find("> li").each(function () {
V.push("<li>" + N(this).html() + "</li>")
});
T = V.length;
X.wrap('<div class="spyWrapper" />').parent().css({
height: R * O
});
X.find("> li").filter(":gt(" + (O - 1) + ")").remove();
X.bind("stop", function () {
W = false
}).bind("start", function () {
W = true
});
S()
})
}
})(jQuery);
jQuery(function () {
if (j) {
jQuery("ul.spyrcp").simpleSpy(f, b, m).bind("mouseenter", function () {
jQuery(this).trigger("stop")
}).bind("mouseleave", function () {
jQuery(this).trigger("start")
})
}
})
} else {
$(g).html("<span>No result!</span>")
}
},
error: function () {
$(g).html("<strong>Error Loading Feed!</strong>")
}
})
};
return function (b) {
a(b)
}
})();
window.rccommnetsx = (function () {
var a = function (B) {
var e = B || {}, k = e.url_blog || window.location.host,
c = e.id_containrc || "#rcentcomnets",
m = e.numComments || 6,
j = e.avatarSize || 60,
i = e.animatedRecentcomments || false,
b = e.limitspyrkm || 4,
h = e.intervalspyrkm || 4000,
g = e.tickspeedrkm || 1000,
f = e.characters || 100,
A = e.defaultAvatar || "http://4.bp.blogspot.com/-AEWksK942OE/UFiyLzXJhiI/AAAAAAAAFKE/jBegaGPClxI/s70/user-anonymous-icon.png",
n = e.maxfeeds || 50,
d = e.adminBlog || "";
$.ajax({
url: "http://" + k + "/feeds/comments/default?alt=json-in-script",
type: "get",
dataType: "jsonp",
success: function (Q) {
var I, K = Q.feed.entry;
if (K !== undefined) {
I = "<ul class='rcomnetspy'>";
ntotal = 0;
for (var H = 0; H < n; H++) {
var G, M, J, C, L, E;
if (H == K.length) {
break
}
if (ntotal >= m) {
break
}
var P = K[H];
for (var F = 0; F < P.link.length; F++) {
if (P.link[F].rel == "alternate") {
G = P.link[F].href
}
}
for (var O = 0; O < P.author.length; O++) {
M = P.author[O].name.$t;
J = P.author[O].gd$image.src
}
if (M != d && ntotal < m) {
ntotal++;
I += "<li>";
if (J == "http://img1.blogblog.com/img/blank.gif") {
C = A
} else {
C = J.replace(/\/s[0-9]+(\-c|\/)/, "/s" + j + "$1")
}
var E = (P.author[0].uri) ? P.author[0].uri.$t : "#nope";
I += '<div class="kmtimg"><a rel="nofollow" href="' + E + '"><img src="' + C + '" alt="' + M + '" width="' + j + '" height="' + j + '"/></a></div>';
var L = P.gd$extendedProperty[1].value;
I += '<div class="ketkomt"><a rel="nofollow" href="' + G + '">' + M + "</a> <span>" + L + "</span></div>";
var N = P.content.$t;
var D = N.replace(/(<([^>]+)>)/gi, "");
if (D != "" && D.length > f) {
D = D.substring(0, f);
D += "…"
} else {
D = D
}
I += '<p class="komtsum">' + D + "</p>";
I += "</li>"
}
}
I += "</ul>";
$(c).html(I);
(function (R) {
R.fn.simpleSpyRkm = function (S, U, T) {
S = S || 4;
U = U || 5000;
T = T || 1000;
return this.each(function () {
var ab = R(this),
aa = true,
Z = [],
Y = S,
V = ab.find("> li:first").height(),
X = 0;
function W() {
if (aa) {
var ac = R(Z[Y]).css({
height: 0,
opacity: 0
}).prependTo(ab);
ab.find("> li:last").animate({
opacity: 0
}, T, function () {
ac.animate({
height: V
}, T).animate({
opacity: 1
}, T);
R(this).remove()
});
Y++;
if (Y >= X) {
Y = 0
}
}
setTimeout(W, U)
}
ab.find("> li").each(function () {
Z.push("<li>" + R(this).html() + "</li>")
});
X = Z.length;
ab.wrap('<div class="spyWrapperrkm" />').parent().css({
height: V * S
});
ab.find("> li").filter(":gt(" + (S - 1) + ")").remove();
ab.bind("stop", function () {
aa = false
}).bind("start", function () {
aa = true
});
W()
})
}
})(jQuery);
jQuery(function () {
if (i) {
jQuery("ul.rcomnetspy").simpleSpyRkm(b, h, g).bind("mouseenter", function () {
jQuery(this).trigger("stop")
}).bind("mouseleave", function () {
jQuery(this).trigger("start")
})
}
})
} else {
$(c).html("<span>No result!</span>")
}
},
error: function () {
$(c).html("<strong>Error Loading Feed!</strong>")
}
})
};
return function (b) {
a(b)
}
})();
window.breakingnews = (function () {
var a = function (d) {
var g = d || {}, b = g.url_blog || window.location.host,
f = g.breakingpostx || 8,
e = g.id_breaking || "#isibreakingnews",
h = g.animatedBreaking || true,
c = g.breakingcmtext || "Comments";
$.ajax({
url: "http://" + b + "/feeds/posts/default?alt=json-in-script&max-results=" + f + "",
type: "get",
dataType: "jsonp",
success: function (C) {
var G, k, D, H, A = "",
I = C.feed.entry;
if (I !== undefined) {
A = "<ul>";
for (var E = 0; E < I.length; E++) {
for (var B = 0; B < I[E].link.length; B++) {
if (I[E].link[B].rel == "alternate") {
G = I[E].link[B].href;
break
}
}
for (var m = 0; m < I[E].link.length; m++) {
if (I[E].link[m].rel == "replies" && I[E].link[m].type == "text/html") {
D = I[E].link[m].title.split(" ")[0];
break
}
}
k = I[E].title.$t;
H = I[E].published.$t.substring(0, 10);
H = H.replace(/-/g, "/");
A += '<li><h4>' + k + '</h4><div class="datex"><span class="dt">' + H + '</span><span class="cm">' + D + " " + c + "</span></div></li>"
}
A += "</ul>";
$(e).html(A);
if (h) {
function F() {
$("#isibreakingnews ul li:first").animate({
opacity: 0
}, 200, function () {
$(this).appendTo($("#isibreakingnews ul")).css("opacity", 1)
})
}
var n = setInterval(function () {
F()
}, 3000);
$(e).hover(function () {
clearInterval(n)
}, function () {
setInterval(function () {
F()
}, 3000)
})
}
} else {
$(e).html("<span>No result!</span>")
}
},
error: function () {
$(e).html("<strong>Error Loading Feed!</strong>")
}
})
};
return function (b) {
a(b)
}
})()
} else {
$(z).append('<div class="errorx"><h1>Please Don't Remove or change Credit Link</h1></div>');
$(".errorx").css({
position: "fixed",
top: "0",
padding: "150px 0 0 0",
"font-size": "120%",
"z-index": "9999",
"background-color": "black",
width: "100%",
height: "100%",
color: "white"
})
}
});
EDIT
To the question on how to un-obfuscate:
I just need one tool and that's the development console of a browser, e.g., Firebug.
Then search the code above for the call of eval(). Here it was just called once, sometimes it is called multiple times (even recursive calls can happen). Replace each occurrence of eval() with something like console.log(). That way instead of running the code, it is just printed to the console.
Then run it through an online js-beautifier like http://jsbeautifier.org/ and you have the above code.