Related
I used Doxygen to create documentation in HTML and now I am trying to convert the HTML files to PDF using wkhtmltopdf but encountered the below error.
The PDF is generated but content is all blank.
I am using wkhtmltopdf 0.12.6 (with patched qt), Doxygen 1.9.4
The jQuery file should be the standard javascript that is generated from Doxygen step.
wkhtmltopdf --debug-javascript --enable-local-file-access *.html output.pdf
Loading pages (1/6)
Warning: file:///C:/Users/Downloads/Mik/html/jquery.js:2 jQuery.Deferred exception: 'null' is not an object
Warning: undefined:0 TypeError: 'null' is not an object
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
S.extend({
Deferred: function(e) {
var o = [
["notify", "progress", S.Callbacks("memory"), S.Callbacks("memory"), 2],
["resolve", "done", S.Callbacks("once memory"), S.Callbacks("once memory"), 0, "resolved"],
["reject", "fail", S.Callbacks("once memory"), S.Callbacks("once memory"), 1, "rejected"]
],
i = "pending",
a = {
state: function() {
return i
},
always: function() {
return s.done(arguments).fail(arguments), this
},
"catch": function(e) {
return a.then(null, e)
},
pipe: function() {
var i = arguments;
return S.Deferred(function(r) {
S.each(o, function(e, t) {
var n = m(i[t[4]]) && i[t[4]];
s[t[1]](function() {
var e = n && n.apply(this, arguments);
e && m(e.promise) ? e.promise().progress(r.notify).done(r.resolve).fail(r.reject) : r[t[0] + "With"](this, n ? [e] : arguments)
})
}), i = null
}).promise()
},
then: function(t, n, r) {
var u = 0;
function l(i, o, a, s) {
return function() {
var n = this,
r = arguments,
e = function() {
var e, t;
if (!(i < u)) {
if ((e = a.apply(n, r)) === o.promise()) throw new TypeError("Thenable self-resolution");
t = e && ("object" == typeof e || "function" == typeof e) && e.then, m(t) ? s ? t.call(e, l(u, o, R, s), l(u, o, M, s)) : (u++, t.call(e, l(u, o, R, s), l(u, o, M, s), l(u, o, R, o.notifyWith))) : (a !== R && (n = void 0, r = [e]), (s || o.resolveWith)(n, r))
}
},
t = s ? e : function() {
try {
e()
} catch (e) {
S.Deferred.exceptionHook && S.Deferred.exceptionHook(e, t.stackTrace), u <= i + 1 && (a !== M && (n = void 0, r = [e]), o.rejectWith(n, r))
}
};
i ? t() : (S.Deferred.getStackHook && (t.stackTrace = S.Deferred.getStackHook()), C.setTimeout(t))
}
}
return S.Deferred(function(e) {
o[0][3].add(l(0, e, m(r) ? r : R, e.notifyWith)), o[1][3].add(l(0, e, m(t) ? t : R)), o[2][3].add(l(0, e, m(n) ? n : M))
}).promise()
},
promise: function(e) {
return null != e ? S.extend(e, a) : a
}
},
s = {};
return S.each(o, function(e, t) {
var n = t[2],
r = t[5];
a[t[1]] = n.add, r && n.add(function() {
i = r
}, o[3 - e][2].disable, o[3 - e][3].disable, o[0][2].lock, o[0][3].lock), n.add(t[3].fire), s[t[0]] = function() {
return s[t[0] + "With"](this === s ? void 0 : this, arguments), this
}, s[t[0] + "With"] = n.fireWith
}), a.promise(s), e && e.call(s, s), s
},
when: function(e) {
var n = arguments.length,
t = n,
r = Array(t),
i = s.call(arguments),
o = S.Deferred(),
a = function(t) {
return function(e) {
r[t] = this, i[t] = 1 < arguments.length ? s.call(arguments) : e, --n || o.resolveWith(r, i)
}
};
if (n <= 1 && (I(e, o.done(a(t)).resolve, o.reject, !n), "pending" === o.state() || m(i[t] && i[t].then))) return o.then();
while (t--) I(i[t], a(t), o.reject);
return o.promise()
}
});
var W = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;
S.Deferred.exceptionHook = function(e, t) {
C.console && C.console.warn && e && W.test(e.name) && C.console.warn("jQuery.Deferred exception: " + e.message, e.stack, t)
}, S.readyException = function(e) {
C.setTimeout(function() {
throw e
})
};
var F = S.Deferred();
I'm scraping images from a comic site and it uses an encryption algorithm to retrieve the images and parse it to a blob link. I want to stop at the decryption and return the Uint8Array and use python code to write it to a file.
import execjs
def rfc(nam):
with open(nam, 'r') as f:
return f.read()
def decryptedData(lnk):
js = execjs.compile(rfc('getAndDecrypt.js'))
resp = js.call('i', lnk)
return bytes(list(resp.values()))
res = decryptedData('https://img.mwimser2.cc/static/upload/book/id/18928/547567/4c8ca89af48c44d45893f959b16447b2.webp?v=20220724')
with open('a.webp', 'wb') as f:
f.write(res)
// getAndDecrypt.js: get and decrypt image
let CryptoJS = require("crypto-js")
let jsdom = require("jsdom")
let { JSDOM } = jsdom
let dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`)
window = dom.window
document = window.document
XMLHttpRequest = window.XMLHttpRequest
var r = "my2ecret782ecret"
function i(e) {
let a = new XMLHttpRequest;
a.open("GET", e, false)
a.responseType = "arraybuffer" //this line gets changed
a.send()
return d(s2b(a.response), r)
}
function o(e) {
let t = e.sigBytes,
r = e.words,
a = new Uint8Array(t);
for (var n = 0, s = 0; n != t;) {
var i = r[s++];
if (a[n++] = (4278190080 & i) >>> 24, n == t) break;
if (a[n++] = (16711680 & i) >>> 16, n == t) break;
if (a[n++] = (65280 & i) >>> 8, n == t) break;
a[n++] = 255 & i
}
return a
}
function d(r, a) {
let s = r,
i = CryptoJS.enc.Utf8.parse(a),
l = CryptoJS.lib.WordArray.create(s),
f = o(CryptoJS.AES.decrypt({
ciphertext: l
}, i, {
iv: i,
padding: CryptoJS.pad.Pkcs7
}));
return f;
}
The link is here if you want to further investigate it.
$(function () {
webpMachine.webpSupport.then(e => {
var t = !1,
r = "my";
let a, n, s = "ret";
async function i(e, t) {
let a = new XMLHttpRequest;
a.open("GET", e, !0), a.responseType = "arraybuffer", a.onload = async function () {
4 == a.readyState && (200 == a.status ? t.src = await d(a.response, r, t) : (console.log(key, e), f(e, key)))
}, a.send()
}
function o(e) {
const t = e.sigBytes,
r = e.words,
a = new Uint8Array(t);
for (var n = 0, s = 0; n != t;) {
var i = r[s++];
if (a[n++] = (4278190080 & i) >>> 24, n == t) break;
if (a[n++] = (16711680 & i) >>> 16, n == t) break;
if (a[n++] = (65280 & i) >>> 8, n == t) break;
a[n++] = 255 & i
}
return a
}
r += "2ecret", r += "782ec", r += "ret", $("img.lazy_img").each(function (e) {
$(this).attr("data-original", "/static/images/imagecover.png"), $(this).on("load", function () {
($(this).attr("src").indexOf("blob:") > -1 || $(this).attr("src").indexOf("base64") > -1) && ($(this).css("width", "auto").css("display", "flex").css("min-height", "0px"), window.URL.revokeObjectURL($(this).attr("src")))
})
}), $("img.lazy_img").lazyload({
threshold: 1500,
effect: "fadeIn",
load: function (e) {
let t = $(this)[0],
r = t.getAttribute("src");
r.indexOf("blob:") < 0 && r.indexOf("base64") && i(t.getAttribute("data-r-src"), t)
}
});
const c = e => new Promise(t => setTimeout(t, e)),
l = e => {
let t = new FileReader;
return t.readAsDataURL(e), new Promise(e => {
t.onloadend = (() => {
e(t.result)
})
})
};
async function d(r, a, n) {
let s = r,
i = CryptoJS.enc.Utf8.parse(a),
l = CryptoJS.lib.WordArray.create(s),
d, f = o(CryptoJS.AES.decrypt({
ciphertext: l
}, i, {
iv: i,
padding: CryptoJS.pad.Pkcs7
})),
p = "";
if (e) {
let e = new Blob([f]);
p = URL.createObjectURL(e)
} else {
let e = 0;
for (;
"" === p && e < 100;) {
if (e++, !t) {
let e;
t = !0, p = await webpMachine.decode(f), t = !1
}
"" === p && await c(300)
}
"" == p && console.log($(n).attr("data-sort"), "fail!!")
}
return p
}
function f(e, t) {
let a = new XMLHttpRequest;
a.open("GET", e, !0), a.responseType = "arraybuffer", a.onload = function () {
200 == a.status && (t.src = d(a.response, r))
}, a.send()
}
})
});
This is the original code. Take a look at the XHR requests for the webp files.
nodejs version: v18.3.0
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.
Dreamweaver colors many lines red with warning. The script works perfectly with jQuery 3! So are these DreamWeaver warnings to be neglected or should (some of these) be changed, and if so how? I have manually written them down since the can only be seen when hovering the mouse over the line numbers.
Missing semicolon (line 2)
Use strict statement (line 4)
Expected === but saw == (line 10)
Expected !==but saw != (line 23)
Expected and assignment or call but saw expression (line 33)
Missing semicolon (41)
Expected === but saw == (43)
Missing use strict statement (45)
the body of a for in statement should be wrapped in an if statement to filter unwanted properties from the prototype (46)
Expected { but saw e (52)
Expected === but saw == (53)
Expecte { but saw for (54)
Expected { but saw e (55)
Expected === but saw == (60)
Expected and assignment or call but saw expression (70)
Expected and assignment or call but saw expression (75)
Missing semicolon (77)
Expected === but saw == (84)
Expected and assignment or call but saw expression (92)
Expected { but saw for (101)
Expected and assignment or call but saw expression (103)
! function(t, e) {
"function" == typeof define && define.amd ? define("ev-emitter/ev-emitter", e) : "object" == typeof module && module.exports ? module.exports = e() : t.EvEmitter = e()
}(this, function() {
function t() {}
var e = t.prototype;
return e.on = function(t, e) {
if (t && e) {
var i = this._events = this._events || {},
n = i[t] = i[t] || [];
return -1 == n.indexOf(e) && n.push(e), this
}
}, e.once = function(t, e) {
if (t && e) {
this.on(t, e);
var i = this._onceEvents = this._onceEvents || {},
n = i[t] = i[t] || [];
return n[e] = !0, this;
}
}, e.off = function(t, e) {
var i = this._events && this._events[t];
if (i && i.length) {
var n = i.indexOf(e);
return -1 != n && i.splice(n, 1), this
}
}, e.emitEvent = function(t, e) {
var i = this._events && this._events[t];
if (i && i.length) {
var n = 0,
o = i[n];
e = e || [];
for (var r = this._onceEvents && this._onceEvents[t]; o;) {
var s = r && r[o];
s && (this.off(t, o), delete r[o]), o.apply(this, e), n += s ? 0 : 1, o = i[n]
}
return this;
}
}, t;
}),
function(t, e) {
"use strict";
"function" == typeof define && define.amd ? define(["ev-emitter/ev-emitter"], function(i) {
return e(t, i);
}) : "object" == typeof module && module.exports ? module.exports = e(t, require("ev-emitter")) : t.imagesLoaded = e(t, t.EvEmitter)
}(window, function(t, e) {
function i(t, e) {
for (var i in e) t[i] = e[i];
return t;
}
function n(t) {
var e = [];
if (Array.isArray(t)) e = t;
else if ("number" == typeof t.length)
for (var i = 0; i < t.length; i++) e.push(t[i]);
else e.push(t);
return e;
}
function o(t, e, r) {
return this instanceof o ? ("string" == typeof t && (t = document.querySelectorAll(t)), this.elements = n(t), this.options = i({}, this.options), "function" == typeof e ? r = e : i(this.options, e), r && this.on("always", r), this.getImages(), h && (this.jqDeferred = new h.Deferred), void setTimeout(function() {
this.check();
}.bind(this))) : new o(t, e, r);
}
function r(t) {
this.img = t;
}
function s(t, e) {
this.url = t, this.element = e, this.img = new Image();
}
var h = t.jQuery,
a = t.console;
o.prototype = Object.create(e.prototype), o.prototype.options = {}, o.prototype.getImages = function() {
this.images = [], this.elements.forEach(this.addElementImages, this)
}, o.prototype.addElementImages = function(t) {
"IMG" == t.nodeName && this.addImage(t); this.options.background === !0 && this.addElementBackgroundImages(t);
var e = t.nodeType;
if (e && d[e]) {
for (var i = t.querySelectorAll("img"), n = 0; n < i.length; n++) {
var o = i[n];
this.addImage(o);
}
if ("string" == typeof this.options.background) {
var r = t.querySelectorAll(this.options.background);
for (n = 0; n < r.length; n++) {
var s = r[n];
this.addElementBackgroundImages(s);
}
}
}
};
var d = {
1: !0,
9: !0,
11: !0
};
return o.prototype.addElementBackgroundImages = function(t) {
var e = getComputedStyle(t);
if (e)
for (var i = /url\((['"])?(.*?)\1\)/gi, n = i.exec(e.backgroundImage); null !== n;) {
var o = n && n[2];
o && this.addBackground(o, t), n = i.exec(e.backgroundImage)
}
}, o.prototype.addImage = function(t) {
var e = new r(t);
this.images.push(e)
}, o.prototype.addBackground = function(t, e) {
var i = new s(t, e);
this.images.push(i)
}, o.prototype.check = function() {
function t(t, i, n) {
setTimeout(function() {
e.progress(t, i, n)
})
}
var e = this;
return this.progressedCount = 0, this.hasAnyBroken = !1, this.images.length ? void this.images.forEach(function(e) {
e.once("progress", t), e.check()
}) : void this.complete()
}, o.prototype.progress = function(t, e, i) {
this.progressedCount++, this.hasAnyBroken = this.hasAnyBroken || !t.isLoaded, this.emitEvent("progress", [this, t, e]), this.jqDeferred && this.jqDeferred.notify && this.jqDeferred.notify(this, t), this.progressedCount == this.images.length && this.complete(), this.options.debug && a && a.log("progress: " + i, t, e)
}, o.prototype.complete = function() {
var t = this.hasAnyBroken ? "fail" : "done";
if (this.isComplete = !0, this.emitEvent(t, [this]), this.emitEvent("always", [this]), this.jqDeferred) {
var e = this.hasAnyBroken ? "reject" : "resolve";
this.jqDeferred[e](this)
}
}, r.prototype = Object.create(e.prototype), r.prototype.check = function() {
var t = this.getIsImageComplete();
return t ? void this.confirm(0 !== this.img.naturalWidth, "naturalWidth") : (this.proxyImage = new Image, this.proxyImage.addEventListener("load", this), this.proxyImage.addEventListener("error", this), this.img.addEventListener("load", this), this.img.addEventListener("error", this), void(this.proxyImage.src = this.img.src))
}, r.prototype.getIsImageComplete = function() {
return this.img.complete && void 0 !== this.img.naturalWidth
}, r.prototype.confirm = function(t, e) {
this.isLoaded = t, this.emitEvent("progress", [this, this.img, e])
}, r.prototype.handleEvent = function(t) {
var e = "on" + t.type;
this[e] && this[e](t)
}, r.prototype.onload = function() {
this.confirm(!0, "onload"), this.unbindEvents()
}, r.prototype.onerror = function() {
this.confirm(!1, "onerror"), this.unbindEvents()
}, r.prototype.unbindEvents = function() {
this.proxyImage.removeEventListener("load", this), this.proxyImage.removeEventListener("error", this), this.img.removeEventListener("load", this), this.img.removeEventListener("error", this)
}, s.prototype = Object.create(r.prototype), s.prototype.check = function() {
this.img.addEventListener("load", this), this.img.addEventListener("error", this), this.img.src = this.url;
var t = this.getIsImageComplete();
t && (this.confirm(0 !== this.img.naturalWidth, "naturalWidth"), this.unbindEvents())
}, s.prototype.unbindEvents = function() {
this.img.removeEventListener("load", this), this.img.removeEventListener("error", this)
}, s.prototype.confirm = function(t, e) {
this.isLoaded = t, this.emitEvent("progress", [this, this.element, e])
}, o.makeJQueryPlugin = function(e) {
e = e || t.jQuery, e && (h = e, h.fn.imagesLoaded = function(t, e) {
var i = new o(this, t, e);
return i.jqDeferred.promise(h(this))
})
}, o.makeJQueryPlugin(), o
});
Stylistic warnings in minified third party libraries can safely be ignored.
Minifiers will almost always trim semicolons when they can, while linters will always warn about semicolons missing.
How to I call a JavaScript function when Tumblr's infinite scroll loads more posts?
I figure it would have to be some sort of listener function for when tumblrAutoPager.init us called. I found the infinite scroll code online and don't really understand it.
var tumblrAutoPager = {
url: "http://proto.jp/",
ver: "0.1.7",
rF: true,
gP: {},
pp: null,
ppId: "",
LN: location.hostname,
init: function () {
if ($("autopagerize_icon") || navigator.userAgent.indexOf('iPhone') != -1) return;
var tAP = tumblrAutoPager;
var p = 1;
var lh = location.href;
var lhp = lh.lastIndexOf("/page/");
var lht = lh.lastIndexOf("/tagged/");
if (lhp != -1) {
p = parseInt(lh.slice(lhp + 6));
tAP.LN = lh.slice(7, lhp);
} else if (lht != -1) {
tAP.LN = lh.slice(7);
if (tAP.LN.slice(tAP.LN.length - 1) == "/") tAP.LN = tAP.LN.slice(0, tAP.LN.length - 1);
} else if ("http://" + tAP.LN + "/" != lh) {
return;
};
var gPFncs = [];
gPFncs[0] = function (aE) {
var r = [];
for (var i = 0, l = aE.length; i < l; i++) {
if (aE[i].className == "autopagerize_page_element") {
r = gCE(aE[i]);
break;
}
}
return r;
};
gPFncs[1] = function (aE) {
var r = [];
for (var i = 0, l = aE.length; i < l; i++) {
var arr = aE[i].className ? aE[i].className.split(" ") : null;
if (arr) {
for (var j = 0; j < arr.length; j++) {
arr[j] == "post" ? r.push(aE[i]) : null;
}
}
}
return r;
};
gPFncs[2] = function (aE) {
var r = [];
var tmpId = tAP.ppId ? [tAP.ppId] : ["posts", "main", "container", "content", "apDiv2", "wrapper", "projects"];
for (var i = 0, l = aE.length; i < l; i++) {
for (var j = 0; j < tmpId.length; j++) {
if (aE[i].id == tmpId[j]) {
r = gCE(aE[i]);
tAP.ppId = aE[i].id;
break;
}
}
}
return r;
};
for (var i = 0; i < gPFncs.length; i++) {
var getElems = gPFncs[i](document.body.getElementsByTagName('*'));
if (getElems.length) {
tAP.gP = gPFncs[i];
tAP.pp = getElems[0].parentNode;
break;
}
}
function gCE(pElem) {
var r = [];
for (var i = 0, l = pElem.childNodes.length; i < l; i++) {
r.push(pElem.childNodes.item(i))
}
return r;
}
if (!tAP.pp) {
return;
}
sendRequest.README = {
license: 'Public Domain',
url: 'http://jsgt.org/lib/ajax/ref.htm',
version: 0.516,
author: 'Toshiro Takahashi'
};
function chkAjaBrowser() {
var A, B = navigator.userAgent;
this.bw = {
safari: ((A = B.split('AppleWebKit/')[1]) ? A.split('(')[0].split('.')[0] : 0) >= 124,
konqueror: ((A = B.split('Konqueror/')[1]) ? A.split(';')[0] : 0) >= 3.3,
mozes: ((A = B.split('Gecko/')[1]) ? A.split(' ')[0] : 0) >= 20011128,
opera: ( !! window.opera) && ((typeof XMLHttpRequest) == 'function'),
msie: ( !! window.ActiveXObject) ? ( !! createHttpRequest()) : false
};
return (this.bw.safari || this.bw.konqueror || this.bw.mozes || this.bw.opera || this.bw.msie)
}
function createHttpRequest() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest()
} else {
if (window.ActiveXObject) {
try {
return new ActiveXObject('Msxml2.XMLHTTP')
} catch (B) {
try {
return new ActiveXObject('Microsoft.XMLHTTP')
} catch (A) {
return null
}
}
} else {
return null
}
}
};
function sendRequest(E, R, C, D, F, G, S, A) {
var Q = C.toUpperCase() == 'GET',
H = createHttpRequest();
if (H == null) {
return null
}
if ((G) ? G : false) {
D += ((D.indexOf('?') == -1) ? '?' : '&') + 't=' + (new Date()).getTime()
}
var P = new chkAjaBrowser(),
L = P.bw.opera,
I = P.bw.safari,
N = P.bw.konqueror,
M = P.bw.mozes;
if (typeof E == 'object') {
var J = E.onload;
var O = E.onbeforsetheader
} else {
var J = E;
var O = null
}
if (L || I || M) {
H.onload = function () {
J(H);
H.abort()
}
} else {
H.onreadystatechange = function () {
if (H.readyState == 4) {
J(H);
H.abort()
}
}
}
R = K(R, D);
if (Q) {
D += ((D.indexOf('?') == -1) ? '?' : (R == '') ? '' : '&') + R
}
H.open(C, D, F, S, A);
if ( !! O) {
O(H)
}
B(H);
H.send(R);
function B(T) {
if (!L || typeof T.setRequestHeader == 'function') {
T.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
}
return T
}
function K(X, V) {
var Z = [];
if (typeof X == 'object') {
for (var W in X) {
Y(W, X[W])
}
} else {
if (typeof X == 'string') {
if (X == '') {
return ''
}
if (X.charAt(0) == '&') {
X = X.substring(1, X.length)
}
var T = X.split('&');
for (var W = 0; W < T.length; W++) {
var U = T[W].split('=');
Y(U[0], U[1])
}
}
}
function Y(b, a) {
Z.push(encodeURIComponent(b) + '=' + encodeURIComponent(a))
}
return Z.join('&')
}
return H
}
function addNextPage(oj) {
if (oj.status == 404) {
tAP.remainFlg = false;
return;
}
var d = document.createElement("div");
d.innerHTML = oj.responseText;
var posts = tAP.gP(d.getElementsByTagName("*"));
if (posts.length < 2) {
tAP.rF = false;
return;
}
d = document.createElement("div");
d.className = "tumblrAutoPager_page_info";
tAP.pp.appendChild(d);
for (var i = 0; i < posts.length; i++) {
tAP.pp.appendChild(posts[i]);
}
var footer = $("footer");
footer ? footer.parentNode.appendChild(footer) : null;
tAP.rF = true;
}
watch_scroll();
function watch_scroll() {
var d = document.compatMode == "BackCompat" ? document.body : document.documentElement;
var r = d.scrollHeight - d.clientHeight - (d.scrollTop || document.body.scrollTop);
if (r < d.clientHeight * 2 && tAP.rF) {
tAP.rF = false;
p++;
sendRequest(addNextPage, "", "GET", "http://" + tAP.LN + "/page/" + p, true);
}
setTimeout(arguments.callee, 200);
};
function $(id) {
return document.getElementById(id)
};
},
switchAutoPage: function () {
this.rF = !this.rF;
var aE = document.getElementsByTagName('*');
for (var i = 0, l = aE.length; i < l; i++) {
if (aE[i].className == "tAP_switch") {
aE[i].firstChild.nodeValue = this.rF ? "AutoPage[OFF]" : "AutoPage[ON]";
}
}
}
};
window.addEventListener ? window.addEventListener('load', tumblrAutoPager.init, false) : window.attachEvent ? window.attachEvent("onload", tumblrAutoPager.init) : window.onload = tumblrAutoPager.init;