Доброго дня всем!
С javascript знаком слабо поэтому не могу дернуть переменную из вложеной функции. Помогите советом. Переменная my_canvas как ее получить в глобальной области видимости ?
PngToy.prototype.fetchDataURL = function(a) {
var b = this;
return b.url = a, b.buffer = b.chunks = b.view = null, b._pos = 0, new Promise(function(c, d) {
try {
for (var e = new ArrayBuffer(a.length), f = new Uint8Array(e), g = 0, h = a.length; g < h; g++) f[g] = a.charCodeAt(g);
var i, j = new DataView(e);
2303741511 === j.getUint32(0) && 218765834 === j.getUint32(4) ? (b.buffer = j.buffer, b.view = j, i = PngToy._getChunks(b.buffer, b.view, b.doCRC, b.allowInvalid), b.chunks = i.chunks || null, b.chunks || b.allowInvalid ? c() : d(i.error)) : d("Not a PNG file.")
} catch (a) {
d(a.message)
}
})
}, $(function() {
function a() {
var a, c = !0,
d = g(),
h = g(),
i = g(),
j = "BrowserLeaks,com <canvas> 1.0",
k = document.getElementById("iframe").contentDocument.createElement("canvas");
if (k.getContext && (a = k.getContext("2d"))) {
if (d = f(), "function" == typeof k.getContext("2d").fillText) {
h = f();
try {
k.setAttribute("width", 220), k.setAttribute("height", 30), a.textBaseline = "top", a.font = "14px 'Arial'", a.textBaseline = "alphabetic", a.fillStyle = "#f60", a.fillRect(125, 1, 62, 20), a.fillStyle = "#069", a.fillText(j, 2, 15), a.fillStyle = "rgba(102, 204, 0, 0.7)", a.fillText(j, 4, 17)
} catch (b) {
console.warn("false", b), k = document.createElement("canvas"), a = k.getContext("2d"), "undefined" == typeof a || "function" != typeof k.getContext("2d").fillText ? (d = g(), h = g(), c = !1) : (k.setAttribute("width", 220), k.setAttribute("height", 30), a.textBaseline = "top", a.font = "14px 'Arial'", a.textBaseline = "alphabetic", a.fillStyle = "#f60", a.fillRect(125, 1, 62, 20), a.fillStyle = "#069", a.fillText(j, 2, 15), a.fillStyle = "rgba(102, 204, 0, 0.7)", a.fillText(j, 4, 17))
}
} else c = !1;
if (c && "function" == typeof k.toDataURL) {
var l;
try {
if (l = k.toDataURL("image/png"), "boolean" == typeof l || "undefined" == typeof l) throw e
} catch (a) {
l = ""
}
0 === l.indexOf("data:image/png") ? i = f() : c = !1
} else c = !1
} else c = !1;
if ((d), (h), (i), c) {
b(a, l)
} else $.post( "../detect2.php", { canvas: "false" })
}
function b(a, b) {
var d = atob(b.replace("data:image/png;base64,", ""));
var l = new PngToy([{
doCRC: "true"
}]);
l.fetchDataURL(d).then(function(a) {
function b(a, b) {
var c = "";
return "IHDR" == a ? (c = "PNG image header: ", c += b.width + "x" + b.height + ", ", c += b.depth + " bits/sample, ", 0 == b.type ? c += "grayscale, " : 2 == b.type ? c += "truecolor, " : 3 == b.type ? c += "paletted, " : 4 == b.type ? c += "grayscale+alpha, " : 6 == b.type && (c += "truecolor+alpha, "), "0" == b.interlaced ? c += "noninterlaced, " : "1" == b.interlaced && (c += "interlaced, "), c = c.slice(0, -2)) : "gAMA" == a ? c = "file gamma = : " + b.gamma : "sRGB" == a ? c = "sRGB color space, rendering intent: " + b.desc : "IDAT" == a ? c = "PNG image data" : "IEND" == a && (c = "end-of-image marker"), c
}
for (var d, e, f, g = "IHDR,PLTE,sPLT,tRNS,tEXt,gAMA,cHRM,sRGB,hIST,pHYs,bKGD,tIME,sBIT,oFFs,sTER,sCAL,pCAL", h = "", i = 0, j = l.chunks.length; i < j; i++) {
for (e = l.chunks[i].crc.toString(16); e.length < 8;) e = "0" + e;
//"IDAT" == l.chunks[i].name && (d = e, $("#crc").html(d.toUpperCase()));
//"IDAT" == l.chunks[i].name && (d = e, $.post( "../detect2.php", { canvas: (d.toUpperCase()) }));
"IDAT" == l.chunks[i].name && (d = e, (d.toUpperCase()));
}
var my_canvas = (d.toUpperCase());
alert(my_canvas);
$.post( "../detect2.php", { canvas: my_canvas} );
})
}
function f() {
return 'True'
}
function g() {
return 'False'
}
"undefined" != typeof window.atob && "function" == typeof Promise && "function" == typeof ArrayBuffer || ($.ajaxSetup({
cache: !0,
async: !1
}), $.getScript("./js/canvas-polyfills.js")), a()
});