Skip to content

Instantly share code, notes, and snippets.

@beautyfree
Created December 11, 2014 15:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beautyfree/8fba66ee44bb2124b2b9 to your computer and use it in GitHub Desktop.
Save beautyfree/8fba66ee44bb2124b2b9 to your computer and use it in GitHub Desktop.
sovetnik.js
/*! Builded 2014-11-17 12-05 */
/*
* Copyright 2014 Metabar Sovetnik
*
* About:
* https://dl.metabar.ru/sovetnik/#/about
*
* Contacts:
* https://dl.metabar.ru/sovetnik/#/feedback
* feedback@metabar.ru
*
* How Sovetnik appeared on your computer? Want to disable it? Please read our FAQ:
* http://docs.metabar.ru/pages/viewpage.action?pageId=19366033
*/
! function(window) {
"use strict";
function Randomizer(a, b) {
this.html = a, this.saveNames = !!b;
var c = this._getAllClassesAndIds();
this.randomNames = this._createRandomNames(c), this.re = this._createRandomizationRegEx(c)
}
function runSuggestScript() {
return mbr.log("start"), mbr.settings.synchronizeSettings(), mbr.hub.trigger("statsd:init"), mbr.settings.canSendUrlVisit(document) && mbr.stats.trackUrlVisit(), mbr.settings.isSuggestScriptEnabled(document) ? (mbr.settings.saveFirstStartTime(), mbr.settings.applySettingsFromUrl(), mbr.hub.on("script:offer", function(a) {
a && mbr.settings.saveEulaAcceptTime()
}), void runParsers()) : void mbr.log("script disabled")
}
function runParsers() {
mbr.parserPipe.init().addParser(mbr.aviaParser).addParser(mbr.selectorsParser).addParser(mbr.microdataParser).addParser(mbr.searchParser).addParser(mbr.cmsParser).addParser(mbr.domainParser).addParser(mbr.couponsParser).end()
}
function setStartedState() {
var a = hashString((new Date).toDateString());
document.documentElement.setAttribute("g_init", a)
}
function isScriptStarted() {
var a = document.documentElement.getAttribute("g_init");
return !(!a || a !== hashString((new Date).toDateString()))
}
function hashString(a) {
return a.split("").reduce(function(a, b, c) {
return a + b.charCodeAt() * (c + 1)
}, 0).toString()
}
function start() {
if (!started) {
if (started = !0, document.querySelector('[href*="instiki"]')) return !1;
if (mbr.hub.init && mbr.hub.init(), mbr.stats && mbr.stats.init(), mbr.view && mbr.view.init(), mbr.environment && mbr.environment.init(), isScriptStarted()) return mbr.log("second script on the page"), void mbr.hub.trigger("script:alreadyWorked");
mbr.hub.trigger("script:start", (new Date).getTime()), mbr.iframeStorage.init("https://dl.metabar.ru"), setStartedState(), watchAjaxSites();
var a = mbr.tools.getHostname(document);
mbr.settings.init(a).then(function() {
runSuggestScript(), mbr.tools.clearPriceContextNodes()
}).catch(mbr.tools.clearPriceContextNodes)
}
}
function watchAjaxSites() {
var a = [/https?:\/\/(www\.)?google\.(ru|com)/, /https?:\/\/(www\.)?onetwotrip.com/, /https?:\/\/(www\.)?biletix.ru/, /https?:\/\/www\.pososhok.ru/, /https?:\/\/(www\.)?momondo\.ru/, /(www\.)?svyaznoy\.travel/];
if (window.location && window.location)
for (var b = 0; b < a.length; b++) a[b].test(window.location.href) && (window.addEventListener ? window.addEventListener("hashchange", function() {
runParsers()
}, !1) : window.attachEvent("hashchange", function() {
runParsers()
}))
}
var mbr = window.mbr || mbr || {};
window.mbr = mbr,
function() {
var a = {
set: function(a, b, c, d, e) {
var f = a + "=" + window.escape(b) + ";";
c && (c instanceof Date ? window.isNaN(c.getTime()) && (c = new Date) : c = new Date((new window.Date).getTime() + 1e3 * window.parseInt(c, 10) * 60 * 60 * 24), f += "expires=" + c.toGMTString() + ";"), d && (f += "path=" + d + ";"), e && (f += "domain=" + e + ";"), window.document.cookie = f
},
get: function(a) {
var b = new window.RegExp("(?:^" + a + "|;\\s*" + a + ")=(.*?)(?:;|$)", "g"),
c = b.exec(window.document.cookie);
return null === c ? null : c[1]
},
remove: function(a) {
this.set(a, "", new Date(1970, 1, 1, 1, 1), "/")
}
};
"object" == typeof mbr ? mbr.cookie = a : window.cookie = a
}(),
function a() {
var b;
b = {
_statsUrl: "//www.google-analytics.com/collect",
_converter: {
patterns: {
appview: {
applicationName: {
id: "an"
},
applicationVersion: {
id: "av"
},
contentDescription: {
id: "cd"
}
},
event: {
eventCategory: {
id: "ec"
},
eventAction: {
id: "ea"
},
eventLabel: {
id: "el"
},
eventValue: {
id: "ev"
}
},
exception: {
exceptionDescription: {
id: "exd"
},
isExceptionFatal: {
id: "exf"
}
},
experiment: {
experimentId: {
id: "xid",
required: !0
},
experimentVariant: {
id: "xvar",
required: !0
}
},
item: {
transactionId: {
id: "ti",
required: !0
},
transactionAffiliation: {
id: "ta"
},
transactionRevenue: {
id: "tr"
},
transactionShipping: {
id: "ts"
},
transactionTax: {
id: "tt"
},
itemName: {
id: "in",
required: !0
},
itemPrice: {
id: "ip"
},
itemQuantity: {
id: "iq"
},
itemCode: {
id: "ic"
},
itemCategory: {
id: "iv"
},
currencyCode: {
id: "cu"
}
},
pageview: {},
social: {
socialNetwork: {
id: "sn",
required: !0
},
socialAction: {
id: "sa",
required: !0
},
socialActionTarget: {
id: "st",
required: !0
}
},
timing: {
userTimingCategory: {
id: "utc"
},
userTimingVariableName: {
id: "utv"
},
userTimingTime: {
id: "utt"
},
userTimingLabel: {
id: "utl"
},
pageLoadTime: {
id: "plt"
},
dnsTime: {
id: "dns"
},
pageDownloadTime: {
id: "pdt"
},
redirectResponseTime: {
id: "rrt"
},
tcpConnectTime: {
id: "tcp"
},
serverResponseTime: {
id: "srt"
}
},
transaction: {
transactionId: {
id: "ti",
required: !0
},
transactionAffiliation: {
id: "ta"
},
transactionRevenue: {
id: "tr"
},
transactionShipping: {
id: "ts"
},
transactionTax: {
id: "tt"
},
itemName: {
id: "in"
},
itemPrice: {
id: "ip"
},
itemQuantity: {
id: "iq"
},
itemCode: {
id: "ic"
},
itemCategory: {
id: "iv"
},
currencyCode: {
id: "cu"
}
},
appTracking: {
applicationName: {
id: "an"
},
applicationVersion: {
id: "av"
}
},
contentInformation: {
documentLocationUrl: {
id: "dl"
},
documentHostName: {
id: "dh"
},
documentPath: {
id: "dp"
},
documentTitle: {
id: "dt"
},
contentDescription: {
id: "cd"
}
},
general: {
protocolVersion: {
id: "v",
required: !0
},
trackingId: {
id: "tid",
required: !0
},
anonymizeIp: {
id: "aip"
},
queueTime: {
id: "qt"
},
cacheBuster: {
id: "z"
}
},
session: {
sessionControl: {
id: "sc"
}
},
systemInfo: {
screenResolution: {
id: "sr"
},
viewportSize: {
id: "vp"
},
documentEncoding: {
id: "de"
},
screenColors: {
id: "sd"
},
userLanguage: {
id: "ul"
},
javaEnabled: {
id: "je"
},
flashVersion: {
id: "fl"
}
},
trafficSources: {
documentReferrer: {
id: "dr"
},
campaignName: {
id: "cn"
},
campaignSource: {
id: "cs"
},
campaignMedium: {
id: "cm"
},
campaignKeyword: {
id: "ck"
},
campaignContent: {
id: "cc"
},
campaignId: {
id: "ci"
},
googleAdwordsId: {
id: "gclid"
},
googleDisplayAdsId: {
id: "dclid"
}
},
visitor: {
clientId: {
id: "cid",
required: !0
}
}
},
eventTypes: {
pageview: !0,
appview: !0,
event: !0,
transaction: !0,
item: !0,
social: !0,
exception: !0,
timing: !0,
experiment: !0
},
convertEvent: function(a, b) {
var c = {},
d = null,
e = null;
if (!this.eventTypes.hasOwnProperty(a)) throw new Error("Unknown type " + a);
if (c.t = a, a in this.patterns) {
e = this.patterns[a];
for (d in e)
if (e.hasOwnProperty(d))
if (d in b) c[e[d].id] = b[d], delete b[d];
else if (e[d].required) throw new Error(d + " not found")
}
for (d in b) !c.hasOwnProperty(d) && b.hasOwnProperty(d) && (c[d] = b[d]);
return c
},
convertSettings: function(a) {
var b, c, d = {};
if (!a.general || !a.general.protocolVersion) throw new Error("general.protocolVersion not found");
if (!a.general || !a.general.trackingId) throw new Error("general.trackingId not found");
if (!a.visitor || !a.visitor.clientId) throw new Error("visitor.clientId not found");
for (b in a)
if (a.hasOwnProperty(b))
for (c in a[b]) a[b].hasOwnProperty(c) && (this.patterns[b] && void 0 !== this.patterns[b][c] ? d[this.patterns[b][c].id] = a[b][c] : (d[b] = d[b] || {}, d[b][c] = a[b][c]));
return d
}
},
_cacheEvents: {
defaultEvents: null,
aliases: {}
},
_settings: {
defaultSettings: null,
aliases: {}
},
_getXHR: function() {
var a;
try {
a = new XMLHttpRequest, "withCredentials" in a || !window.XDomainRequest || (a = new window.XDomainRequest)
} catch (b) {
try {
a = new ActiveXObject("Microsoft.XMLHTTP")
} catch (c) {
a = new ActiveXObject("Msxml2.XMLHTTP")
}
}
return a
},
_mixObjects: function() {
var a, b, c, d = {};
for (a = 0; a < arguments.length; a++) {
b = arguments[a];
for (c in b) b.hasOwnProperty(c) && (d[c] = b[c])
}
return d
},
_postObject: function(a, b) {
var c, d, e;
if (e = this._getXHR(), "withCredentials" in e) a = "https:" + a;
else {
if ("http:" !== window.location.protocol) return;
a = "http:" + a
}
e.open("POST", a, !0), c = [];
for (var f in b) b.hasOwnProperty(f) && "undefined" != typeof b[f] && c.push(f + "=" + encodeURIComponent(b[f]));
d = c.join("&"), e.send(d)
},
_calculateAutoParams: function(a) {
var b = {
dr: function() {
try {
return window.document.referrer
} catch (a) {
return ""
}
},
sr: function() {
try {
return window.screen.availWidth + "x" + window.screen.availHeight
} catch (a) {
return ""
}
},
vp: function() {
try {
var a = "CSS1Compat" === window.document.compatMode ? window.document.documentElement : window.document.body,
b = a.clientHeight,
c = a.clientWidth;
return c + "x" + b
} catch (d) {
return ""
}
},
de: function() {
try {
return window.document.characterSet || window.document.charset || window.document.defaultCharset
} catch (a) {
return ""
}
},
sd: function() {
try {
return window.screen.colorDepth ? window.screen.colorDepth + "-bits" : ""
} catch (a) {
return ""
}
},
ul: function() {
try {
return window.navigator.userLanguage || window.navigator.language
} catch (a) {
return ""
}
},
je: function() {
try {
return window.navigator.javaEnabled()
} catch (a) {
return ""
}
},
fl: function() {
try {
try {
var a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
try {
a.AllowScriptAccess = "always"
} catch (b) {
return "6,0,0"
}
} catch (b) {}
return new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]
} catch (c) {
try {
if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]
} catch (b) {}
}
return "0,0,0"
},
dl: function() {
try {
return window.document.location.href
} catch (a) {
return ""
}
},
dh: function() {
try {
return window.document.location.host
} catch (a) {
return ""
}
},
dp: function() {
try {
return window.document.location.pathname
} catch (a) {
return ""
}
},
dt: function() {
try {
return window.document.title
} catch (a) {
return ""
}
}
};
return b[a] ? b[a].call() : "auto"
},
init: function(a, b) {
a = this._converter.convertSettings(a), b ? this._settings.aliases[b] = a : this._settings.defaultSettings = a;
for (var c in a) a.hasOwnProperty(c) && "auto" === a[c] && (a[c] = this._calculateAutoParams(c));
for (var d, e = b ? this._cacheEvents.aliases[b] : this._cacheEvents.defaultEvents; e && e.length;) d = e.splice(0, 1), this._postObject(this._statsUrl, this._mixObjects(a, d[0]))
},
_track: function(a, b, c) {
if (b = this._converter.convertEvent(a, b), c) {
if (!this._settings.aliases[c]) return this._cacheEvents.aliases[c] = this._cacheEvents.aliases[c] || [], this._cacheEvents.aliases[c].push(b), this
} else if (!this._settings.defaultSettings) return this._cacheEvents.defaultEvents = this._cacheEvents.defaultEvents || [], this._cacheEvents.defaultEvents.push(b), this;
var d = c ? this._settings.aliases[c] : this._settings.defaultSettings;
return this._postObject(this._statsUrl, this._mixObjects(d, b)), this
},
trackAppview: function(a, b) {
var c = "appview";
return this._track(c, a, b), this
},
trackEvent: function(a, b) {
var c = "event";
return this._track(c, a, b), this
},
trackException: function(a, b) {
var c = "exception";
return this._track(c, a, b), this
},
trackExperiment: function(a, b) {
var c = "experiment";
return this._track(c, a, b), this
},
trackItem: function(a, b) {
var c = "item";
return this._track(c, a, b), this
},
trackPageview: function(a, b) {
var c = "pageview";
return this._track(c, a, b), this
},
trackSocial: function(a, b) {
var c = "social";
return this._track(c, a, b), this
},
trackTiming: function(a, b) {
var c = "timing";
return this._track(c, a, b), this
},
trackTransaction: function(a, b) {
var c = "transaction";
return this._track(c, a, b), this
}
}, window._gualib = window._gualib || b, window._gualibInit = window._gualibInit || a
}(), mbr.hub = mbr.hub || {
init: function() {
mbr.hub = new mbr.Mediator
}
}, mbr.tools = mbr.tools || {
_months: ["янв", "фев", "мар", "апр", "май", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"],
getHostname: function(a) {
a = a || window.document;
var b = a.domain;
return /^www./.test(b) && (b = b.slice(4)), b
},
isSubdomain: function(a, b) {
var c = a.indexOf(b);
return -1 === c ? !1 : 0 === c ? !0 : "." === a[c - 1]
},
priceAnalyze: function(a) {
return a = a.replace(/\s*/g, ""), a = /\d+[\.,`]*[0-9]*[\.,`]*[0-9]*/g.exec(a), a = a && a.length && a[0] || "", a = a.replace(/[^0-9,\.]/g, ""), a = a.replace(/(,|\.)$/g, ""), a = a.replace(/(,|\.)\d\d?$/g, ""), a = a.replace(/[.,]/g, ""), a = a.replace(/`*/g, "")
},
getTextContents: function(a) {
for (var b = "", c = 0; c < a.childNodes.length; c++) a.childNodes[c].nodeType == document.TEXT_NODE ? b += " " + a.childNodes[c].textContent : a.childNodes[c].nodeType == document.ELEMENT_NODE && (b += " " + this.getTextContents(a.childNodes[c]));
return b = b.replace(/\s+/g, " ").replace(/^[^\dA-Za-zА-Яа-я\(\)\.\,\$€]+/, "").replace(/[^\dA-Za-zА-Яа-я\(\)]\.\,\$€+$/, ""), b.trim()
},
getQueryParam: function(a, b) {
var c, d, e = [b, encodeURIComponent(b)];
if (-1 != a.lastIndexOf("#") ? c = a.substr(a.lastIndexOf("#") + 1) : -1 != a.indexOf("?") && (c = a.substr(a.indexOf("?") + 1)), c) {
c = c.split("&");
for (var f = 0; f < e.length; f++)
for (var g = 0; g < c.length; g++)
if (0 === c[g].indexOf(e[f] + "=")) return d = c[g].substr((e[f] + "=").length), decodeURIComponent(d.replace(/\+/g, " "))
}
},
formatDate: function(a) {
var b = /^\d{4}-(\d{2})-(\d{2})/;
return a && b.test(a) ? "(" + RegExp.$2 + " " + this._months[parseInt(RegExp.$1, 10) - 1] + ")" : ""
},
decodeHtml: function(a) {
var b = function(a) {
var b, c = document.createElement("p");
return c.innerHTML = a, b = c.textContent || c.text, c = null, b
};
return a.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);?/gi, function(a, c) {
return "#" === c[0] ? String.fromCharCode("x" === c[1].toLowerCase() ? parseInt(c.substr(2), 16) : parseInt(c.substr(1), 10)) : b("&" + c + ";")
})
},
getProfitText: function(a, b, c) {
var d = a - b,
e = "";
return d > 100 && "руб." == c && (e += d + " " + c), e
},
isMonthOfNextYear: function(a) {
var b = (new Date).getMonth();
return b > a
},
decode: function(a) {
var b, c, d, e, f, g, h, i = "",
j = 0,
k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
for (a = a.replace(/[^A-Za-z0-9\+\/\=]/g, ""); j < a.length;) e = k.indexOf(a.charAt(j++)), f = k.indexOf(a.charAt(j++)), g = k.indexOf(a.charAt(j++)), h = k.indexOf(a.charAt(j++)), b = e << 2 | f >> 4, c = (15 & f) << 4 | g >> 2, d = (3 & g) << 6 | h, i += String.fromCharCode(b), 64 != g && (i += String.fromCharCode(c)), 64 != h && (i += String.fromCharCode(d));
var l = "";
j = 0;
for (var m = 0, n = 0; j < i.length;)
if (m = i.charCodeAt(j), 128 > m) l += String.fromCharCode(m), j++;
else if (m > 191 && 224 > m) n = i.charCodeAt(j + 1), l += String.fromCharCode((31 & m) << 6 | 63 & n), j += 2;
else {
n = utftext.charCodeAt(j + 1);
var o = utftext.charCodeAt(j + 2);
l += String.fromCharCode((15 & m) << 12 | (63 & n) << 6 | 63 & o), j += 3
}
return l
},
mixin: function(a, b) {
var c = {};
for (var d in b)("undefined" == typeof c[d] || c[d] != b[d]) && (a[d] = b[d]);
return a
},
log: function(a) {
mbr.settings && mbr.settings.isLogEnabled && mbr.settings.isLogEnabled() && console.log(a)
},
getPriceContextElement: function() {
for (var a = document.getElementsByTagName("script"), b = a.length - 1; b >= 0; b--)
if (a[b].src && (a[b].src.indexOf("static/js/ecomerce-context") > -1 || a[b].src.indexOf("sovetnik.min.js") > -1 || a[b].src.indexOf("mbr=") > -1)) return a[b]
},
clearPriceContextNodes: function(a) {
if (mbr.settings.needCleanDOM()) {
a ? mbr.iframeStorage.clear() : mbr.hub.on("pipe:reject", function() {
mbr.iframeStorage.clear();
var a = document.getElementById("mbrstl"),
b = document.getElementById("mbrtmplt");
a && a.parentNode.removeChild(a), b && b.parentNode.removeChild(b)
});
var b = this.getPriceContextElement();
b && b.parentNode && b.parentNode.removeChild(b)
}
},
getCurrencyFromStr: function(a) {
if (a) {
a = a.toUpperCase();
var b = [{
pattern: /(?:EUR)|€/,
currency: "EUR"
}, {
pattern: /(?:USD)|(?:У\.Е\.)|\$/,
currency: "USD"
}, {
pattern: /(?:UAH)|(?:ГРН)|(?:₴)/,
currency: "UAH"
}, {
pattern: /(?:RUR)|(?:RUB)|(?:Р\.)|(?:РУБ)/,
currency: "RUB"
}, {
pattern: /(?:ТГ)|(?:KZT)|(?:₸)|(?:ТҢГ)|(?:TENGE)|(?:ТЕНГЕ)/,
currency: "KZT"
}],
c = b.map(function(b) {
return {
currency: b.currency,
index: a.search(b.pattern)
}
}).filter(function(a) {
return a.index > -1
}).sort(function(a, b) {
return a.index - b.index
});
return c.length ? c[0].currency : void 0
}
},
getDifferentElement: function(a) {
for (var b = [].slice.call(document.querySelectorAll(a)); b.length > 1;) b = b.map(function(a) {
return a.parentNode
}), b = b.filter(function(a) {
return a && 1 === b.filter(function(b) {
return b === a
}).length
});
if (b.length) {
try {
if (b[0].matches(a)) return b[0]
} catch (c) {
if (b[0].webkitMatchesSelector(a)) return b[0]
}
return b[0].querySelector && b[0].querySelector(a)
}
},
getUniqueElements: function(a) {
var b = [].slice.call(document.querySelectorAll(a));
if (b.length) {
if (b.filter(function(a) {
return !a.className
}).length > 0) return b.filter(function(a) {
return !a.className
});
b = b.filter(function(a) {
var c = a.className;
return 1 === b.filter(function(a) {
return a.className === c
}).length
}), b.length > 5 && (b = [])
}
return b
},
formatPrice: function(a, b) {
"USD" === b ? b = "$" : "EUR" === b && (b = "€");
var c = Math.floor(a),
d = Math.round(a % 1 * 100);
return c = c.toString().split("").map(function(a, b, c) {
return b && (c.length - b) % 3 === 0 && (a = " " + a), a
}).join(""), a = c, d && (a += "." + d), a += " " + b
}
}, mbr.log = mbr.tools.log, mbr.xhr = {
isCORSSupported: function() {
return !!this._getXHR(!0)
},
_getXHR: function(a) {
var b;
if (void 0 !== typeof XMLHttpRequest && (b = new XMLHttpRequest), a)
if ("withCredentials" in b) try {
b.withCredentials = !0
} catch (c) {
b = null
} else b = null;
else if (!b) try {
b = new ActiveXObject("Microsoft.XMLHTTP")
} catch (d) {
try {
b = new ActiveXObject("Msxml2.XMLHTTP")
} catch (c) {}
}
return b
},
get: function(a, b, c, d) {
var e, f = this._getXHR(!d);
f || c && c({
error: "CORS not supported"
}), d || (f.withCredentials = !0);
var g, h = b ? -1 === (a || "").indexOf("?") ? "?" : "&" : "";
b = b || {};
var i = [];
for (g in b) b.hasOwnProperty(g) && i.push(encodeURIComponent(g) + "=" + encodeURIComponent(b[g]));
h += i.join("&"), f.open("GET", a + h, !0), f.onreadystatechange = function() {
if (e) {
var a = (new Date).getTime() - e;
mbr.hub.trigger("server:responseEnd", a)
}
if (4 === f.readyState)
if (200 === f.status) c && c(JSON.parse(f.responseText));
else {
var b;
if ("number" == typeof f.status || "string" == typeof f.status ? (b = f.status, "string" == typeof f.statusText && (b += " " + f.statusText)) : b = "Unknown code", f.responseText) try {
var d = JSON.parse(f.responseText);
return mbr.hub.trigger("suggest:error", "Error with XHR", null, b, !1), void(c && c(d))
} catch (g) {}
c && c({
error: "Error with XHR",
errorMessage: b
})
}
}, e = (new Date).getTime(), f.send(null)
},
post: function(a, b) {
var c = this._getXHR();
c.open("POST", a, !0), c.setRequestHeader("Content-Type", "application/json;charset=UTF-8"), c.send(JSON.stringify(b))
}
}, mbr.iframeStorage = mbr.iframeStorage || {
listeners: {},
messages: [],
iframe: {},
ready: !1,
iframepath: "/static/storage/index.html",
version: 1,
generateCookie: function() {
return Math.round(9e6 * Math.random())
},
sendMessage: function(a) {
this.iframe.postMessage(a, this.host), this.iframe.postMessage(JSON.stringify(a), this.host)
},
processMessages: function() {
for (; this.messages.length;) {
var a = this.messages.pop();
this.sendMessage(a)
}
},
prepareMessage: function(a, b) {
var c = this.generateCookie();
return a.cookie = c, this.listeners[c] = b, a
},
pullMessage: function(a) {
var b = new mbr.Promise(function(b) {
a = this.prepareMessage(a, b)
}.bind(this));
return this.messages.push(a), this.ready && this.processMessages(), b
},
getVersion: function() {
var a = {
type: "MBR_STORAGE",
command: "get",
key: "version"
},
b = new mbr.Promise(function(b) {
a = this.prepareMessage(a, b)
}.bind(this));
return this.sendMessage(a), b
},
get: function(a) {
var b = {
type: "MBR_STORAGE",
command: "get",
key: a
};
return this.pullMessage(b)
},
set: function(a, b) {
var c = {
type: "MBR_STORAGE",
command: "set",
key: a,
value: b
};
return this.pullMessage(c)
},
remove: function(a) {
var b = {
type: "MBR_STORAGE",
command: "remove",
key: a
};
return this.pullMessage(b)
},
loadSettings: function() {
return this.init("https://dl.metabar.ru").then(function() {
return this.version > 1 ? this._loadSettingsV2() : this._loadSettingsV1()
}.bind(this))
},
_loadSettingsV1: function() {
var a = {
type: "MBR_STORAGE",
command: "loadSettings"
};
return this.pullMessage(a)
},
_loadSettingsV2: function() {
return mbr.Promise.all([this._loadPartnerSettings(), this._loadUserSettings()]).then(function(a) {
var b = a[0],
c = a[1];
for (var d in b) b.hasOwnProperty(d) && !c.hasOwnProperty(d) && (c[d] = b[d]);
return c
})
},
_loadPartnerSettings: function() {
var a = {
type: "MBR_STORAGE",
command: "loadPartnerSettings"
};
return this.pullMessage(a)
},
_loadUserSettings: function() {
var a = {
type: "MBR_STORAGE",
command: "loadUserSettings"
};
return this.pullMessage(a)
},
saveSettings: function(a) {
var b = {
type: "MBR_STORAGE",
command: "saveSettings",
value: a
};
this.pullMessage(b)
},
getSelector: function(a) {
var b = {
type: "MBR_STORAGE",
command: "getSelector",
domain: a
};
return this.pullMessage(b)
},
getCookies: function() {
var a = {
type: "MBR_STORAGE",
command: "getCookies"
};
return this.pullMessage(a)
},
getLocalStorage: function() {
var a = {
type: "MBR_STORAGE",
command: "getLocalStorage"
};
return this.pullMessage(a)
},
test: function() {
var a = {
type: "MBR_STORAGE",
command: "testStorage"
};
return this.pullMessage(a)
},
listener: function(a) {
var b;
if (a && a.data) {
if ("string" == typeof a.data) try {
b = JSON.parse(a.data)
} catch (c) {
return
} else b = a.data;
if (b.cookie && "MBR_STORAGE" === b.type) {
var d = this.listeners[b.cookie];
if (d) {
try {
d(b.value)
} catch (e) {}
delete this.listeners[b.cookie]
}
}
b && "MBR_SETTINGS" === b.type && b.value && (mbr.log("save settings"), mbr.settings.isUniversalScript() && mbr.settings.applySettings(b.value))
}
},
clear: function() {
mbr.settings.isOurSite(mbr.tools.getHostname(document)) || this._container && this._container.parentNode && this._container.parentNode.removeChild(this._container)
},
init: function(a) {
if (!this.readyPromise) {
var b = this;
this.readyPromise = new mbr.Promise(function(c) {
b.host = a;
var d = document.createElement("iframe");
d.style.display = "none", d.onload = function() {
b.iframe = this.contentWindow, b.getVersion().then(function(a) {
a && (b.version = a), b.ready = !0, b.messages.length && b.processMessages(), c()
})
}, d.src = b.host + b.iframepath + "?version=" + mbr.settings.getAppVersion(), b._container = d, document.body.appendChild(d), window.addEventListener ? window.addEventListener("message", function() {
b.listener.apply(b, arguments)
}, !0) : window.attachEvent("onmessage", function() {
b.listener.apply(b, arguments)
})
})
}
return mbr.iframeStorage.test().then(function(a) {
a || (mbr.stats.trackIframeException(), mbr.iframeStorage.clear(), mbr.tools.clearPriceContextNodes())
}), this.readyPromise
}
}, mbr.settings = mbr.settings || {
_defaultSettings: JSON.parse('{"trackingId":"UA-46120314-1","applicationName":"Sovetnik","offerEnabled":true,"autoShowShopList":true,"affId":1008,"universalScript":true}'),
_blacklist: {},
_defaultCampaignPrefix: "Price Suggest - ",
isKnownHttpsSite: function(a) {
return this._selector || mbr.aviaParser.isAviaDomain(a) || this.isOurSite(a)
},
_fromYandexMarket: function(a) {
var b = !1;
if (a) {
var c = a.replace(/https?:\/\//, "");
b = mbr.tools.isSubdomain(c, "market.yandex.ru")
}
return b
},
_fromDirect: function(a) {
return a.indexOf("yclid=") > 0
},
_isYandexSite: function(a) {
var b = /([^\.]+?)\.[^\.]+?$/,
c = b.exec(a);
return c && c.length > 1 ? "yandex" === c[1] || "ya" === c[1] : void 0
},
_fromYandexPartner: function(a) {
if (a) {
var b = a.replace(/https?:\/\//, "");
if (this._blacklist.yandexBlackList)
for (var c = 0; c < this._blacklist.yandexBlackList.length; c++)
if (0 === b.indexOf(this._blacklist.yandexBlackList[c])) return !0
}
return !1
},
canSendUrlVisit: function(a) {
var b = mbr.tools.getHostname(a);
if (this._settings && this._settings.sovetnikRemoved) return !1;
if (this._settings && this._settings.operaExtension) return !1;
if (this._settings && this._settings.offerEnabled && "rejected" === this._settings.offer) return !1;
if (this._blacklist.fullBlackList)
for (var c = 0; c < this._blacklist.fullBlackList.length; c++)
if (b && mbr.tools.isSubdomain(b, this._blacklist.fullBlackList[c])) return !1;
return !0
},
isSuggestScriptEnabled: function(a) {
var b = mbr.tools.getHostname(a);
if (this._settings && this._settings.sovetnikRemoved) return !1;
if (this._settings && this._settings.offerEnabled && "rejected" === this._settings.offer) return mbr.hub.trigger("script:disabled", "EulaNotAccepted"), !1;
if (this._blacklist.fullBlackList)
for (var c = 0; c < this._blacklist.fullBlackList.length; c++)
if (b && mbr.tools.isSubdomain(b, this._blacklist.fullBlackList[c])) return mbr.hub.trigger("page:fullBlackList", b), !1;
return this._isYandexSite(b) ? !1 : this._fromYandexMarket(a.referrer) ? (mbr.hub.trigger("script:disabled", "fromMarketSite"), !1) : this._fromYandexPartner(a.referrer) ? (mbr.log("from yandex partner"), !1) : this._domainDisabled ? (mbr.hub.trigger("script:domainDisabled"), mbr.hub.trigger("script:disabled", "DisabledForDomain"), !1) : "https:" !== a.location.protocol || this.isKnownHttpsSite(b) ? !0 : (mbr.hub.trigger("page:unknownHttpsSite", b), !1)
},
isProductSuggestEnabled: function(a) {
if (this._blacklist.pcBlackList)
for (var b = 0; b < this._blacklist.pcBlackList.length; b++)
if (a && mbr.tools.isSubdomain(a, this._blacklist.pcBlackList[b])) return !1;
return this._fromDirect(document.URL) ? (mbr.hub.trigger("script:disabled", "fromYandexDirect"), !1) : "/" !== window.location.pathname
},
canExtractPrice: function(a) {
if (a && this._blacklist.priceBlackList)
for (var b = 0; b < this._blacklist.priceBlackList.length; b++)
if (mbr.tools.isSubdomain(a, this._blacklist.priceBlackList[b])) return !1;
return !0
},
isAviaEnabled: function() {
return !(!this._settings || !this._settings.aviaEnabled)
},
isOtherRegionsEnabled: function() {
return !(!this._settings || !this._settings.otherRegionsEnabled)
},
canUseMicrodata: function(a) {
if (this._blacklist.microdataBlackList)
for (var b = 0; b < this._blacklist.microdataBlackList.length; b++)
if (a && mbr.tools.isSubdomain(a, this._blacklist.microdataBlackList[b])) return !1;
return !0
},
canAddRelativePosition: function(a) {
if (this._blacklist.relativePositionBlacklist)
for (var b = 0; b < this._blacklist.relativePositionBlacklist.length; b++)
if (a && mbr.tools.isSubdomain(a, this._blacklist.relativePositionBlacklist[b])) return !1;
return !0
},
canCheckCMS: function() {
return !this._selector
},
canCheckDomain: function() {
return !this._selector
},
canSearchCheck: function() {
return !this._settings.offerEnabled || "accepted" === this._settings.offer
},
canShowCoupon: function() {
return this._settings && "couponsEnabled" === this._settings.coupons
},
isOurSite: function(a) {
return a.indexOf(".metabar.ru") > -1 || "localhost" === a
},
isMbrApplication: function() {
return this._settings && this._settings.mbrApplication
},
needShowOffer: function() {
return !!this._settings.offerEnabled && !this._settings.offer
},
getViewModificators: function() {
return this._settings && this._settings.view
},
getCustomLogo: function() {
return this._settings && this._settings.customLogo
},
isUniversalScript: function() {
return this._defaultSettings && this._defaultSettings.universalScript
},
needRandomize: function() {
return !this._settingsLoaded || this._randomize
},
_onSettingsLoaded: function(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) {
b = b || {}, this._settings = b, this._settings.couponsEnabled = "couponsEnabled" === c, this._settings.sovetnikRemoved = "true" === d, this._settings.otherRegionsEnabled = "otherRegionsDisabled" !== o, mbr.hub.trigger("script:removed", this._settings.sovetnikRemoved), e ? (this._settings.offer = "accepted", mbr.hub.trigger("script:offer", !0)) : e === !1 ? (this._settings.offer = "rejected", mbr.hub.trigger("script:offer", !1)) : mbr.hub.trigger("script:offer", void 0), this._blacklist = g, this._selector = h, a || (a = "xxxxxxxxxxxxxxxxxxx".replace(/x/g, function() {
return Math.round(15 * Math.random()).toString(16)
}), mbr.iframeStorage.set("clientId", a)), this._clientId = a, this._logEnabled = !!i, this.lowestPriceOnly = "guaranteedLowestPriceOnly" === f, this._optInCount = parseInt(j, 10) || 0, this._doNotClean = !!l, this._domainDisabled = k, this._region = m && m.id, this._regionName = m && m.name, this._country = n && n.id || 225, this._firstStartTime = p, this._eulaAcceptTime = q, this._cookiesTable = r, this._localStorageTable = s, this._settingsLoaded = !0, this._randomize = !t
},
getSelector: function() {
var a = null,
b = mbr.customSelectors[mbr.tools.getHostname()];
if (this._selector)
if (this._selector.urlTemplates) {
var c = document.URL,
d = this._selector.urlTemplates.some(function(a) {
return new RegExp(a).test(c)
});
d && (a = this._selector)
} else a = this._selector;
if (b)
if (a)
for (var e in b) b.hasOwnProperty(e) && (a[e] = b[e]);
else a = b;
return a
},
needLowestPriceOnly: function() {
return !!(this.lowestPriceOnly || this.isAvitoSite() || this.isAliexpress())
},
getAppName: function() {
return this._settings && this._settings.applicationName
},
getAppVersion: function() {
return "201411171205"
},
getCampaignName: function() {
return this._settings && this._settings.campaignName
},
getTrackingId: function() {
return this._settings && this._settings.trackingId
},
getClientId: function() {
return this._clientId
},
getAffId: function() {
return this._settings && this._settings.affId
},
isLogEnabled: function() {
return this._logEnabled
},
getAffSub: function() {
return this._settings && this._settings.affSub
},
getSource: function() {
return this._settings && this._settings.source
},
isAutoShowingShopListEnabled: function() {
return this._settings && this._settings.autoShowShopList
},
getRegion: function() {
return this._region
},
getRegionName: function() {
return this._regionName
},
getCountryId: function() {
return this._region && this._country
},
isDefaultScript: function() {
return 1008 == this.getAffId() && this.isMbrApplication()
},
isAvitoSite: function() {
return location.host.indexOf("avito.ru") > -1
},
isAliexpress: function() {
return location.host.indexOf("aliexpress.com") > -1
},
isWildberries: function() {
return location.host.indexOf("wildberries.ru") > -1
},
isLamoda: function() {
return location.host.indexOf("lamoda.ru") > -1
},
needShowInvertOptIn: function() {
return this.needShowOffer() ? (this._optInCount++, mbr.iframeStorage.set("optInCount", this._optInCount), this._optInCount > 10) : !1
},
needCleanDOM: function() {
return !this._doNotClean
},
saveFirstStartTime: function() {
this._settingsLoaded && !this._firstStartTime && (this._firstStartTime = (new Date).getTime(), mbr.iframeStorage.set("firstStartTime", this._firstStartTime))
},
saveEulaAcceptTime: function() {
this._settingsLoaded && !this._eulaAcceptTime && (this._eulaAcceptTime = (new Date).getTime(), mbr.iframeStorage.set("eulaAcceptTime", this._eulaAcceptTime))
},
getActivateTime: function() {
return this._settings.offerEnabled ? this._eulaAcceptTime : this._firstStartTime
},
getFirstStartTime: function() {
return this._firstStartTime
},
getCookiesTable: function() {
return this._cookiesTable
},
getLocalStorageTable: function() {
return this._localStorageTable
},
synchronizeSettings: function() {
return this.isUniversalScript() ? this.applySettingsFromUrl() || this._waitPostMessage() : this.applySettingsFromUrl() || this.applySettings({})
},
_waitPostMessage: function() {
return new mbr.Promise(function(a) {
this._settingsApplied ? a() : this._resolvePostMessage = a, setTimeout(function() {
this._settingsApplied || this.applySettings({})
}.bind(this), 5e3)
}.bind(this))
},
applySettingsFromUrl: function() {
var a = mbr.tools.getPriceContextElement(),
b = ["affId", "applicationName", "offerEnabled", "affSub", "aviaEnabled", "autoShowShopList"];
if (a) {
var c, d = mbr.tools.getQueryParam(a.src, "settings");
if (d) c = JSON.parse(decodeURIComponent(d));
else
for (var e, f = 0; f < b.length; f++) e = mbr.tools.getQueryParam(a.src, b[f]), "undefined" != typeof e && (e = "true" === e ? !0 : "false" === e ? !1 : e, c = c || {}, c[b[f]] = e);
if (c) return this.applySettings(c)
}
},
applySettings: function(a) {
"string" == typeof a && (a = JSON.parse(a)), this._settings = this._settings || {};
var b = {};
if (a)
for (var c in a) a.hasOwnProperty(c) && ("undefined" == typeof this._settings[c] && (this._settings[c] = a[c]), b[c] = a[c]);
if (this._defaultSettings) {
this._defaultSettings.aviaEnabled = !0;
for (c in this._defaultSettings) this._defaultSettings.hasOwnProperty(c) && ("undefined" == typeof this._settings[c] && (this._settings[c] = this._defaultSettings[c]), "undefined" == typeof b[c] && (b[c] = this._defaultSettings[c]))
}
return !this._settings.campaignName && this._settings.applicationName && (this._settings.campaignName = this._defaultCampaignPrefix + this._settings.applicationName), !this._settings.mbrApplication && this._settings.applicationName && mbr.iframeStorage.set("appName", this._settings.applicationName), this._resolvePostMessage && this._resolvePostMessage(), this._settingsApplied = !0, mbr.iframeStorage.saveSettings(b), mbr.Promise.resolve()
},
init: function(a) {
var b = mbr.Promise.all([mbr.iframeStorage.get("clientId"), mbr.iframeStorage.loadSettings(), mbr.iframeStorage.get("coupons"), mbr.iframeStorage.get("sovetnikRemoved"), mbr.iframeStorage.get("mbr.offerAccepted"), mbr.iframeStorage.get("typePrice"), mbr.iframeStorage.get("blacklist"), mbr.iframeStorage.getSelector(a), mbr.iframeStorage.get("logEnabled"), mbr.iframeStorage.get("optInCount"), mbr.iframeStorage.get(a), mbr.iframeStorage.get("doNotClean"), mbr.iframeStorage.get("activeCity"), mbr.iframeStorage.get("activeCountry"), mbr.iframeStorage.get("otherRegions"), mbr.iframeStorage.get("firstStartTime"), mbr.iframeStorage.get("eulaAcceptTime"), mbr.iframeStorage.get("cookies"), mbr.iframeStorage.get("localStorage"), mbr.iframeStorage.get("noRandomize")]);
return b.then(function(a) {
this._onSettingsLoaded.apply(this, a)
}.bind(this)), b
}
}, mbr.environment = mbr.environment || {
_pageInBlackList: function(a) {
window.postMessage({
type: "MBR_ENVIRONMENT",
command: "blacklist",
value: a
}, "*")
},
_sovetnikRemoved: function(a) {
window.postMessage({
type: "MBR_ENVIRONMENT",
command: "removed",
value: a
}, "*")
},
_offerAccepted: function(a) {
window.postMessage({
type: "MBR_ENVIRONMENT",
command: "offerAccepted",
value: a
}, "*")
},
init: function() {
mbr.hub.on("page:fullBlackList", this._pageInBlackList), mbr.hub.on("page:unknownHttpsSite", this._pageInBlackList), mbr.hub.on("script:removed", this._sovetnikRemoved), mbr.hub.on("script:offer", this._offerAccepted)
}
}, mbr.stats = mbr.stats || {
_cacheStatsdCount: [],
_cacheStatsdTimings: [],
_sendStatsdCount: function(a, b) {
var c = document.location.protocol + "//collector.metabar.ru/count";
if (a && b && this._cacheStatsdCount.push({
name: a,
value: b
}), this._statsdInitialized)
for (var d; this._cacheStatsdCount.length;) {
d = this._cacheStatsdCount.shift();
var e = mbr.xhr && mbr.xhr.isCORSSupported() || !mbr.JSONP ? mbr.xhr : mbr.JSONP;
e.get(c, {
name: d.name.replace("<aff_id>", mbr.settings.getAffId()),
value: d.value
}, null, !0)
}
},
_sendStatsdTiming: function(a, b) {
var c = document.location.protocol + "//collector.metabar.ru/timing";
if (a && b && this._cacheStatsdCount.push({
name: a,
value: b
}), this._statsdInitialized)
for (var d; this._cacheStatsdTimings.length;) {
d = this._cacheStatsdTimings.shift();
var e = mbr.xhr && mbr.xhr.isCORSSupported() || !mbr.JSONP ? mbr.xhr : mbr.JSONP;
e.get(c, {
name: d.name,
value: d.value
}, null, !0)
}
},
_getDomain: function() {
return document.domain
},
_getTypeView: function(a) {
return "product" === a ? "PriceBar" : "avia" === a ? "AviaBar" : a
},
initGUA: function(a, b) {
a = a || {}, "string" != typeof b && (b = null), window._gualib && window._gualib.init({
general: {
protocolVersion: 1,
trackingId: a.trackingId || mbr.settings.getTrackingId()
},
visitor: {
clientId: a.clientId || mbr.settings.getClientId()
},
trafficSources: {
documentReferrer: "auto",
campaignName: a.campaignName || mbr.settings.getCampaignName(),
campaignSource: a.campaignSource || mbr.tools.getHostname(document),
campaignMedium: a.method,
campaignKeyword: a.keyword
},
systemInfo: {
screenResolution: "auto",
viewportSize: "auto",
documentEncoding: "auto",
screenColors: "auto",
userLanguage: "auto"
},
appTracking: {
applicationName: a.applicationName || mbr.settings.getAppName(),
applicationVersion: a.applicationVersion || mbr.settings.getAppVersion()
}
}, b)
},
trackItemFound: function() {
window._gualib && window._gualib.trackAppview({
contentDescription: "ProductFound",
sc: "start"
}), mbr.log("send ProductFound")
},
trackItemError: function(a, b, c, d) {
window._gualib && (window._gualib.trackEvent({
eventCategory: "PriceContextServer",
eventAction: a,
eventLabel: c,
cd: "ServerResponse: " + a
}), window._gualib.trackAppview({
contentDescription: "ServerResponse: " + a
}), window._gualib.trackException({
exceptionDescription: c,
isExceptionFatal: d ? 1 : 0
})), mbr.log("send Error")
},
trackItemNotShow: function(a) {
window._gualib && window._gualib.trackAppview({
contentDescription: "PricebarNotShown: " + a
}), mbr.log("send PricebarNotShown")
},
trackOfferFound: function(a) {
window._gualib && window._gualib.trackAppview({
contentDescription: "OfferFound"
}), window._gualib && window._gualib.trackEvent({
eventCategory: "PriceContextServer",
eventAction: "OfferFound",
eventLabel: a.category,
cd: "OfferFound"
}), mbr.log("send OfferFound")
},
trackShow: function(a) {
var b = this._getTypeView(a).toLowerCase(),
c = "suggest_script.<aff_id>.sitebar.<bar_type>.shown".replace("<bar_type>", b);
this._sendStatsdCount(c, 1);
var d, e = {
contentDescription: this._getTypeView(a) + "IsShown"
},
f = (new Date).getTime(),
g = mbr.settings.getActivateTime();
g ? (d = Math.floor((f - g) / 864e5), e["cm[2]"] = d) : e["cm[2]"] = 0, window._gualib && window._gualib.trackAppview(e), mbr.log("send PricebarIsShown")
},
trackPriceBarClose: function(a) {
var b = this._getTypeView(a).toLowerCase(),
c = "suggest_script.<aff_id>.sitebar.<bar_type>.closed.click".replace("<bar_type>", b);
this._sendStatsdCount(c, 1), window._gualib && window._gualib.trackAppview({
contentDescription: "CloseButtonClick"
}), mbr.log("send CloseButtonClick")
},
trackDisallowDomain: function(a) {
var b = this._getTypeView(a).toLowerCase(),
c = "suggest_script.<aff_id>.sitebar.<bar_type>.settings_dlg.disable_domain.checked".replace("<bar_type>", b);
this._sendStatsdCount(c, 1), window._gualib && window._gualib.trackEvent({
eventCategory: a,
eventAction: "DisableForDomainClick",
eventLabel: this._getDomain(),
cd: this._getTypeView(a) + "IsShown"
}), mbr.log("send DisableForDomainClick")
},
trackClick: function(a, b, c) {
var d = this._getTypeView(a).toLowerCase();
if (a = this._getTypeView(a), c = this._getTypeView(c) || c, window._gualib) {
if (window._gualib.trackEvent({
eventCategory: a,
eventAction: c + "Click",
eventLabel: this._getDomain(),
eventValue: 1,
cd: a + "IsShown"
}), c === a) {
window._gualib.trackAppview({
contentDescription: a + "Click"
});
var e = "suggest_script.<aff_id>.sitebar.<bar_type>.click".replace("<bar_type>", d);
this._sendStatsdCount(e, 1)
}
b && window._gualib.trackEvent({
eventCategory: a,
eventAction: a + "ButtonClick",
eventLabel: this._getDomain(),
eventValue: 1,
cd: a + "IsShown"
}), mbr.log("send PriceBarClick")
}
},
trackErrorButtonClick: function(a) {
window._gualib && window._gualib.trackEvent({
eventCategory: "FeedbackPopup",
eventAction: a,
eventLabel: mbr.tools.getHostname(document)
})
},
trackOptInShow: function(a, b) {
b = this._getTypeView(b).toLowerCase();
var c = "suggest_script.<aff_id>.sitebar.<bar_type>.optin.shown".replace("<bar_type>", b);
this._sendStatsdCount(c, 1);
var d = a ? "Bright" : "";
d += "OptInShown", window._gualib && window._gualib.trackAppview({
contentDescription: d
}), mbr.log("send " + d)
},
trackOptInAccept: function(a, b) {
b = this._getTypeView(b).toLowerCase();
var c = "suggest_script.<aff_id>.sitebar.<bar_type>.optin.accept".replace("<bar_type>", b);
this._sendStatsdCount(c, 1);
var d = a ? "Bright" : "";
d += "OptInAccept", window._gualib && window._gualib.trackAppview({
contentDescription: d
}), mbr.log("send " + d)
},
trackOptInDecline: function(a, b) {
b = this._getTypeView(b).toLowerCase();
var c = "suggest_script.<aff_id>.sitebar.<bar_type>.optin.decline".replace("<bar_type>", b);
this._sendStatsdCount(c, 1);
var d = a ? "Bright" : "";
d += "OptInDecline", window._gualib && window._gualib.trackAppview({
contentDescription: d
}), mbr.log("send " + d)
},
trackShowInfoPopup: function(a) {
a = this._getTypeView(a).toLowerCase();
var b = "suggest_script.<aff_id>.sitebar.<bar_type>.about_dlg.shown".replace("<bar_type>", a);
this._sendStatsdCount(b, 1)
},
trackShowSettingsPopup: function(a) {
a = this._getTypeView(a).toLowerCase();
var b = "suggest_script.<aff_id>.sitebar.<bar_type>.settings_dlg.shown ".replace("<bar_type>", a);
this._sendStatsdCount(b, 1)
},
trackCouponShown: function() {
window._gualib && window._gualib.trackAppview({
contentDescription: "CouponNotifyShown"
}), mbr.log("send CouponNotifyShown")
},
trackCouponsListShown: function() {
window._gualib && window._gualib.trackAppview({
contentDescription: "CouponNotifyAllShown"
}), mbr.log("send CouponNotifyAllShown")
},
trackCouponsDisallowDomain: function() {
window._gualib && window._gualib.trackEvent({
eventCategory: "CouponNotify",
eventAction: "DisableForDomainClick",
eventLabel: this._getDomain(),
cd: "CouponNotifyShown"
}), mbr.log("send DisableForDomainClick")
},
trackCouponClick: function() {
window._gualib && (window._gualib.trackAppview({
contentDescription: "CouponNotifyClick"
}), window._gualib.trackEvent({
eventCategory: "CouponNotify",
eventAction: "CouponNotifyClick",
eventLabel: mbr.tools.getHostname(document),
eventValue: 1,
cd: "CouponNotifyShown"
}), mbr.log("send CouponNotifyClick"))
},
trackSearchDefault: function(a, b) {
window._gualib && window._gualib.trackEvent({
eventCategory: a,
eventAction: "Search",
eventLabel: b
}, "searchStats"), mbr.log("send search stats")
},
trackAvito: function(a, b) {
window._gualib && window._gualib.trackEvent({
eventCategory: "AVITO",
eventAction: a,
eventLabel: b
}, "searchStats"), mbr.log("send avito stats")
},
trackSuperJob: function(a, b) {
window._gualib && window._gualib.trackEvent({
eventCategory: "SuperJob",
eventAction: b,
eventLabel: a
}, "searchStats"), mbr.log("send superjob stats")
},
trackSearch: function(a) {
this.initGUA({
trackingId: "UA-47302089-3",
campaignSource: mbr.tools.getHostname(document),
keyword: a.query
}, "searchStats"), "Mail.ru" === a.engine || "Yandex" === a.engine || "Google" === a.engine ? this.trackSearchDefault(a.engine, a.query) : "SuperJob" === a.engine ? this.trackSuperJob(a.query, a.type) : "Avito" === a.engine && this.trackAvito(a.section, a.subSection)
},
trackIframeException: function() {
this.initGUA({
trackingId: "UA-47302089-1",
clientId: 1
}, "exception"), window._gualib && window._gualib.trackException({
exceptionDescription: "Error in iframe storage"
}, "exception")
},
trackScriptAlreadyWorked: function() {
var a = "lastAlreadyWorked",
b = "suggest_script.<aff_id>.script.stopped.already_worked";
this._sendStatsdCount(b, 1), mbr.iframeStorage.get(a).then(function(b) {
var c = (new Date).getTime();
(!b || c - parseInt(b, 10) > 864e5) && (mbr.iframeStorage.set(a, c), window._gualib && window._gualib.trackEvent({
eventCategory: "EcomerceJS",
eventAction: "AlreadyWorked"
}))
})
},
trackScriptDisabled: function(a) {
this.initGUA();
var b = "suggest_script.<aff_id>.script.stopped.<reason>".replace("<reason>", a);
if (this._sendStatsdCount(b, 1), "EulaNotAccepted" === a) {
var c = "lastEulaNotAccepted";
mbr.iframeStorage.get(c).then(function(b) {
var d = (new Date).getTime();
(!b || d - parseInt(b, 10) > 864e5) && (mbr.iframeStorage.set(c, d), window._gualib && window._gualib.trackEvent({
eventCategory: "EcomerceJS",
eventAction: "SuggestScriptStopped",
eventLabel: a
}))
})
} else window._gualib && window._gualib.trackEvent({
eventCategory: "EcomerceJS",
eventAction: "SuggestScriptStopped",
eventLabel: a
});
mbr.log("script stopped " + a)
},
trackShopButtonClicked: function() {
window._gualib && window._gualib.trackEvent({
eventCategory: "PriceBar",
eventAction: "AllOffersButtonClick",
eventLabel: mbr.tools.getHostname(),
eventValue: 0,
cd: "PricebarIsShown"
}), mbr.log("All shops button is clicked")
},
trackShopListShown: function(a) {
var b = a ? "shop_list" : "dress_carousel",
c = "suggest_script.<aff_id>.popup.<popup_type>.shown".replace("<popup_type>", b);
this._sendStatsdCount(c, 1), window._gualib && window._gualib.trackAppview({
contentDescription: "OffersListIsShown"
}), mbr.log("Shoplist is shown")
},
trackShopClick: function(a, b, c) {
var d = c ? "shop_list" : "dress_carousel",
e = "suggest_script.<aff_id>.popup.<popup_type>.offerslist.<type_click>.click".replace("<type_click>", a.toLowerCase()).replace("<popup_type>", d);
this._sendStatsdCount(e, 1), window._gualib && window._gualib.trackEvent({
eventCategory: "OffersList",
eventAction: a,
eventLabel: b,
eventValue: 1,
cd: "OffersListIsShown"
}), mbr.log("shop clicked + " + a + " + " + b)
},
trackShopListCloseClick: function(a) {
var b = a ? "shop_list" : "dress_carousel",
c = "suggest_script.<aff_id>.popup.<popup_type>.closed.click".replace("<popup_type>", b);
this._sendStatsdCount(c, 1), window._gualib && window._gualib.trackEvent({
eventCategory: "OffersList",
eventAction: "OffersListCloseClick",
eventLabel: mbr.tools.getHostname(document),
eventValue: 0,
cd: "OffersListIsShown"
})
},
trackUrlVisit: function() {
var a = "//uv.metabar.ru/foo?",
b = {
url: encodeURIComponent(document.URL),
aff_id: mbr.settings.getAffId(),
v: mbr.settings.getAppVersion(),
client_id: mbr.settings.getClientId(),
time: (new Date).getTime()
},
c = [];
for (var d in b) b.hasOwnProperty(d) && c.push(d + "=" + b[d]);
a += c.join("&");
var e = document.createElement("img");
e.width = 1, e.height = 1, e.src = a, e.style.position = "absolute", e.style.bottom = 0, e.style.right = 0, e.style.visibility = "hidden", e.style.zIndex = 0, e.onload = function() {
mbr.log("url visit is tracked"), e.parentNode && e.parentNode.removeChild(e)
}, document.body.appendChild(e)
},
trackTiming: function(a, b) {
if ("start" === b) this._cacheStartTime = a;
else if ("server" === b) this._cacheServerResponseTime = a;
else if ("show" === b && window._gualib && window.performance && window.performance.timing) {
var c = window.performance.timing.responseEnd,
d = window.performance.timing.domContentLoadedEventStart,
e = window.performance.timing.loadEventStart;
c && (this._sendStatsdTiming("suggest_script.<aff_id>.script.startTime.AfterResponseEnd", this._cacheStartTime - c), this._sendStatsdTiming("suggest_script.<aff_id>.script.showTime.AfterResponseEnd", a - c), window._gualib.trackTiming({
userTimingCategory: "SuggestStartTime",
userTimingVariableName: "startAfterResponseEnd",
userTimingTime: this._cacheStartTime - c
}), window._gualib.trackTiming({
userTimingCategory: "SuggestShowTime",
userTimingVariableName: "showAfterResponseEnd",
userTimingTime: a - c
})), d && (this._sendStatsdTiming("suggest_script.<aff_id>.script.startTime.AfterDOMContentLoaded", this._cacheStartTime - d), this._sendStatsdTiming("suggest_script.<aff_id>.script.showTime.AfterDOMContentLoaded", a - d), window._gualib.trackTiming({
userTimingCategory: "SuggestStartTime",
userTimingVariableName: "startAfterDOMContentLoaded",
userTimingTime: this._cacheStartTime - d
}), window._gualib.trackTiming({
userTimingCategory: "SuggestShowTime",
userTimingVariableName: "showAfterDOMContentLoaded",
userTimingTime: a - d
})), e && (this._sendStatsdTiming("suggest_script.<aff_id>.script.startTime.AfterOnLoad", this._cacheStartTime - e), this._sendStatsdTiming("suggest_script.<aff_id>.script.showTime.AfterOnLoad", a - e), window._gualib.trackTiming({
userTimingCategory: "SuggestStartTime",
userTimingVariableName: "startAfterOnLoad",
userTimingTime: this._cacheStartTime - e
}), window._gualib.trackTiming({
userTimingCategory: "SuggestShowTime",
userTimingVariableName: "showAfterOnLoad",
userTimingTime: a - e
})), this._cacheServerResponseTime && (this._sendStatsdTiming("suggest_script.<aff_id>.script.serverTime.ResponseTime", this._cacheServerResponseTime), window._gualib.trackTiming({
userTimingCategory: "SuggestServerTime",
userTimingVariableName: "serverResponseTime",
userTimingTime: this._cacheServerResponseTime
}))
}
},
init: function() {
this._initialized || (this._initialized = !0, mbr.hub.on("parser:found", this.initGUA, null, this), mbr.hub.on("parser:found", this.trackItemFound, null, this), mbr.hub.on("domainParser:found", this.initGUA, null, this), mbr.hub.on("suggest:error", this.trackItemError, null, this), mbr.hub.on("suggest:productOfferFound", this.trackOfferFound, null, this), mbr.hub.on("pricebar:show", this.trackShow, null, this), mbr.hub.on("pricebar:close", this.trackPriceBarClose, null, this), mbr.hub.on("pricebar:disallowDomain", this.trackDisallowDomain, null, this), mbr.hub.on("pricebar:click", this.trackClick, null, this), mbr.hub.on("pricebar:optInShow", this.trackOptInShow, null, this), mbr.hub.on("pricebar:optInAccept", this.trackOptInAccept, null, this), mbr.hub.on("pricebar:optInDecline", this.trackOptInDecline, null, this), mbr.hub.on("pricebar:errorClick", this.trackErrorButtonClick, null, this), mbr.hub.on("pricebar:showInfoPopup", this.trackShowInfoPopup, null, this), mbr.hub.on("pricebar:showSettingsPopup", this.trackShowSettingsPopup, null, this), mbr.hub.on("couponView:show", this.trackCouponShown, null, this), mbr.hub.on("couponView:showList", this.trackCouponsListShown, null, this), mbr.hub.on("couponView:disallowDomain", this.trackCouponsDisallowDomain, null, this), mbr.hub.on("couponView:click", this.trackCouponClick, null, this), mbr.hub.on("search", this.trackSearch, null, this), mbr.hub.once("script:disabled", this.trackScriptDisabled, null, this), mbr.hub.on("script:alreadyWorked", this.trackScriptAlreadyWorked, null, this), mbr.hub.on("shop:allButtonClicked", this.trackShopButtonClicked, null, this), mbr.hub.on("shop:openList", this.trackShopListShown, null, this), mbr.hub.on("shop:opened", this.trackShopClick, null, this), mbr.hub.on("shop:closeButtonClicked", this.trackShopListCloseClick, null, this), mbr.hub.on("script:start", function(a) {
this.trackTiming(a, "start")
}, null, this), mbr.hub.on("pricebar:render", function(a) {
this.trackTiming(a, "show")
}, null, this), mbr.hub.on("server:responseEnd", function(a) {
this.trackTiming(a, "server")
}, null, this), mbr.hub.on("statsd:init", function() {
this._statsdInitialized = !0, this._sendStatsdCount(), this._sendStatsdTiming()
}, null, this))
}
}, mbr.suggest = mbr.suggest || {
_addScriptDataToParams: function(a) {
var b = {},
c = mbr.settings.getAffId && mbr.settings.getAffId(),
d = mbr.settings.getAppVersion && mbr.settings.getAppVersion(),
e = mbr.settings.getAffSub && mbr.settings.getAffSub(),
f = mbr.settings.getSource && mbr.settings.getSource(),
g = mbr.settings.getRegion && mbr.settings.getRegion(),
h = mbr.settings.getCountryId && mbr.settings.getCountryId(),
i = mbr.settings.getClientId && mbr.settings.getClientId(),
j = mbr.settings.needShowOffer && mbr.settings.needShowOffer(),
k = mbr.settings.getFirstStartTime && mbr.settings.getFirstStartTime(),
l = mbr.settings.getActivateTime && mbr.settings.getActivateTime();
c && (b.aff_id = c), d && (b.v = d), e && (b.aff_sub = e), f && (b.source = f), g && (b.region = g), h && (b.country = h), i && (b.clientid = i), j && (b.opt_in = j), l && (b.activate_time = l), k && (b.first_run = k), b.lowest_only = !(!mbr.settings.needLowestPriceOnly || !mbr.settings.needLowestPriceOnly());
for (var m in a) a.hasOwnProperty(m) && (b[m] = a[m]);
return b
},
_getNetProvider: function() {
return mbr.xhr && mbr.xhr.isCORSSupported() || !mbr.JSONP ? mbr.xhr : mbr.JSONP
},
_getURL: function(a, b) {
var c, d = -1 === (a || "").indexOf("?") ? "?" : "&";
b = b || {};
var e = [];
for (c in b) b.hasOwnProperty(c) && e.push(encodeURIComponent(c) + "=" + encodeURIComponent(b[c]));
return d += e.join("&"), a + d
},
getProductOffers: function(a) {
mbr.log("get offers");
var b = {
text: a.productName,
url: a.url
};
a.productPrice > 0 && (b.price = a.productPrice), a.currency && (b.currency = a.currency), b = this._addScriptDataToParams(b), b.other_reg = !(!mbr.settings.isOtherRegionsEnabled || !mbr.settings.isOtherRegionsEnabled()), b.method = a.method, mbr.log("get lowest price"), mbr.log(b);
var c = this._getNetProvider();
return a.query = this._getURL("https://suggest.metabar.ru/products?", b), new mbr.Promise(function(d, e) {
c.get(a.query, null, function(c) {
!c.error && c.offers && c.offers.length && c.offers[0].price ? (c.original = a, c.offers = c.offers.map(function(a) {
if (b.price) {
var c = parseInt(a.price.value, 10);
a.price.isHigherThanCurrent = c > b.price, a.price.isEqualToCurrent = c === b.price, a.price.isLowerThanCurrent = c < b.price
}
return a
}), c.method = a.method, mbr.log("offers found"), mbr.log(c), mbr.hub.trigger("suggest:productOfferFound", c), d(c)) : (mbr.log("have not offers"), c && c.error && mbr.hub.trigger("suggest:error", c.error, a && a.productName, c.errorMessage, !0), e(c))
})
})
},
getFlights: function(a) {
if (mbr.log(a), a.origin && a.destination && a.departure_at && a.return_at) {
var b = {
origin: a.origin,
destination: a.destination,
departure_at: a.departure_at,
return_at: a.return_at,
url: a.url
};
a.price && (b.price = a.person ? a.price / a.person : a.price), a.currency && (b.currency = a.currency), b = this._addScriptDataToParams(b);
var c = this._getNetProvider();
return a.query = this._getURL("https://suggest.metabar.ru/avia?", b), new mbr.Promise(function(b, d) {
c.get(a.query, null, function(c) {
c && c.avia && c.avia.length ? (c.avia[0].original = a, mbr.log("avia found"), mbr.log(c), mbr.hub.trigger("suggest:aviaFound", c.avia[0]), b(c)) : d(c)
})
})
}
return mbr.Promise.reject()
},
getCoupons: function(a) {
if (a) {
var b = {
url: a
};
b = this._addScriptDataToParams(b);
var c = this._getNetProvider();
return new mbr.Promise(function(a, d) {
c.get("https://suggest.metabar.ru/coupons?", b, function(b) {
mbr.log("cpupons found"), mbr.log(b), b && b.coupons && b.coupons.length ? a(b.coupons) : d(b)
})
})
}
return mbr.Promise.reject()
},
getProductOfferByURL: function(a) {
mbr.log("get offers by url");
var b = {
url: a.url,
price: a.productPrice
};
b = this._addScriptDataToParams(b), b.method = "url-search", mbr.log("get product offer by url"), mbr.log(b);
var c = this._getNetProvider();
return b.query = this._getURL("https://suggest.metabar.ru/products?", b), new mbr.Promise(function(d, e) {
c.get(b.query, null, function(c) {
if (!c.error && c.offers && c.offers.length && c.offers[0].price) {
c.original = a;
var f = c.convertedPrice || b.price;
c.offers = c.offers.map(function(a) {
if (f) {
var b = parseInt(a.price.value, 10);
a.price.isHigherThanCurrent = b > f, a.price.isEqualToCurrent = b === f, a.price.isLowerThanCurrent = f > b
}
return a
}), c.method = "url-search", mbr.log("offers found"), mbr.log(c), mbr.hub.trigger("suggest:productOfferFound", c), d(c)
} else mbr.log("have not offers"), c && c.error && mbr.hub.trigger("suggest:error", c && c.error, c && c.errorMessage, !0), e(c)
})
})
}
}, mbr.customSelectors = {
"aliexpress.com": {
_tryGetEnglishName: function(a) {
if (a = a || [], a = a.filter(function(a) {
return "oem" !== a && "new" !== a && -1 === a.indexOf("Другой")
}), !a.length) return "";
var b = /[а-яА-Я]/,
c = a.filter(function(a) {
return !b.test(a)
});
return c.length ? c[0] : a[0].indexOf("Яблоко") > -1 || a[0].indexOf("яблоко") > -1 ? "Apple" : a[0]
},
_getNameByCategoryRegex: function(a, b) {
return this._tryGetEnglishName(a.filter(function(a) {
return b.test(a.innerHTML)
}).map(function(a) {
return mbr.tools.getTextContents(a.querySelector("dd")).toLowerCase()
}))
},
getName: function(a) {
var b = "",
c = /^(Фирменное\sнаименование)|(Производитель)|(>Brand)/,
d = /(Model)|(моделирует)|(Модел)/,
e = /(ПЗУ)|(ROM)/,
f = [].slice.call(a.querySelectorAll("#product-desc .product-params .ui-box-body .ui-attr-list"));
if (f && f.length) {
var g = this._getNameByCategoryRegex(f, c),
h = this._getNameByCategoryRegex(f, d),
i = this._getNameByCategoryRegex(f, e);
g && h && (-1 === h.indexOf(g) && (b = g + " "), b += h, i && (/\dg$/.test(i) && (i += "b"), b += " " + i))
}
return b
}
}
}, mbr.customSelectors["aliexpress.com"].getName(document), mbr.priceParser = {
_getProductPriceBySchema: function() {
var a = 0,
b = mbr.tools.getUniqueElements('[itemtype="http://schema.org/Product"],[itemtype="http://schema.org/Offer"],[itemtype="http://data-vocabulary.org/Product"],[xmlns\\:gr="http://purl.org/goodrelations/v1#"]');
if (b.length) {
var c = b[0],
d = c.querySelector("[itemprop=price]") || c.querySelector("[itemprop=average]") || c.querySelector("[itemprop=lowPrice]") || c.querySelector('[property="gr:hasCurrencyValue"]');
d && (mbr.hub.trigger("productPrice:found", d), a = mbr.tools.priceAnalyze(d.textContent || d.text || d.getAttribute("content")), a = Number(a), a = a || 0)
}
return a
},
_getProductCurrencyBySchema: function() {
var a, b = mbr.tools.getUniqueElements('[itemtype="http://schema.org/Product"],[itemtype="http://schema.org/Offer"],[itemtype="http://data-vocabulary.org/Product"],[xmlns\\:gr="http://purl.org/goodrelations/v1#"]');
if (b.length) {
var c = b[0],
d = c.querySelector("[itemprop=priceCurrency]") || c.querySelector("[itemprop=currency]"),
e = c.querySelector("[itemprop=price]") || c.querySelector("[itemprop=average]") || c.querySelector("[itemprop=lowPrice]") || c.querySelector('[property="gr:hasCurrencyValue"]');
d ? a = d.getAttribute("content") || d.textContent || d.text : e && (a = e.getAttribute("content") || e.textContent || e.text, a = mbr.tools.getCurrencyFromStr(a), a || (a = e.parentNode.getAttribute("content") || e.parentNode.textContent || e.parentNode.text, a = mbr.tools.getCurrencyFromStr(a))), a && (a = a.replace(/[a-z]/g, function(a) {
return a.toUpperCase()
}).replace(/[^A-Z]/g, ""))
}
return a
},
_getProductPriceByHProduct: function() {
var a = 0,
b = mbr.tools.getUniqueElements(".hproduct .price");
if (b.length) {
var c = b[0];
mbr.hub.trigger("productPrice:found", c), a = mbr.tools.priceAnalyze(c.textContent || c.text || c.getAttribute("content")), a = Number(a), a = a || 0
}
return a
},
_getProductCurrencyByHProduct: function() {
var a, b = mbr.tools.getUniqueElements(".hproduct .price");
if (b.length) {
var c = b[0];
a = mbr.tools.getCurrencyFromStr(c.innerHTML), a || (a = mbr.tools.getCurrencyFromStr(c.parentNode.innerHTML))
}
return a
},
_getProductPriceByDefaultSelector: function() {
var a;
return a = mbr.tools.getDifferentElement(".price"), a ? (mbr.hub.trigger("productPrice:found", a), a = mbr.tools.getTextContents(a), a ? (a = mbr.tools.priceAnalyze(a), a = Number(a) || 0) : a = 0, a) : 0
},
_getPriceBySelector: function(a, b) {
var c = 0,
d = a.querySelector(b);
if (d && (mbr.hub.trigger("productPrice:found", d), d.getAttribute && (c = d.getAttribute("data-price")), !c)) {
var e = mbr.tools.getTextContents(d) || d.getAttribute("value");
e = mbr.tools.priceAnalyze(e), e = Number(e), c = e || 0
}
return c
},
_getCurrencyBySelector: function(a, b) {
var c, d = a.querySelector(b);
return d && (c = mbr.tools.getCurrencyFromStr(d.innerHTML), c || (c = mbr.tools.getCurrencyFromStr(d.parentNode.innerHTML))), c
},
getProductPrice: function(a) {
var b = mbr.tools.getHostname(a),
c = 0,
d = mbr.settings.getSelector();
return mbr.settings.canExtractPrice(b) && (d && (d.priceSelector ? c = this._getPriceBySelector(a, d.priceSelector) : d.getPrice && (c = d.getPrice(a))), c = c || this._getProductPriceBySchema(a) || this._getProductPriceByHProduct(a) || this._getProductPriceByDefaultSelector(a)), c
},
getCurrency: function(a) {
var b, c = mbr.settings.getSelector();
return b = this._getCurrencyBySelector(a, c && (c.currencySelector || c.priceSelector) || ".price"), b = b || c && c.getCurrency && c.getCurrency(a), b = b || this._getProductCurrencyBySchema(a) || this._getProductCurrencyByHProduct(a)
}
}, mbr.selectorsParser = {
_canParse: function(a) {
return mbr.settings.isProductSuggestEnabled(a)
},
_getNameBySelector: function(a, b) {
var c = null,
d = window.document.querySelectorAll(b);
if (1 == d.length) {
var e = d[0];
mbr.hub.trigger("productName:found", e), c = mbr.tools.getTextContents(e) || e.getAttribute("value")
}
return c
},
_parse: function(a, b) {
var c, d = {};
return b.nameSelector && (c = this._getNameBySelector(a, b.nameSelector)), !c && b.getName && (c = b.getName(a)), c ? (d.name = c, mbr.hub.trigger("parser:found", {
method: "selector",
name: c
}), d.price = this.getProductPrice(a), d.currency = this.getCurrency(a), d) : (mbr.hub.trigger("parser:notFound", {
domain: mbr.tools.getHostname(a)
}), null)
},
run: function(a) {
var b = mbr.tools.getHostname(a);
if (this._canParse(b)) {
mbr.log("selectors run!");
var c = mbr.settings.getSelector();
if (c && (c.nameSelector || c.getName)) {
var d = this._parse(a, c);
if (d) return mbr.log("Name: " + d.name + "; Price: " + d.price + "; Currency " + d.currency), mbr.suggest.getProductOffers({
productName: d.name,
productPrice: d.price,
currency: d.currency,
url: a.URL,
method: "selectors"
})
}
}
return new mbr.Promise.reject
}
}, mbr.tools.mixin(mbr.selectorsParser, mbr.priceParser), mbr.microdataParser = {
_canParse: function(a) {
return mbr.settings.isProductSuggestEnabled(a) && mbr.settings.canUseMicrodata(a)
},
_getProductNameBySchema: function() {
var a = null,
b = mbr.tools.getUniqueElements('[itemtype="http://schema.org/Product"],[itemtype="http://schema.org/Offer"],[itemtype="http://data-vocabulary.org/Product"],[xmlns\\:gr="http://purl.org/goodrelations/v1#"]');
if (b.length) {
var c = b[0];
if (c.getAttribute("itemref")) return;
var d = c.querySelectorAll('[itemprop=name],[property="gr:name"]');
[].forEach.call(d, function(b) {
a = a || b.getAttribute("content") || b.textContent || b.text || ""
}), d.length && mbr.hub.trigger("productName:found", d[0]), a = a.replace(/\,/g, " ");
var e = c.querySelector("[itemprop=brand]");
if (e) {
var f = e.textContent || e.text || e.getAttribute("content");
f && (a = 0 !== a.indexOf(f) ? f + " " + a : a.replace(f, f + " "))
}
}
return a
},
_getProductNameByHProduct: function() {
var a = null,
b = mbr.tools.getUniqueElements(".hProduct,.hproduct");
if (b.length) {
var c = b[0],
d = c.querySelectorAll(".fn");
[].forEach.call(d, function(b) {
a = a || b.getAttribute("content") || b.textContent || b.text || ""
}), d.length && mbr.hub.trigger("productName:found", d[0]), a = a.replace(/\,/g, " ");
var e = c.querySelector(".brand");
if (e) {
var f = e.textContent || e.text || e.getAttribute("content");
a = 0 !== a.indexOf(f) ? f + " " + a : a.replace(f, f + " ")
}
}
return a
},
_parse: function(a) {
var b, c = this._getProductNameBySchema(a);
if (c ? b = "microdata" : (c = this._getProductNameByHProduct(a), c && (b = "hproduct")), !c) return null;
var d = this.getProductPrice(a),
e = this.getCurrency(a);
return mbr.hub.trigger("parser:found", {
method: b,
name: c
}), {
name: c,
price: d,
currency: e
}
},
run: function(a) {
var b = mbr.tools.getHostname(a);
if (this._canParse(b)) {
mbr.log("md.run!");
var c = this._parse(a);
if (c) return mbr.log("Product name = " + c.name + " price = " + c.price), mbr.suggest.getProductOffers({
productName: c.name,
productPrice: c.price,
currency: c.currency,
url: a.URL,
method: "microdata"
})
}
return new mbr.Promise.reject
}
}, mbr.tools.mixin(mbr.microdataParser, mbr.priceParser), mbr.cmsParser = {
_selectors: [{
selector: 'link[href*="bitrix/"]',
cms: "1C-Bitrix"
}, {
selector: 'meta[content*="Amiro.CMS"]',
cms: "Amiro.CMS"
}, {
selector: '[umi\\:field-name],html[xmlns\\:umi*="umi-cms.ru"]',
cms: "UMI.CMS",
product: '[umi\\:field-name="h1"]',
price: '[umi\\:field-name="price"]'
}, {
selector: "meta[content*='AdVantShop.NET']",
cms: "AdVantShop.NET"
}, {
selector: "meta[content*='PHPSHOP']",
cms: "PHPShop"
}, {
selector: 'link[href*="insales.ru"]',
cms: "InSales"
}, {
selector: "h1.mainbox-title",
cms: "CS-Cart",
product: "h1.mainbox-title"
}, {
cms: "PrestaShop",
selector: "meta[content*='PrestaShop']"
}, {
cms: "OsCommerce",
selector: 'link[rel="stylesheet"][href^="templates/"][href$="/stylesheet.css"]'
}, {
cms: "Joomla!",
selector: "meta[content*='Joomla']"
}, {
cms: "WordPress",
selector: "meta[content*='WordPress']"
}, {
selector: 'script[src*="drupal"]',
cms: "Drupal"
}],
_canParse: function(a) {
return mbr.settings.isProductSuggestEnabled(a) && mbr.settings.canCheckCMS(a)
},
_getCMS: function(a) {
for (var b = 0; b < this._selectors.length; b++)
if (this._selectors[b].selector && a.querySelector(this._selectors[b].selector)) return this._selectors[b];
return null
},
_getProductName: function(a, b) {
var c = b.product || "h1",
d = a.querySelector(c);
return d ? mbr.tools.getTextContents(d) : null
},
_getProductPriceBySelector: function(a, b) {
if (b) {
var c = a.querySelector(b);
if (c) {
var d = mbr.tools.getTextContents(c);
return d = mbr.tools.priceAnalyze(d), d = Number(d) || 0
}
}
return 0
},
run: function(a) {
var b = mbr.tools.getHostname(a);
if (this._canParse(b)) {
mbr.log("cms.run!");
var c = this._getCMS(a);
if (c) {
mbr.log("find cms = %s", c.cms);
var d = this._getProductName(a, c);
if (d) {
var e = this._getProductPriceBySelector(a, c.price) || this.getProductPrice(a),
f = this.getCurrency(a);
if (e) return mbr.hub.trigger("parser:found", {
method: "cms",
name: d
}), mbr.log("Product name = " + d + " price = " + e), mbr.suggest.getProductOffers({
productName: d,
productPrice: e,
currency: f,
url: a.URL,
method: "cms"
});
mbr.log("price not found")
}
}
}
return mbr.Promise.reject()
}
}, mbr.tools.mixin(mbr.cmsParser, mbr.priceParser), mbr.aviaParser = {
_sites: [{
name: "aeroflot",
urlRE: /https?:\/\/reservation\.aeroflot\.ru/,
domain: "reservation.aeroflot.ru",
getInfo: function(a) {
return new mbr.Promise(function(b) {
var c = 10,
d = function() {
if (!c) return void b(m);
c -= 1;
var e = a.querySelector('[name="itineraryParts[0].departureAirport"]'),
f = a.querySelector('[name="itineraryParts[0].arrivalAirport"]'),
g = a.querySelector("#outbounds .active .date"),
h = a.querySelector("#inbounds .active .date"),
i = a.querySelector("#outbounds .active .prices-amount"),
j = a.querySelector("#inbounds .active .prices-amount"),
k = a.querySelector("#outbounds .active .currency"),
l = a.querySelector("#ADT_id");
if (e && f && g && h && i && j && l && k) {
var m = {};
if (m.origin = e.value, m.destination = f.value, m.departure_at = g.getAttribute("data-wl-date").split(" ")[0].replace(/\//g, "-"), m.return_at = h.getAttribute("data-wl-date").split(" ")[0].replace(/\//g, "-"), m.price = parseInt(mbr.tools.priceAnalyze(i.innerText || i.textContent), 10) + parseInt(mbr.tools.priceAnalyze(j.innerText || j.textContent), 10), m.person = l.getAttribute("data-wl-value"), m.currency = k.innerText || k.textContent, m.origin && m.destination && m.departure_at && m.return_at && m.price && m.person && m.currency) return void b(m)
}
setTimeout(d, 500)
};
d()
})
}
}, {
name: "s7",
urlRE: /ibe\.s7\.ru\/S7\/webqtrip\.html/,
domain: "ibe.s7.ru",
months: {
"Январь": "01",
"Февраль": "02",
"Март": "03",
"Апрель": "04",
"Май": "05",
"Июнь": "06",
"Июль": "07",
"Август": "08",
"Сентябрь": "09",
"Октябрь": "10",
"Ноябрь": "11",
"Декабрь": "12",
January: "01",
February: "02",
March: "03",
April: "04",
May: "05",
June: "06",
July: "07",
August: "08",
September: "09",
October: "10",
November: "11",
December: "12"
},
getInfo: function(a) {
var b, c, d, e, f = a.querySelectorAll(".route_details_left .col_2");
if (!(f && f.length > 1)) return mbr.Promise.reject();
b = f[0], c = f[1];
var g = a.querySelectorAll(".route_details_right .col_2")[1];
if (b && c) {
var h = /\((.+?)\).+?\((.+?)\)/,
i = h.exec(mbr.tools.getTextContents(b));
i && i.length > 2 && (d = i[1], e = i[2]), c = mbr.tools.getTextContents(c), c = c.split(" "), c[1] = this.months[c[1]], c = c[2] + "-" + c[1] + "-" + c[0]
}
var j = {
origin: d,
destination: e,
departure_at: c
};
return g && (g = mbr.tools.getTextContents(g), g = g.split(" "), g[1] = this.months[g[1]], g[0] = 1 === g[0].length ? "0" + g[0] : g[0], g = g[2] + "-" + g[1] + "-" + g[0], j.return_at = g), new mbr.Promise(function(b) {
var c = 10,
d = "#totalAmountWithOutDiscount",
e = function() {
if (!c) return void b(j);
c -= 1;
var f = a.querySelector(d);
f && (f.innerText || f.textContent) ? (j.price = parseInt((f.innerText || f.textContent).replace(/\D/g, ""), 10), b(j)) : setTimeout(e, 500)
};
e()
})
}
}, {
name: "ozon.travel",
urlRE: /ozon\.travel\/flight\/search\//,
domain: "ozon.travel",
getInfo: function(a) {
var b, c = a.URL,
d = /flight\/search\/([a-z]{3})([a-z]{3})(?:[a-z]{6}){0,1}\/d(\d{4}\-\d{2}\-\d{2})(?:d(\d{4}\-\d{2}\-\d{2}))?/,
e = d.exec(c);
return e && e.length > 3 ? (b = {
origin: e[1].toUpperCase(),
destination: e[2].toUpperCase(),
departure_at: e[3],
person: parseInt(mbr.tools.getQueryParam(c, "Dlts"), 10) || 1
}, e.length > 4 && (b.return_at = e[4]), new mbr.Promise(function(c) {
var d = 30,
e = ".tariff big",
f = function() {
if (!d) return void c(b);
d -= 1;
var g = a.querySelector(e);
if (g) {
var h = "RUR";
g.innerHTML.indexOf("$") > -1 ? h = "USD" : g.innerHTML.indexOf("€") > -1 && (h = "EUR"), b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(g)), 10), b.currency = h, c(b)
} else setTimeout(f, 500)
};
f()
})) : mbr.Promise.reject()
}
}, {
name: "avia.travel.ru",
domain: "avia.travel.ru",
urlRE: /\.avia\.travel\.ru\/flights/,
getInfo: function(a) {
return new mbr.Promise(function(b) {
var c = ".TPWL-ticket-price",
d = ".TPWL-realtime_progressbar.ui-progressbar",
e = /([A-Z]{3})$/,
f = function() {
var g = a.querySelector(c),
h = a.querySelector(d);
if (!h || 0 == h.offsetWidth && 0 == h.offsetHeight) {
var i = a.URL,
j = /\.avia\.travel\.ru\/flights\/([A-Z]{3})(\d{2})(\d{2})([A-Z]{3})(\d{2})(\d{2})(\d)/,
k = j.exec(i),
l = {
origin: k[1],
destination: k[4],
person: +k[7]
},
m = k[2],
n = k[3],
o = k[5],
p = k[6],
q = (new Date).getFullYear(),
r = mbr.tools.isMonthOfNextYear(parseInt(n, 10)) ? q + 1 : q,
s = mbr.tools.isMonthOfNextYear(parseInt(p, 10)) || mbr.tools.isMonthOfNextYear(parseInt(n, 10)) ? q + 1 : q;
if (l.departure_at = r + "-" + n + "-" + m, l.return_at = s + "-" + p + "-" + o, g) {
var k = e.exec(g.innerHTML);
k && k.length > 1 && (l.currency = k[1]), l.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(g)), 10)
}
b(l)
} else setTimeout(f, 500)
};
f()
})
}
}, {
name: "transaero.ru",
urlRE: /https?:\/\/(?:www\.)?transaero\.ru\/wps\/portal\//,
domain: "transaero.ru",
getInfo: function(a) {
var b = (a.URL, {}),
c = /\(([A-Z]+)\).+?\(([A-Z]+)\)/,
d = /(\d{2})\-(\d{2})\-(\d{4})/,
e = a.getElementById("onewayItin"),
f = a.getElementById("onewayDepartureDateTime"),
g = a.getElementById("returnwayDepartureDateTime");
if (e && f) {
var h = c.exec(e.innerText || e.textContent);
if (h && 3 === h.length && (b.origin = h[1], b.destination = h[2], h = d.exec(f.innerText || f.textContent), h && 4 === h.length)) return b.departure_at = h[3] + "-" + h[2] + "-" + h[1], g && (h = d.exec(g.innerText || g.textContent), h && 4 === h.length && (b.return_at = h[3] + "-" + h[2] + "-" + h[1])), new mbr.Promise(function(c) {
var d = 30,
e = ".totalPrice > table > tbody > tr > td",
f = function() {
if (!d) return void c(b);
d -= 1;
var g = a.querySelector(e);
g && (g.innerText || g.textContent) ? (b.price = parseInt(g.innerText || g.textContent, 10), c(b)) : setTimeout(f, 500)
};
f()
})
}
return mbr.Promise.reject()
}
}, {
name: "sale.transaero.ru",
urlRE: /sale\.transaero\.ru\/step/,
domain: "sale.transaero.ru",
getInfo: function(a) {
var b = a.URL,
c = a.referrer,
d = {
origin: mbr.tools.getQueryParam(b, "departureAirportCode") || mbr.tools.getQueryParam(c, "departureAirportCode") || mbr.tools.getQueryParam(b, "origin") || mbr.tools.getQueryParam(c, "origin"),
destination: mbr.tools.getQueryParam(b, "arrivalAirportCode") || mbr.tools.getQueryParam(c, "arrivalAirportCode") || mbr.tools.getQueryParam(b, "destination") || mbr.tools.getQueryParam(c, "destination"),
departure_at: mbr.tools.getQueryParam(b, "departureDate") || mbr.tools.getQueryParam(c, "departureDate"),
person: +(mbr.tools.getQueryParam(b, "adultsNum") || mbr.tools.getQueryParam(c, "adultsNum") || mbr.tools.getQueryParam(b, "numAdults") || mbr.tools.getQueryParam(c, "numAdults")),
return_at: mbr.tools.getQueryParam(b, "returnDate") || mbr.tools.getQueryParam(c, "returnDate")
};
return d.origin && d.destination && d.departure_at && d.return_at ? new mbr.Promise(function(b) {
var c = "#summaryTable td",
e = 200,
f = function() {
if (!e--) return void b(d);
var g = a.querySelectorAll(c);
g && g.length ? (g = g[g.length - 1], d.price = parseInt(mbr.tools.priceAnalyze(g.innerText || g.textContent), 10), d.currency = mbr.tools.getCurrencyFromStr(g.innerText || g.textContent), b(d)) : setTimeout(f, 1e3)
};
f()
}) : mbr.Promise.reject(d)
}
}, {
name: "avia.tutu.ru",
urlRE: /avia\.tutu\.ru\/offers\/\?/,
domain: "avia.tutu.ru",
getInfo: function(a) {
function b(a) {
return a && !/[А-Я]/i.test(a)
}
for (var c, d = a.URL.substr(a.URL.indexOf("?") + 1), e = d.split("&"), f = {
city_name_from: null,
city_name_to: null,
date_forward: null,
date_back: null,
passengers: ""
}, g = 0; g < e.length; g++) e[g] = e[g].split("="), e[g][0] in f && (f[e[g][0]] = decodeURIComponent(e[g][1]), f[e[g][0]] = f[e[g][0]].split(" ")[0]);
if (!b(f.city_name_from) || !b(f.city_name_to)) {
var h = a.querySelector(".rm-page-container~script");
if (h) {
var i = h.innerHTML;
if (i = i.substring(i.indexOf('{"from'), i.indexOf(',"debugInfo'))) {
var j = JSON.parse(i);
j && (f.city_name_from = j.from[0].iata, f.city_name_to = j.to[0].iata), f.date_forward && f.date_back || (f.date_forward = j.date[0], f.date_back = j.date[1])
}
}
}
return f.city_name_from && f.city_name_to && f.date_forward ? (c = {
origin: f.city_name_from,
destination: f.city_name_to,
departure_at: f.date_forward.split(".").reverse().join("-")
}, f.date_back && (c.return_at = f.date_back.split(".").reverse().join("-")), new mbr.Promise(function(b) {
var d = ".b-promostamp.b-promostamp-bestprice ~ .b-buttonext-avia > .buttonext_rows > .buttonext_digits",
e = ".b-clouds_wait",
g = function() {
var h = a.querySelector(d),
i = a.querySelector(e);
h && !i ? (c.price = parseInt((h.innerText || h.textContent).replace(/\D/g, ""), 10), c.person = parseInt(f.passengers[0], 10) || 1, b(c)) : setTimeout(g, 500)
};
g()
})) : mbr.Promise.reject()
}
}, {
name: "travelwith.s7.ru",
domain: "travelwith.s7.ru",
urlRE: /travelwith\.s7\.ru\/(?:selectExactDateSearchFlights|selectFlexibleSearchFlights)\.action/,
getInfo: function(a) {
var b, c = a.URL;
if (b = {
origin: mbr.tools.getQueryParam(c, "DA1"),
destination: mbr.tools.getQueryParam(c, "AA1"),
departure_at: mbr.tools.getQueryParam(c, "DD1"),
person: +mbr.tools.getQueryParam(c, "TA"),
return_at: mbr.tools.getQueryParam(c, "DD2") || void 0,
currency: mbr.tools.getQueryParam(c, "CUR")
}, b.origin && b.destination && b.departure_at && b.person > 0) {
var d = a.querySelector(".amount b");
if (d) {
var e = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(d)), 10);
e && (b.price = e)
}
return mbr.Promise.resolve(b)
}
return mbr.Promise.reject()
}
}, {
name: "onetwotrip.com",
domain: "onetwotrip.com",
urlRE: /onetwotrip\.com\/.*(\d{2})(\d{2})([A-Z]{3})([A-Z]{3})(\d{2})(\d{2}).*&s$/,
getInfo: function(a) {
var b, c, d = a.URL,
e = this.urlRE.exec(d),
f = {
origin: e[3],
destination: e[4],
person: 1
},
g = e[1],
h = e[2],
i = e[5],
j = e[6],
k = new Date;
if (b = mbr.tools.isMonthOfNextYear(parseInt(h, 10)) ? k.getFullYear() + 1 : k.getFullYear(), c = mbr.tools.isMonthOfNextYear(parseInt(j, 10)) || mbr.tools.isMonthOfNextYear(parseInt(h, 10)) ? k.getFullYear() + 1 : k.getFullYear(), f.departure_at = b + "-" + h + "-" + g, f.return_at = c + "-" + j + "-" + i, f.origin && f.destination && f.departure_at && f.return_at) {
var l = a.querySelector(".direction_price span:not(.min_priceword)");
if (l) {
var m = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(l)), 10);
m && (f.price = m);
var n = a.querySelector("#CurrenciesBlock .d_option .selected");
n && (f.currency = n.getAttribute("data-cur"))
}
return mbr.Promise.resolve(f)
}
return mbr.Promise.reject()
}
}, {
name: "anywayanyday.com",
domain: "anywayanyday.com",
urlRE: /anywayanyday\.com\/avia\/offers\/(\d{2})(\d{2})([A-Z]{3})([A-Z]{3})(\d{2})(\d{2})[A-Z]{6}AD(\d+)/,
getInfo: function(a) {
var b, c, d = a.URL,
e = this.urlRE.exec(d),
f = {
origin: e[3],
destination: e[4],
person: +e[7]
},
g = e[1],
h = e[2],
i = e[5],
j = e[6],
k = new Date;
return b = mbr.tools.isMonthOfNextYear(parseInt(h, 10)) ? k.getFullYear() + 1 : k.getFullYear(), c = mbr.tools.isMonthOfNextYear(parseInt(j, 10)) || mbr.tools.isMonthOfNextYear(parseInt(h, 10)) ? k.getFullYear() + 1 : k.getFullYear(), f.departure_at = b + "-" + h + "-" + g, f.return_at = c + "-" + j + "-" + i, new mbr.Promise(function(b) {
var c = 50,
d = ".b-price",
e = ".j-currency_changer.s-selected",
g = function() {
if (!c) return void b(f);
c -= 1;
var h = a.querySelector(d);
if (h && (h.innerText || h.textContent)) {
f.price = parseInt((h.innerText || h.textContent).replace(/\D/g, ""), 10);
var i = a.querySelector(e);
i && (f.currency = i.getAttribute("data-currency")), b(f)
} else setTimeout(g, 500)
};
g()
})
}
}, {
name: "biletix.ru",
domain: "biletix.ru",
urlRE: /https?:\/\/biletix\.ru\/#offer__\d+/,
getInfo: function(a) {
var b = {},
c = {
origin: "depart",
destination: "arrival",
departure_at: "dateto",
return_at: "dateback",
type: "RT_OW",
person: "adult"
};
for (var d in c)
if (c.hasOwnProperty(d)) {
if (c[d] = a.getElementsByName(c[d]), !c[d] || !c[d].length) return mbr.Promise.reject();
if (c[d] = c[d][0].value, !c[d]) return mbr.Promise.reject()
}
if ("RT" === c.type) {
var e, f = /\(([A-Z]{3})\)/;
if (e = f.exec(c.origin), e && e.length > 1 && (b.origin = e[1], e = f.exec(c.destination), e && e.length > 1)) {
b.destination = e[1], b.departure_at = c.departure_at.split(".").reverse().join("-"), b.return_at = c.return_at.split(".").reverse().join("-"), b.person = +c.person;
var g = a.querySelector(".price");
if (g) {
b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(g)), 10);
var h = a.querySelector("li.selected label");
h && (b.currency = h.innerText || h.textContent)
}
return mbr.Promise.resolve(b)
}
}
return mbr.Promise.reject()
}
}, {
name: "pososhok.ru",
domain: "pososhok.ru",
urlRE: /https?:\/\/(www.)?pososhok\.ru\//,
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
var d = 15,
e = "#mapContainer",
f = function() {
var b = a.querySelector(".flight .price h5"),
c = a.querySelector(".thin-selector .selected"),
d = a.querySelectorAll("#form-roundtrip .datepicker-bind");
if (b && c && d && 2 === d.length) {
var e = location.hash.split("-");
if (e.length > 2) {
var f = {};
return f.origin = e[e.length - 2], f.destination = e[e.length - 1], f.person = +mbr.tools.getTextContents(c), f.departure_at = d[0].value, f.return_at = d[0].value, f.price = +mbr.tools.priceAnalyze(mbr.tools.getTextContents(b)), f
}
}
return null
},
g = function() {
if (!d) {
var h = f();
return void(h ? b(h) : c())
}
d -= 1, a.querySelector(e) ? setTimeout(g, 1e3) : (h = f(), h ? b(h) : c(h))
};
g()
})
}
}, {
name: "new.pososhok.ru",
domain: "new.pososhok.ru",
urlRE: /https?:\/\/new\.pososhok\.ru\/#result\//,
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
var d = {},
e = /([A-Z]{3})\-([A-Z]{3})$/,
f = e.exec(a.URL);
if (!(f && f.length > 2)) return void c();
d.origin = f[1], d.destination = f[2];
var g = 60,
h = function() {
if (g--) {
var e = a.querySelector("#form-roundtrip");
if (!e) return void setTimeout(h, 1e3);
var f = a.querySelectorAll("#minor-form-roundtrip .dates .datepicker-bind");
f && 2 === f.length && (d.departure_at = f[0].value, d.return_at = f[1].value);
var i = a.querySelector('[data-field="adults"]');
d.person = i ? i.value : 1;
var j = a.querySelector(".best-flight .price");
if (j && (d.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(j)), 10), d.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(j))), d.origin && d.destination && d.departure_at && d.return_at && d.price) return void b(d);
c()
} else c()
};
h()
})
}
}, {
name: "agent.ru",
domain: "agent.ru",
urlRE: /https?:\/\/(www.)?agent.ru\/ru\/booking\/choice/,
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
for (var d, e = a.getElementsByTagName("script"), f = /var searchRequest\s*=\s*(.+?);\s*\n?/, g = e.length - 1; g >= 0 && !(e[g].textContent.indexOf("var searchRequest") > -1 && (d = f.exec(e[g].textContent), d && d.length)); g--);
if (d && d.length) {
var h;
try {
h = JSON.parse(d[1])
} catch (i) {
c()
}
if (h && h.segments && 2 === h.segments.length) {
var j = {};
j.origin = h.segments[0].departurePoint.city.codeIATA, j.destination = h.segments[0].arrivalPoint.city.codeIATA, j.person = h.adultsCount;
var k = new Date(h.segments[0].departureDate),
l = k.getMonth() + 1;
l = 10 > l ? "0" + l : l;
var m = new Date(h.segments[1].departureDate),
n = m.getMonth() + 1;
n = 10 > n ? "0" + n : n, j.departure_at = k.getFullYear() + "-" + l + "-" + (k.getDate() < 10 ? "0" + k.getDate() : k.getDate()), j.return_at = m.getFullYear() + "-" + n + "-" + (m.getDate() < 10 ? "0" + m.getDate() : m.getDate());
var o = a.querySelector("nobr.rub"),
p = a.querySelector("nobr.usd"),
q = a.querySelector("nobr.eur"),
r = ".price .rub b";
o && "none" !== o.style.display ? j.currency = "RUB" : p && "none" !== p.style.display ? (j.currency = "USD", r = ".price .usd b") : q && "none" !== q.style.display && (j.currency = "EUR", r = ".price .eur b");
var s = a.querySelector(r);
s && (j.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(s)), 10)), b(j)
}
}
c()
})
}
}, {
name: "nabortu.ru",
domain: "nabortu.ru",
urlRE: /https?:\/\/(www.)?nabortu\.ru\/aviabilety\/\?/,
getInfo: function(a) {
var b, c = a.URL;
if (b = {
origin: mbr.tools.getQueryParam(c, "codeFrom"),
destination: mbr.tools.getQueryParam(c, "codeWhere"),
departure_at: mbr.tools.getQueryParam(c, "datein"),
person: +mbr.tools.getQueryParam(c, "adults_num"),
return_at: mbr.tools.getQueryParam(c, "dateout") || void 0
}, b.origin && b.destination && b.departure_at && b.person > 0) {
b.departure_at = b.departure_at.split(".").reverse().join("-"), b.return_at = b.return_at.split(".").reverse().join("-");
var d = a.querySelector(".act-black a");
if (d) {
var e = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(d)), 10);
e && (b.price = e)
}
return mbr.Promise.resolve(b)
}
return mbr.Promise.reject()
}
}, {
name: "aviacassa.ru",
domain: "aviacassa.ru",
urlRE: /https?:\/\/(?:www\.)?aviacassa\.ru\/air\/view\/([A-Z]{3})\-([A-Z]{3})\/(\d{4}\-\d{2}\-\d{2})\/(\d{4}\-\d{2}\-\d{2})\/(\d+)ADT/,
getInfo: function(a) {
var b = a.URL,
c = this.urlRE.exec(b),
d = {
origin: c[1],
destination: c[2],
departure_at: c[3],
return_at: c[4],
person: +c[5]
};
if (d.origin && d.destination && d.departure_at && d.return_at) {
var e = a.querySelector(".blueborderedflight .dyna-currency-amount");
if (e) {
var f = parseInt((e.innerText || e.textContent).replace(/\D/g, ""), 10);
if (f) {
d.price = f;
var g = a.querySelector(".dyna-currency-symbol");
g && (d.currency = g.innerText || g.textContent)
}
}
return mbr.Promise.resolve(d)
}
return mbr.Promise.reject()
}
}, {
name: "sindbad.ru",
domain: "sindbad.ru",
urlRE: /https?:\/\/(?:www\.)?sindbad\.ru\/ru\/flight\/results\/([A-Z]{3})([A-Z]{3})(\d{4})(\d{2})(\d{2})(\d{4})(\d{2})(\d{2})(\d)00E0/,
getInfo: function(a) {
var b = a.URL,
c = this.urlRE.exec(b),
d = {
origin: c[1],
destination: c[2],
departure_at: c[3] + "-" + c[4] + "-" + c[5],
return_at: c[6] + "-" + c[7] + "-" + c[8],
person: +c[9]
};
if (d.origin && d.destination && d.departure_at && d.return_at) {
var e = a.querySelector(".cost .lPrice");
if (e) {
var f = parseInt((e.innerText || e.textContent).replace(/\D/g, ""), 10);
f && (d.price = f)
}
return mbr.Promise.resolve(d)
}
return mbr.Promise.reject()
}
}, {
name: "klm.com",
domain: "klm.com",
urlRE: /https?:\/\/(?:www\.)?klm\.com\/travel\/[^\/]+\/apps\/ebt\/calendar\.htm/,
getInfo: function(a) {
var b = a.URL,
c = {
origin: mbr.tools.getQueryParam(b, "origin"),
destination: mbr.tools.getQueryParam(b, "destination"),
departure_at: mbr.tools.getQueryParam(b, "outboundDate"),
return_at: mbr.tools.getQueryParam(b, "inboundDate"),
person: +mbr.tools.getQueryParam(b, "numberOfAdults")
};
return c.origin && c.destination && c.departure_at && c.return_at && c.person ? new mbr.Promise(function(b) {
var d = ".est-selected.est-price div, .est-flight.est-selected .est-price",
e = ".search-loading",
f = ".est-loading-indicator",
g = 15,
h = function() {
if (g--) {
var i = a.querySelector(d),
j = a.querySelector(e),
k = a.querySelector(f);
if (i && !j && 0 == k.offsetWidth && 0 == k.offsetHeight) {
var l = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(i).replace(/\D/g, "")), 10);
if (l) return c.price = l, c.currency = mbr.tools.getCurrencyFromStr(i.querySelector("span").innerText), void b(c)
}
setTimeout(h, 1e3)
} else b(c)
};
h()
}) : mbr.Promise.reject()
}
}, {
name: "britishairways.com",
domain: "britishairways.com",
urlRE: /https?:\/\/(www.)?britishairways\.com\/travel\/fx/,
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
for (var d, e = a.getElementsByTagName("script"), f = /depart_airport\s*=\s*'(\S{3})';[\s\S]+?destination_airport\s*=\s*'(\S{3})'[\s\S]+currency_code\s*=\s*'(\S{3})[\s\S]+depart_date\s*=\s*'([\d\-]{10})[\s\S]+return_date\s*=\s*'([\d\-]{10})/, g = e.length - 1; g >= 0 && !(e[g].textContent.indexOf("collectTagManData") > -1 && (d = f.exec(e[g].textContent), d && d.length)); g--);
if (d && d.length > 5) {
var h = {};
if (h.origin = d[1], h.destination = d[2], h.currency = d[3], h.departure_at = d[4], h.return_at = d[5], h.person = 1, h.origin && h.destination && h.departure_at && h.return_at) {
var i = a.querySelector("#outboundDates .col1 .lowestPriceFlagtrue label"),
j = a.querySelector("#inboundDates .col1 .lowestPriceFlagtrue label");
return j && i && (h.price = parseInt(i.innerHTML.replace(/\D/g, ""), 10) + parseInt(j.innerHTML.replace(/\D/g, ""), 10)), void b(h)
}
}
c()
})
}
}, {
name: "airfrance.ru",
domain: "airfrance.ru",
urlRE: /https?:\/\/(www.)?airfrance\.ru\/cgi\-bin\/AF\/.+?\/.+?\/local\/process\/standardbooking\/DisplayFlightPageAction\.do/,
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
for (var d, e = a.getElementsByTagName("script"), f = /u3\s*=\s*"(\S{3})(\S{3})";[\s\S]+?u5\s*=\s*"(\S{3})"/, g = e.length - 1; g >= 0 && !(e[g].textContent.indexOf("var u3") > -1 && (d = f.exec(e[g].textContent), d && d.length)); g--);
if (d && d.length > 3) {
var h = {};
h.origin = d[1], h.destination = d[2], h.currency = d[3];
var i = a.getElementById("idTrip0Day"),
j = a.getElementById("idTrip0MonthYear"),
k = a.getElementById("idTrip1Day"),
l = a.getElementById("idTrip1MonthYear");
if (i && j && k && l && (h.departure_at = j.value.substr(0, 4) + "-" + j.value.substr(4, 2) + "-" + i.value, h.return_at = l.value.substr(0, 4) + "-" + l.value.substr(4, 2) + "-" + k.value), h.origin && h.destination && h.departure_at && h.return_at) {
var m = a.querySelector(".blocMiniRecapOnePaxPrice");
return m && (h.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(m)), 10)), void b(h)
}
}
c()
})
}
}, {
name: "skyscanner.ru",
urlRE: /https?\:\/\/(www\.)?skyscanner\.(ru|com|de|net|co\.id|com\.ua)\/transport\/(flights|fluge)\//,
domain: "skyscanner.ru",
getInfo: function(a) {
var b = {};
return new mbr.Promise(function(c) {
var d = 40,
e = ".header-info-bestprice button",
f = function() {
if (!d) return void c(b);
d -= 1;
var g = a.querySelector(".day-options-item.depart .day-options-navigation span"),
h = a.querySelector(".day-options-item.return .day-options-navigation span"),
i = a.querySelectorAll(".route-code");
g && h && i && i.length > 1 && (b.departure_at = g.getAttribute("data-date"), b.return_at = h.getAttribute("data-date"), b.origin = (i[0].innerText || i[0].textContent).substr(1, 3), b.destination = (i[1].innerText || i[1].textContent).substr(1, 3));
var j = a.querySelector(e);
j ? (b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(j)), 10), b.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(j)), c(b)) : setTimeout(f, 1e3)
};
f()
})
}
}, {
name: "airberlin.com",
urlRE: /https?\:\/\/(www\.)?airberlin\.com\/.+?\/booking\/flight\/vacancy\.php/,
domain: "airberlin.com",
getInfo: function(a) {
var b = {};
return new mbr.Promise(function(c) {
var d = 40,
e = "#vacancy_priceoverview .total td",
f = function() {
if (!d) return void c(b);
d -= 1;
var g = a.querySelector(".paxcountpertype");
g && (b.person = +g.innerHTML.replace(/\D/g, "")); {
var h = a.getElementById("departurecode"),
i = a.getElementById("destinationcode"),
j = a.getElementById("outbounddate"),
k = a.getElementById("returndate");
a.querySelectorAll(".route-code")
}
h && i && j && k && (b.departure_at = j.value.split(/\.|\//).reverse().join("-"), b.return_at = k.value.split(/\.|\//).reverse().join("-"), b.origin = h.value, b.destination = i.value);
var l = a.querySelector(e);
l ? (b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(l)).replace(".", ""), 10), b.currency = mbr.tools.getCurrencyFromStr(l.innerHTML), c(b)) : setTimeout(f, 1e3)
};
f()
})
}
}, {
name: "booking.alitalia.com",
urlRE: /https?:\/\/booking\.alitalia\.com\/Booking\//,
domain: "alitalia.com",
getInfo: function(a) {
var b = {},
c = a.getElementById("Destinations_DepartureAirport"),
d = a.getElementById("Destinations_ArrivalAirport"),
e = a.querySelector('[name="DCSext.NumAd"]'),
f = a.getElementById("Destinations_DepartureDate"),
g = a.getElementById("Destinations_ReturnDate"),
h = a.querySelector("#OutboundRoutePanel .brand_routedetail_bestprice input"),
i = a.querySelector("#ReturnRoutePanel .brand_routedetail_bestprice input");
return c && d && e && f && g ? (b.origin = c.value, b.destination = d.value, b.person = +e.content, b.departure_at = f.value.split("/").reverse().join("-"), b.return_at = g.value.split("/").reverse().join("-"), h && i && (b.price = Number(h.getAttribute("price")) + Number(i.getAttribute("price")), b.currency = mbr.tools.getCurrencyFromStr(h.value)), mbr.Promise.resolve(b)) : mbr.Promise.reject()
}
}, {
name: "iberia.com",
urlRE: /https?:\/\/(www\.)?iberia\.com\/web\/(dispatchSearchFormHOME|dispatchCurrencyChangeConfirm)/,
domain: "iberia.com",
getInfo: function(a) {
var b = {},
c = a.querySelector(".from-fly-table .choose-flight-list .like-row");
if (c) {
var d = a.querySelectorAll(".from-fly-table .choose-flight-list .like-row .flight-code");
if (d && d.length) {
var e = d[0].href;
b.origin = mbr.tools.getQueryParam(e, "beginLocation"), b.departure_at = mbr.tools.getQueryParam(e, "bDate"), b.departure_at = b.departure_at.replace(/(\d{4})(\d{2})(\d{2}).+/, "$1-$2-$3"), e = d[d.length - 1].href, b.destination = mbr.tools.getQueryParam(e, "endLocation")
}
d = a.querySelector(".return-fly-table .choose-flight-list .like-row .flight-code"), d && (b.return_at = mbr.tools.getQueryParam(d.href, "bDate").replace(/(\d{4})(\d{2})(\d{2}).+/, "$1-$2-$3"));
var f = a.querySelectorAll(".selected .price");
if (f) var g = f[0],
h = f[1];
g && (b.price = +mbr.tools.priceAnalyze(mbr.tools.getTextContents(g)), b.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(g))), h && (b.price += +mbr.tools.priceAnalyze(mbr.tools.getTextContents(h)))
}
return b.origin && b.destination && b.departure_at && b.return_at ? mbr.Promise.resolve(b) : mbr.Promise.reject()
}
}, {
name: "kayak.ru",
urlRE: /https?:\/\/(?:www\.)?kayak\.ru\/flights\/(\S{3})\-(\S{3})\/(\S{10})\/(\S{10})/,
domain: "kayak.ru",
getInfo: function(a) {
var b, c = a.URL,
d = this.urlRE.exec(c);
return d ? (b = {
origin: d[1].toUpperCase(),
destination: d[2].toUpperCase(),
departure_at: d[3],
return_at: d[4]
}, new mbr.Promise(function(c) {
var d = ".pricerange a",
e = "#progressDiv",
f = function() {
var g = a.querySelector(d),
h = a.querySelector(e);
g && !h ? (b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(g)), 10), c(b)) : setTimeout(f, 500)
};
f()
})) : mbr.Promise.reject()
}
}, {
name: "lufthansa.com",
urlRE: /https?:\/\/book\.lufthansa\.com\/lh\/dyn\/air\-lh\/revenue\/viewFlights/,
domain: "lufthansa.com",
getInfo: function(a) {
var b = {},
c = a.querySelector(".flight-details").querySelectorAll('[title="Acronym full name"]');
c && (b.origin = c[0].innerHTML, b.destination = c[1].innerHTML);
var d = a.querySelector("#calendarDatesList0 .tab.ui-state-active time");
d && (b.departure_at = d.innerHTML.replace(/[^\.\d]/g, "").replace(/(\d{2})\.(\d{2})\.(\d{2})/, "20$3-$2-$1"));
var e = a.querySelector("#calendarDatesList1 .tab.ui-state-active time");
e && (b.return_at = e.innerHTML.replace(/[^\.\d]/g, "").replace(/(\d{2})\.(\d{2})\.(\d{2})/, "20$3-$2-$1"));
var f = a.querySelector("#calendarDatesList0 .tab.ui-state-active .number");
f && (b.price = +f.getAttribute("data-value"));
var g = a.querySelector("#calendarDatesList1 .tab.ui-state-active .number");
g && (b.price += +g.getAttribute("data-value"));
var h = a.querySelector("#calendarDatesList1 .tab.ui-state-active .currency");
return h && (b.currency = mbr.tools.getTextContents(h)), b.origin && b.destination && b.return_at && b.departure_at ? mbr.Promise.resolve(b) : mbr.Promise.reject()
}
}, {
name: "travel.ulmart.ru",
urlRE: /https?:\/\/travel\.ulmart\.ru\/flight\/search/,
domain: "travel.ulmart.ru",
getInfo: function(a) {
var b = {},
c = a.URL,
d = mbr.tools.getQueryParam(c, "fromPoint"),
e = mbr.tools.getQueryParam(c, "toPoint"),
f = mbr.tools.getQueryParam(c, "adultsCount"),
g = mbr.tools.getQueryParam(c, "forthDate"),
h = mbr.tools.getQueryParam(c, "returnDate"),
i = a.querySelector(".b-price__num");
return d && e && f && g && h ? (b.origin = d, b.destination = e, b.person = +f, b.departure_at = g.split(/\.|\//).reverse().join("-"), b.return_at = h.split(/\.|\//).reverse().join("-"), i && (b.price = Number(mbr.tools.priceAnalyze(mbr.tools.getTextContents(i))) || 0, b.currency = "RUR"), mbr.Promise.resolve(b)) : mbr.Promise.reject()
}
}, {
name: "tripadvisor.ru",
urlRE: /https?\:\/\/(www\.)?tripadvisor\.(com|ru)\/CheapFlights/,
domain: "tripadvisor.ru",
getInfo: function(a) {
var b = a.URL,
c = {
origin: mbr.tools.getQueryParam(b, "Orig"),
destination: mbr.tools.getQueryParam(b, "Dest")
},
d = mbr.tools.getQueryParam(b, "leaveday"),
e = mbr.tools.getQueryParam(b, "retday");
return d && e && (1 === d.length && (d = "0" + d), 1 === e.length && (e = "0" + e), c.departure_at = d + "/" + mbr.tools.getQueryParam(b, "leavemonth"), c.return_at = e + "/" + mbr.tools.getQueryParam(b, "retmonth"), c.origin && c.destination && c.departure_at && c.return_at) ? (c.departure_at = c.departure_at.split("/").reverse().join("-"), c.return_at = c.return_at.split("/").reverse().join("-"), mbr.Promise.resolve(c)) : mbr.Promise.reject()
}
}, {
name: "momondo.ru",
urlRE: /https?:\/\/(?:www\.)?momondo\.ru\/.+?Search=true/,
domain: "momondo.ru",
getInfo: function(a) {
var b = a.URL,
c = {
origin: mbr.tools.getQueryParam(b, "SO0"),
destination: mbr.tools.getQueryParam(b, "SD0"),
departure_at: mbr.tools.getQueryParam(b, "SDP0"),
return_at: mbr.tools.getQueryParam(b, "SDP1")
};
return c.origin && c.destination && c.departure_at && c.return_at ? (c.departure_at = c.departure_at.split("-").reverse().join("-"), c.return_at = c.return_at.split("-").reverse().join("-"), new mbr.Promise(function(d) {
var e = "#flight-tickets-sortbar-cheapest .price",
f = "#wheelcontainer object",
g = function() {
var h = a.querySelector(e),
i = a.querySelector(f);
!i || i.offsetWidth < 100 ? (h && (c.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(h)), 10), c.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(h))), b = a.URL, c.origin = mbr.tools.getQueryParam(b, "SO0"), c.destination = mbr.tools.getQueryParam(b, "SD0"), c.departure_at = mbr.tools.getQueryParam(b, "SDP0"), c.return_at = mbr.tools.getQueryParam(b, "SDP1"), c.departure_at = c.departure_at.split("-").reverse().join("-"), c.return_at = c.return_at.split("-").reverse().join("-"), d(c)) : setTimeout(g, 500)
};
g()
})) : mbr.Promise.reject()
}
}, {
name: "buruki.ru",
urlRE: /https?:\/\/(?:www\.)?buruki\.ru\/search\/([a-z]{3})\/([a-z]{3})\/(\d{4}-\d{2}-\d{2})\/(\d{4}-\d{2}-\d{2})\/(\d+)/,
domain: "kayak.ru",
getInfo: function(a) {
var b = this.urlRE.exec(a.URL);
if (b) {
var c = {
origin: b[1].toUpperCase(),
destination: b[2].toUpperCase(),
departure_at: b[3],
return_at: b[4],
person: b[5]
};
return new mbr.Promise(function(b) {
var d = ".search-results-item .price",
e = ".bu-progress",
f = 60,
g = function() {
if (f--) {
var h = a.querySelector(d),
i = a.querySelector(e);
h && !i ? (c.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(h)), 10), c.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(h)), b(c)) : setTimeout(g, 500)
} else b(c)
};
g()
})
}
return mbr.Promise.reject()
}
}, {
name: "trip.ru",
urlRE: /https?:\/\/(www\.)?trip\.ru\/flights\/searches\//,
domain: "trip.ru",
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
var d = a.getElementById("workingIndication");
d || c();
var e = 60,
f = function() {
if (e--)
if ("none" === d.style.display) {
var g = {},
h = a.getElementById("resultsContainer");
h && (h = h.getAttribute("data-search-od"), h && (g.origin = h.split("-")[0], g.destination = h.split("-")[1])), g.departure_at = a.getElementById("e_travel_flights_search_departure").value, g.return_at = a.getElementById("e_travel_flights_search_return").value, g.person = parseInt(a.getElementById("passengers").value, 10);
var i = a.getElementById("lblMinPrice");
i && (g.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(i)), 10), g.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(i.parentNode))), b(g)
} else setTimeout(f, 1e3);
else c()
};
f()
})
}
}, {
name: "orenair.ru",
urlRE: /https?:\/\/(intershop\.)?orenair\.ru\/(.+?)\/timetable#timetable-pricing/,
domain: "intershop.orenair.ru",
getInfo: function(a) {
var b = {},
c = a.getElementById("originCityName"),
d = a.getElementById("destinationCityName"),
e = a.getElementById("thereDate"),
f = a.getElementById("backDate"),
g = a.getElementById("count-aaa");
if (c && d && e && f && g) {
b.origin = c.value, b.destination = d.value, b.departure_at = e.value.split(".").reverse().join("-"), b.return_at = f.value.split(".").reverse().join("-"), b.person = +g.value;
var h = a.querySelector("#payment-type-card a");
return h && (b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(h)), 10), b.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(h))), mbr.Promise.resolve(b)
}
return mbr.Promise.reject()
}
}, {
name: "utair.ru",
urlRE: /https?:\/\/(booking\.)?utair\.ru\/(.+?)\/avia\/b2b\/(tariffication|availability)\.jsf/,
domain: "booking.utair.ru",
getInfo: function(a) {
var b = a.referrer,
c = {
origin: mbr.tools.getQueryParam(b, "origin-city-name"),
destination: mbr.tools.getQueryParam(b, "destination-city-name"),
departure_at: mbr.tools.getQueryParam(b, "there-date"),
return_at: mbr.tools.getQueryParam(b, "back-date"),
person: +mbr.tools.getQueryParam(b, "count-aaa")
};
return c.origin && c.destination && c.departure_at && c.return_at && c.person ? (c.departure_at = c.departure_at.split(".").reverse().join("-"), c.return_at = c.return_at.split(".").reverse().join("-"), new mbr.Promise(function(b) {
var d = ".variant-cost a, .tarif-payment-variants a",
e = 60,
f = function() {
if (e--) {
var g = a.querySelector(d);
g ? (c.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(g)), 10), c.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(g)), b(c)) : setTimeout(f, 1e3)
} else b(c)
};
f()
})) : mbr.Promise.reject()
}
}, {
name: "pass.rzd.ru",
urlRE: /https?:\/\/pass\.rzd\.ru\/timetable\/.+?st0/,
domain: "pass.rzd.ru",
getInfo: function(a) {
var b = {},
c = a.URL.replace(/\|/g, "&"),
d = mbr.tools.getQueryParam(c, "st0"),
e = mbr.tools.getQueryParam(c, "st1"),
f = mbr.tools.getQueryParam(c, "dt0"),
g = mbr.tools.getQueryParam(c, "dt1");
return d && e && f && g ? (b.origin = d, b.destination = e, b.departure_at = f.split(".").reverse().join("-"), b.return_at = g.split(".").reverse().join("-"), mbr.Promise.resolve(b)) : mbr.Promise.reject()
}
}, {
name: "transport.marshruty.ru",
urlRE: /transport\.marshruty\.ru\/Transports\/Timetable\.aspx/,
domain: "transport.marshruty.ru",
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
var d = 60,
e = function() {
if (d--)
if (a.getElementById("ctnWaitSeats")) setTimeout(e, 1e3);
else {
var f = {},
g = a.querySelectorAll(".variants a");
g && 2 === g.length && (f.origin = mbr.tools.getTextContents(g[0]), f.destination = mbr.tools.getTextContents(g[1]));
var h = a.querySelector(".ritem");
if (h = h && h.getAttribute("rid"), h && (f.departure_at = h.substr(0, 8), f.return_at = h.substr(h.indexOf(",") + 1, 8), f.departure_at && f.return_at)) {
f.departure_at = f.departure_at.substr(0, 4) + "-" + f.departure_at.substr(4, 2) + "-" + f.departure_at.substr(6, 2), f.return_at = f.return_at.substr(0, 4) + "-" + f.return_at.substr(4, 2) + "-" + f.return_at.substr(6, 2), f.person = +mbr.tools.getQueryParam(a.URL, "adult") || 1;
var i = a.querySelector(".price");
return i && (f.price = +mbr.tools.priceAnalyze(mbr.tools.getTextContents(i)), f.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(i))), void b(f)
}
c()
} else c()
};
e()
})
}
}, {
name: "svyaznoy.travel",
urlRE: /(?:www\.)?svyaznoy\.travel\/#([A-Z]{3})(\d{2})(\d{2})\/([A-Z]{3})(\d{2})(\d{2})\/A(\d)/,
domain: "svyaznoy.travel",
getInfo: function(a) {
var b = this.urlRE.exec(a.URL),
c = {
origin: b[1],
destination: b[4],
person: +b[7]
},
d = b[2],
e = b[3],
f = b[5],
g = b[6],
h = (new Date).getFullYear(),
i = mbr.tools.isMonthOfNextYear(parseInt(e, 10)) ? h + 1 : h,
j = mbr.tools.isMonthOfNextYear(parseInt(g, 10)) || mbr.tools.isMonthOfNextYear(parseInt(e, 10)) ? h + 1 : h;
return c.departure_at = i + "-" + e + "-" + d, c.return_at = j + "-" + g + "-" + f, c.origin && c.destination && c.departure_at && c.return_at ? new mbr.Promise(function(b) {
var d = 60,
e = function() {
if (d--) {
var f = a.querySelector("#results_best .sum .price strong");
f ? (c.price = +mbr.tools.priceAnalyze(mbr.tools.getTextContents(f)), b(c)) : setTimeout(e, 1e3)
} else b(c)
};
e()
}) : mbr.Promise.reject()
}
}, {
name: "bravoavia.ru",
urlRE: /(www\.)?bravoavia\.ru\/vg1\/search\/results\.action/,
domain: "bravoavia.ru",
getInfo: function(a) {
return new mbr.Promise(function(b, c) {
var d = 60,
e = function() {
if (d--) {
var f = a.querySelector(".vg_sld_bar .rangeContainer");
if (f) {
var g = a.referrer,
h = {
origin: mbr.tools.getQueryParam(g, "departureAirport"),
destination: mbr.tools.getQueryParam(g, "arrivalAirport"),
departure_at: mbr.tools.getQueryParam(g, "outboundDay") + mbr.tools.getQueryParam(g, "outboundMonthYear"),
return_at: mbr.tools.getQueryParam(g, "returnDay") + mbr.tools.getQueryParam(g, "returnMonthYear")
};
if (h.origin && h.destination && h.departure_at && h.return_at) return h.departure_at = h.departure_at.substr(0, 2) + "-" + h.departure_at.substr(2, 2) + "-" + h.departure_at.substr(4, 4), h.return_at = h.return_at.substr(0, 2) + "-" + h.return_at.substr(2, 2) + "-" + h.return_at.substr(4, 4), h.price = Number(mbr.tools.priceAnalyze(mbr.tools.getTextContents(f))), h.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(f)), void b(h);
c()
} else setTimeout(e, 1e3)
} else c()
};
e()
})
}
}, {
name: "finnair.com",
urlRE: /https?:\/\/(www\.)finnair\.com\/pl\/AY(Online|Portal)\/wds\/(Override|StartOver|FlexPricerAvailability)\.action/,
domain: "finnair.com",
getInfo: function(a) {
var b = {},
c = a.querySelector("[name='B_LOCATION_1']"),
d = a.querySelector("[name='B_LOCATION_2']"),
e = a.querySelector("[name='B_DATE_1']"),
f = a.querySelector("[name='B_DATE_2']"),
g = a.querySelector("[name='NB_TRAVELLERS']");
if (c && d && e && f && g) {
b.origin = c.value, b.destination = d.value, b.departure_at = [e.value.substr(0, 4), e.value.substr(4, 2), e.value.substr(6, 2)].join("-"), b.return_at = [f.value.substr(0, 4), f.value.substr(4, 2), f.value.substr(6, 2)].join("-"), b.person = +g.value;
var h = a.querySelector(".priceSelectedEffectOff span, #roundtripBox1");
return h && (b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(h)), 10), b.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(h))), mbr.Promise.resolve(b)
}
return mbr.Promise.reject()
}
}, {
name: "letaem.ru",
urlRE: /https?:\/\/(www\.)?letaem\.ru\/search/,
domain: "letaem.ru",
getInfo: function(a) {
var b = {},
c = a.getElementById("pseudoFromCode"),
d = a.getElementById("pseudoToCode"),
e = a.getElementById("dateThere"),
f = a.getElementById("dateBack");
if (c && d && e && f) {
b.origin = c.value, b.destination = d.value, b.departure_at = e.value.split(".").reverse().join("-"), b.return_at = f.value.split(".").reverse().join("-");
var g = a.querySelector(".price");
return g && (b.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(g)), 10), b.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(g))), mbr.Promise.resolve(b)
}
return mbr.Promise.reject()
}
}, {
name: "light-flight.ru",
urlRE: /https?:\/\/light\-flight\.ru\/ticketsearch/,
domain: "light-flight.ru",
getInfo: function(a) {
var b = a.URL,
c = {
origin: mbr.tools.getQueryParam(b, "from"),
destination: mbr.tools.getQueryParam(b, "to"),
departure_at: mbr.tools.getQueryParam(b, "dateThere"),
return_at: mbr.tools.getQueryParam(b, "dateBack"),
person: mbr.tools.getQueryParam(b, "adult")
};
if (c.origin && c.destination && c.departure_at && c.return_at && c.person) {
c.departure_at = c.departure_at.split(".").reverse().join("-"), c.return_at = c.return_at.split(".").reverse().join("-"), c.person = +c.person || 1;
var d = a.querySelector(".ticketBlock .head");
return d && (c.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(d)), 10), c.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(d))), mbr.Promise.resolve(c)
}
return mbr.Promise.reject()
}
}, {
name: "avia.euroset.ru",
urlRE: /avia\.euroset\.ru\/\?go\=flights\/results/,
domain: "avia.euroset.ru",
getInfo: function(a) {
var b = mbr.tools.getQueryParam(a.URL, "sro"),
c = /([A-Z]{3})([A-Z]{3})(\d{2}\.\d{2}\.\d{4})RT(\d{2}\.\d{2}\.\d{4})(\d)/;
if (c.test(b)) {
var d = {
origin: RegExp.$1,
destination: RegExp.$2,
departure_at: RegExp.$3.split(".").reverse().join("-"),
return_at: RegExp.$4.split(".").reverse().join("-"),
person: +RegExp.$5
},
e = a.querySelector(".item_foot a");
return e && (d.price = parseInt(mbr.tools.priceAnalyze(mbr.tools.getTextContents(e)), 10), d.currency = mbr.tools.getCurrencyFromStr(mbr.tools.getTextContents(e))), mbr.Promise.resolve(d)
}
return mbr.Promise.reject()
}
}],
getInfo: function(a) {
for (var b = 0; b < this._sites.length; b++)
if (this._sites[b].urlRE.test(a.URL)) {
var c = this._sites[b].getInfo(a);
return c.then(function(b) {
b.method = "avia", b.url = a.URL, mbr.hub.trigger("parser:found", b)
}), c
}
return mbr.Promise.reject()
},
isAviaDomain: function(a) {
a = a || "";
for (var b = 0; b < this._sites.length; b++)
if (a.indexOf(this._sites[b].domain) > -1) return !0;
return !1
},
_canParse: function() {
return mbr.settings.isAviaEnabled()
},
run: function(a) {
return this._canParse() ? (mbr.log("start avia"), this.getInfo(a).then(function(a) {
return mbr.suggest.getFlights(a)
})) : mbr.Promise.reject()
}
}, mbr.domainParser = {
_shopId: "mbr-price-context-shop",
_canParse: function(a) {
return mbr.settings.isProductSuggestEnabled(a) && mbr.settings.canCheckDomain(a)
},
_detect: function(a) {
var b = this._shopId,
c = localStorage.getItem(b);
if (c) return "true" === c ? mbr.Promise.resolve() : mbr.Promise.reject();
var d = mbr.Promise(function(b, c) {
mbr.JSONP ? mbr.JSONP.get("https://ajax.googleapis.com/ajax/services/search/web?", {
v: "1.0",
q: '"Отзывы о магазине" "' + a + '" site:market.yandex.ru'
}, function(a) {
a && a.responseData.results && a.responseData.results.length ? b() : c()
}) : c()
});
return d.then(function() {
localStorage.setItem(b, "true")
}).catch(function() {
localStorage.setItem(b, "false")
}), d
},
_getProductName: function(a) {
var b;
return b = a.querySelector("h1"), b ? mbr.tools.getTextContents(b) : null
},
_parse: function(a) {
var b = this._getProductName(a),
c = this.getProductPrice(a);
if (b) {
if (c) return mbr.hub.trigger("parser:found", {
method: "url-search",
name: b
}), {
name: b,
price: c
};
mbr.log("price not found")
}
return null
},
run: function(a) {
var b = mbr.tools.getHostname(a),
c = (this._detect.bind(this), this.getProductPrice.bind(this));
return this._canParse(b) ? (mbr.log("dm.run!"), this._detect(b).then(function() {
mbr.log("this is a shop");
var b = c(a);
return b ? (mbr.log("price is found"), mbr.hub.trigger("domainParser:found", {
method: "url-search"
}), mbr.suggest.getProductOfferByURL({
url: a.URL,
productPrice: b
})) : (mbr.log("price is not found"), mbr.Promise.reject())
})) : mbr.Promise.reject()
}
}, mbr.tools.mixin(mbr.domainParser, mbr.priceParser), mbr.couponsParser = {
_canShowCoupons: function() {
return mbr.settings.canShowCoupon() && !mbr.cookie.get("mbr-have-not-coupons")
},
_getCoupons: function(a) {
var b = mbr.cookie.get("mbr-coupons");
if (b) return b = JSON.parse(window.unescape(b)), mbr.hub.trigger("coupons:found", b), mbr.Promise.resolve(b);
var c = mbr.suggest.getCoupons(a);
return c.then(function(a) {
var b = new Date;
b.setDate(b.getDate() + 10), mbr.cookie.set("mbr-coupons", JSON.stringify(a), b), mbr.hub.trigger("coupons:found", a)
}).catch(function() {
var a = new Date;
a.setDate(a.getDate() + 10), mbr.cookie.set("mbr-have-not-coupons", "true", a)
}), c
},
run: function(a) {
if (mbr.log("coupons.run!"), !this._canShowCoupons()) return mbr.Promise.reject();
var b = mbr.tools.getHostname(a);
return this._getCoupons(b)
}
}, mbr.searchParser = {
_isFirstSearch: function(a) {
return !mbr.cookie.get(a)
},
_searchEngines: {
"Mail.ru": {
urlPattern: /https?:\/\/go\.mail\.ru\/search/,
queryParam: "q",
nextPageParam: "sf"
},
Yandex: {
urlPattern: /https?:\/\/(?:www.)?yandex\.ru\/yandsearch/,
queryParam: "text",
nextPageParam: "p"
},
Google: {
urlPattern: /^https?:\/\/(?:www.)?google\.(ru|com)\/.+q=/,
nextPageParam: "start",
queryParam: "q"
},
SuperJob: {
urlPattern: /https?:\/\/(?:www.)?superjob\.ru\/(vacancy|resume)\/search/,
queryParam: "keywords[0][keys]",
nextPageParam: "page"
},
Avito: {
urlPattern: /https?:\/\/(?:www.)?avito\.ru\/.+?\//,
queryParam: "q",
infoRe: /https?:\/\/(?:www.)?avito\.ru\/.+?\/([^\/\?]+)\/?([^\?]+)?(?:.*?)(?:q\=([^&]+))?$/,
priceContextSections: {
telefony: !0,
bytovaya_elektronika: !0,
velosipedy: !0,
bytovaya_tehnika: !0,
tovary_dlya_kompyutera: !0,
audio_i_video: !0
},
isPriceContextEnabled: function(a) {
var b = this.infoRe.exec(a);
if (b && b.length) {
var c = b[1];
return !!this.priceContextSections[c]
}
return !1
}
}
},
getInfoFromAvito: function(a) {
var b, c, d, e = this._searchEngines.Avito.infoRe.exec(a),
f = null;
return e && e.length && (b = e[1], c = e[2], d = e[3], f = {}, b && (f.section = b), c && -1 === c.search(/_\d+$/) && (f.subSection = c), d && (f.query = decodeURIComponent(d.replace(/\+/g, " ")))), f
},
getInfoAboutSearchPage: function(a) {
var b = null;
for (var c in this._searchEngines) this._searchEngines.hasOwnProperty(c) && (!this._searchEngines[c].urlPattern.test(a) || this._searchEngines[c].nextPageParam && -1 !== a.indexOf(this._searchEngines[c].nextPageParam + "=") || (b = {}, "Avito" === c ? b = this.getInfoFromAvito(a) : (b.query = mbr.tools.getQueryParam(a, this._searchEngines[c].queryParam), "SuperJob" === c && (b.type = this._searchEngines[c].urlPattern.exec(a)[1])), b.engine = c));
return b
},
_canFindOffers: function(a) {
return mbr.settings.isProductSuggestEnabled(a)
},
run: function(a) {
mbr.log("search run!");
var b = a.URL,
c = mbr.tools.getHostname(a),
d = this.getInfoAboutSearchPage(b);
return d && (mbr.hub.trigger("search", d), this._searchEngines[d.engine].isPriceContextEnabled && this._searchEngines[d.engine].isPriceContextEnabled(b) && d.query && this._isFirstSearch(d.query) && (mbr.cookie.set(d.query, "true"), this._canFindOffers(c))) ? mbr.suggest.getProductOffers({
productName: d.query,
url: b,
method: "search"
}) : mbr.Promise.reject()
}
}, mbr.parserPipe = mbr.parserPipe || {
_state: "",
_canAddParser: !0,
_parsers: [],
_callNext: function() {
this._state = "pending";
var a = this._parsers.shift();
a && a.run(document).then(this._onPromiseResolve, this._onPromiseReject)
},
_onPromiseResolve: function() {
this._state = "fulfilled", mbr.hub.trigger("pipe:fulfill")
},
_onPromiseReject: function() {
this._state = "rejected", 0 !== this._parsers.length || this._canAddParser ? this._callNext() : mbr.hub.trigger("pipe:reject")
},
isDone: function() {
return "fulfilled" === this._state
},
isPending: function() {
return "pending" === this._state
},
addParser: function(a) {
return a && "function" == typeof a.run && !this.isDone() && this._canAddParser && (this._parsers.push(a), this.isPending() || this._callNext()), this
},
end: function() {
this._canAddParser = !1
},
init: function() {
return this._state = "", this._parsers = [], this._canAddParser = !0, this._onPromiseReject = this._onPromiseReject.bind(this), this._onPromiseResolve = this._onPromiseResolve.bind(this), this
}
}, Randomizer.prototype._getAllClassesAndIds = function() {
for (var a = {}, b = /(?:class|id)\s*=["'](.+?)["']/g, c = null; c = b.exec(this.html);) c[1].replace(/\s+/, " ").split(" ").forEach(function(b) {
b && (a[b] = !0)
});
return Object.keys(a).sort(function(a, b) {
return b.length - a.length
})
}, Randomizer.prototype._createRandomNames = function(a) {
var b = {},
c = this.saveNames;
return a.forEach(function(a) {
b[a] = c ? a : "mxxxxxxxxxxxx".replace(/x/g, function() {
return Math.round(35 * Math.random()).toString(36)
})
}), b
}, Randomizer.prototype._createRandomizationRegEx = function(a) {
return new RegExp(a.join("|"), "g")
}, Randomizer.prototype.randomize = function(a) {
return a.replace(this.re, function(a) {
return this.randomNames[a]
}.bind(this))
}, mbr.Randomizer = Randomizer, mbr.feedback = mbr.feedback || {
_url: "http://jira.metabar.ru/rest/api/2/issue/",
_highPrice: {
summary: "Высокая цена на {{productName}}",
description: "Страница - {{url}}\nОпределенное название - {{originProductName}}\nОпределенная цена - {{originPrice}}\nВалюта - {{currency}}\n----\nНазвание на прайсбаре - {{productName}}\nЦена на прайсбаре - {{price}}\n----\nМетод извлечения - {{extractMethod}}\nГород - {{region}}\nUser-Agent: {{userAgent}}\n----\n{code:javascript}{{settings}}{code}\n----\nCookies:\n||Name||Value||\n{{cookiesTable}}\nLocal Storage:\n||Name||Value||\n{{localStorageTable}}----\nСсылка-запрос к серверу - {{requestUrl}}\nОтвет сервера - {code:javascript}{{serverResponse}}{code}\n"
},
_wrongName: {
summary: "Неверно определен товар {{productName}}",
description: "Страница - {{url}}\nОпределенное название - {{originProductName}}\nОпределенная цена - {{originPrice}}\nВалюта - {{currency}}\n----\nНазвание на прайсбаре - {{productName}}\nЦена на прайсбаре - {{price}}\n----\nМетод извлечения - {{extractMethod}}\nГород - {{region}}\nUser-Agent: {{userAgent}}\n----\n{code:javascript}{{settings}}{code}\n----\nCookies:\n||Name||Value||\n{{cookiesTable}}\nLocal Storage:\n||Name||Value||\n{{localStorageTable}}----\nСсылка-запрос к серверу - {{requestUrl}}\nОтвет сервера - {code:javascript}{{serverResponse}}{code}\n"
},
_unknownError: {
summary: "Ошибка в предложении {{productName}}",
description: 'Сообщение пользователя: "{{message}}"\n----\nСтраница - {{url}}\nОпределенное название - {{originProductName}}\nОпределенная цена - {{originPrice}}\nВалюта - {{currency}}\n----\nНазвание на прайсбаре - {{productName}}\nЦена на прайсбаре - {{price}}\n----\nМетод извлечения - {{extractMethod}}\nГород - {{region}}\nUser-Agent: {{userAgent}}\n----\n{code:javascript}{{settings}}{code}\n----\nCookies:\n||Name||Value||\n{{cookiesTable}}\nLocal Storage:\n||Name||Value||\n{{localStorageTable}}----\nСсылка-запрос к серверу - {{requestUrl}}\nОтвет сервера - {code:javascript}{{serverResponse}}{code}\n'
},
_prepareString: function(a, b) {
return a.replace(/{{message}}/g, b.message).replace(/{{productName}}/g, b.productName).replace(/{{url}}/g, b.url).replace(/{{requestUrl}}/g, b.requestUrl).replace(/{{originProductName}}/g, b.originProductName).replace(/{{originPrice}}/g, b.originPrice).replace(/{{serverResponse}}/g, b.serverResponse).replace(/{{settings}}/g, b.settings).replace(/{{extractMethod}}/g, b.extractMethod).replace(/{{region}}/g, b.regionName || "Определен автоматически").replace(/{{currency}}/g, b.currency || "Unknown").replace(/{{userAgent}}/g, navigator.userAgent).replace(/{{price}}/g, b.price).replace(/{{cookiesTable}}/g, mbr.settings.getCookiesTable()).replace(/{{localStorageTable}}/g, mbr.settings.getLocalStorageTable())
},
_sendMessage: function(a, b, c) {
var d = {
fields: {
project: {
key: "SOV"
},
summary: a,
description: b,
issuetype: {
name: "Bug"
},
labels: [c],
customfield_11130: "%REMOTE_IP%"
}
};
mbr.xhr.post(this._url, d)
},
trackHighPrice: function(a, b, c, d, e, f, g) {
var h = this._prepareString(this._highPrice.summary, {
productName: b
}),
i = this._prepareString(this._highPrice.description, {
url: a,
productName: b,
requestUrl: f.query,
originProductName: f && f.productName,
extractMethod: d,
serverResponse: e,
regionName: mbr.settings.getRegionName(),
price: c,
originPrice: f && (f.price || f.productPrice),
currency: f && f.currency,
settings: JSON.stringify(g, 2, 2)
});
this._sendMessage(h, i, "high_price")
},
trackWrongProduct: function(a, b, c, d, e, f, g) {
var h = this._prepareString(this._wrongName.summary, {
productName: b
}),
i = this._prepareString(this._wrongName.description, {
url: a,
productName: b,
requestUrl: f.query,
originProductName: f && f.productName,
extractMethod: d,
serverResponse: e,
regionName: mbr.settings.getRegionName(),
price: c,
currency: f && f.currency,
originPrice: f && (f.price || f.productPrice),
settings: JSON.stringify(g, 2, 2)
});
this._sendMessage(h, i, "wrong_offer")
},
trackUnknownError: function(a, b, c, d, e, f, g, h) {
var i = this._prepareString(this._unknownError.summary, {
productName: c
}),
j = this._prepareString(this._unknownError.description, {
message: a,
url: b,
productName: c,
requestUrl: g.query,
originProductName: g && g.productName,
extractMethod: e,
serverResponse: f,
regionName: mbr.settings.getRegionName(),
price: d,
originPrice: g && (g.price || g.productPrice),
currency: g && g.currency,
settings: JSON.stringify(h, 2, 2)
});
this._sendMessage(i, j, "unknown_error")
}
}, mbr.abtest = mbr.abtest || {
tests: [{
match: {
delivery_info: "original"
},
ids: {
aviaBrightOptIn: 59,
aviaOptIn: 49,
aviaLowest: 51,
avia: 53,
popup: 174,
"default": 172
}
}, {
match: {
delivery_info: "delivery_info"
},
ids: {
aviaBrightOptIn: 59,
aviaOptIn: 49,
aviaLowest: 51,
avia: 53,
popup: 178,
"default": 176
}
}],
getModificators: function(a) {
a = a || {};
var b = [];
this.tests.forEach(function(b) {
for (var c in b.match) b.match.hasOwnProperty(c) && !a.hasOwnProperty(c) && (a[c] = "original")
});
for (var c in a) a.hasOwnProperty(c) && b.push(c + "_" + a[c]);
return b
},
getIds: function(a) {
var b, c, d;
if (a)
for (b = 0; b < this.tests.length; b++) {
d = !1;
for (c in this.tests[b].match)
if (this.tests[b].match.hasOwnProperty(c)) {
if (a[c] !== this.tests[b].match[c]) {
d = !1;
break
}
d = !0
}
if (d) return this.tests[b].ids
}
return null
}
}, mbr.hasoffersTracking = mbr.hasoffersTracking || {
_defaultIds: {
aviaBrightOptIn: 59,
aviaOptIn: 49,
aviaLowest: 51,
avia: 53,
avitoBrightOptIn: 57,
avitoOptIn: 47,
avitoLowest: 35,
avito: 41,
brightOptIn: 55,
optIn: 45,
lowest: 21,
best: 33,
equalsPrice: 29,
higherPrice: 31,
profitable: 43,
popupTop: 61,
popup1: 63,
popup2: 65,
popup3: 67,
popup4: 69,
popup5: 71,
isDressWildberries: 99,
isDressLamoda: 101,
isAliexpress: 103
},
_wrapUrl: function(a, b) {
return "undefined" != typeof b ? a + "&file_id=" + b : a
},
wrapAviaURL: function(a, b, c) {
c = c || this._defaultIds;
var d = b.optInShown && b.isBrightOptIn && c.aviaBrightOptIn || b.optInShown && c.aviaOptIn || b.isLowest && c.aviaLowest || c.avia || c.default;
return this._wrapUrl(a, d)
},
wrapMainURL: function(a, b, c) {
c = c || this._defaultIds;
var d = b.isPriceDefined && c.priceDefined || c.priceUndefined || b.isDressWildberries && c.isDressWildberries || b.isDressLamoda && c.isDressLamoda || b.isAliexpress && c.isAliexpress || b.optInShown && b.isBrightOptIn && b.isAvito && c.avitoBrightOptIn || b.optInShown && b.isBrightOptIn && c.brightOptIn || b.optInShown && b.isAvito && c.avitoOptIn || b.optInShown && c.optIn || b.isAvito && b.isLowest && c.avitoLowest || b.isAvito && c.avito || (b.isBest || b.isAvito) && c.best || b.isLowest && c.lowest || b.isEqualsPrice && c.equalsPrice || b.isHigherThanCurrent && c.higherPrice || b.isProfitable && c.profitable || c.default;
return this._wrapUrl(a, d)
},
wrapPopupURL: function(a, b, c, d) {
d = d || this._defaultIds, c = c || {};
var e = [d.popupTop, d.popup1, d.popup2, d.popup3, d.popup4, d.popup5];
return c.isPriceDefined && !c.isAvito ? c.isEqualsPrice || c.isHigherThanCurrent ? (e[0] = d.popupCompareTop || e[0], d.popup = d.popupCompare || d.popup) : c.isLowest ? (e[0] = d.popupLowestTop || e[0], d.popup = d.popupLowest || d.popup) : (e[0] = d.popupProfitableTop || e[0], d.popup = d.popupProfitable || d.popup) : (e[0] = d.popupPriceUndefinedTop || e[0], d.popup = d.popupPriceUndefined || d.popup), this._wrapUrl(a, e[b] || d.popup || d.default)
}
};
var pricebar = {
type: "",
data: {},
css: null,
template: null,
html: null,
_offerAccepted: void 0,
events: {
"click #market_context_headcrab": "_openUrl",
"click .shop-url": "_shopOpened",
"click #price_context_show_price": "_acceptOffer",
"click #price_context_no": "_declineOffer",
"click #market_context_question": "_toggleInfo",
"click #market_context_settings": "_toggleSettings",
"click #market_context_shops": "_toggleShops",
"click #market_context_headcrab .pb-sitebar_popover-close": "_hidePopovers",
"click #market_context_close": "_closePopup",
"click #checkbox_do_not_show": "_toggleDisallowDomain",
"click body": "_onBodyClick",
"mouseenter .pb-sitebar-options": "_preventShowShops",
"mouseleave .pb-sitebar-options": "_stopPreventingShowShops",
"mouseenter #market_context_headcrab,#market_context_shops,.pb-sitebar-button": "_initShowShops",
"mouseenter .pb-sitebar-right-action": "_cancelShowShops",
"mouseleave #market_context_headcrab": "_cancelShowShops",
"click #sitebar_shops_popover, #sitebar_settings_popover, #sitebar_info_popover, #sitebar_clothes_popover": "_onPopoverClick",
"resize window": "_fixOfferPosition",
"click .wrong-product, .high-price, .unknown-error, .wrong-region": "_sendError",
"submit #form-error": "_sendError",
"click .pb-sitebar-carousel .clothes-carousel-control": "_carouselControlClick"
},
ids: {
pricebar: "market_context_headcrab",
price: "market_context_price",
offerPopup: "sitebar_policy_popover",
offerYesButton: "price_context_show_price",
popoverInfo: "sitebar_info_popover",
popoverSettings: "sitebar_settings_popover",
popoverShops: "sitebar_shops_popover",
popoverClothes: "sitebar_clothes_popover",
checkboxDoNotShow: "checkbox_do_not_show",
popoverThanks: "sitebar_feedback_popover",
formError: "form-error",
clothesCarousel: "clothes-carousel"
},
classes: {
offerShown: "pb-sitebar_offer",
buttonGo: "pb-sitebar-button",
shoplist: "shoplist",
text: "pb-sitebar-cnt",
carouselDisabled: "slick-disabled",
carouselPrev: "slick-prev",
clothesCarouselControl: "clothes-carousel-control"
},
clean: function() {
this.type = "", this.data = {}, this.html = null, this._offerAccepted = void 0
},
init: function(a, b, c) {
c = c || {}, this.type = a, this.extractMethod = b.method || "", this.original = b.original || {};
try {
this.serverResponse = JSON.stringify(b, 2, 2)
} catch (d) {
this.serverResponse = JSON.stringify(b)
}
var e = b.offers ? b.offers[0] : b;
this.data = {
isAvia: "avia" === a,
isProduct: "product" === a,
isAvito: c.isAvito || mbr.settings.isAvitoSite(),
isDefaultScript: "undefined" != typeof c.isDefaultScript ? c.isDefaultScript : mbr.settings.isDefaultScript(),
isMbrApplication: "undefined" != typeof c.isMbrApplication ? c.isMbrApplication : mbr.settings.isMbrApplication(),
appName: c.appName || mbr.settings.getAppName(),
showOffer: "undefined" != typeof c.showOffer ? c.showOffer : mbr.settings.needShowOffer(),
showOfferInvert: "undefined" != typeof c.showOfferInvert ? c.showOfferInvert : mbr.settings.needShowInvertOptIn(),
isLowestPrice: e.guaranteedLowestPrice,
isMostRelevant: e.mostRelevant,
url: e.url,
autoShowShopList: "undefined" != typeof c.autoShowShopList ? c.autoShowShopList : mbr.settings.isAutoShowingShopListEnabled(),
bestOffers: b.bestOffers,
viewModificators: c.viewModificators || mbr.settings.getViewModificators(),
customLogo: c.customLogo || mbr.settings.getCustomLogo()
};
var f = mbr.abtest.getModificators(b.bucketInfo),
g = mbr.abtest.getIds(b.bucketInfo);
if (this.data.abClass = f.join(" "), this.data.ab = {}, f.forEach(function(a) {
this.data.ab[a] = !0
}.bind(this)), "product" === a && e.name) {
var h = e.name.split("(")[0];
this.data.originalProductName = h, h && h.length > 64 && (h = h.substr(0, 64) + "..."), this.data.productName = h, this.data.photo = e.photo, this.data.shop = e.shopInfo, this.data.type = this._getTypeOffer(e), this.data.isHigherThanCurrent = e.price.isHigherThanCurrent, this.data.isEqualToCurrent = e.price.isEqualToCurrent, this.data.shops = b.offers.map(function(a) {
return a.shopInfo.rating = Math.max(a.shopInfo.rating, 0), {
name: a.shopInfo.name,
rating: a.shopInfo.rating,
url: a.url,
price: mbr.tools.formatPrice(a.price.value, a.price.currencyName || ""),
type: this._getTypeOffer(a),
trackingImg: a.trackingImg,
photo: a.photo
}
}.bind(this)), this.data.bestOffers = this.data.bestOffers || !this.original.productPrice || !this.data.isAvito && (this.data.isHigherThanCurrent || this.data.isEqualToCurrent);
var i = {
isAvito: this.data.isAvito,
isLowest: this.data.isLowestPrice,
isBest: this.data.bestOffers,
isEqualsPrice: !this.data.isAvito && this.data.isEqualToCurrent,
isHigherThanCurrent: !this.data.isAvito && this.data.isHigherThanCurrent,
isProfitable: !this.data.isLowestPrice && !this.data.isHigherThanCurrent && !this.data.bestOffers,
optInShown: this.data.showOffer,
isBrightOptIn: this.data.showOfferInvert,
isDressWildberries: mbr.settings.isWildberries(),
isDressLamoda: mbr.settings.isLamoda(),
isAliexpress: mbr.settings.isAliexpress(),
isPriceDefined: !!this.original.productPrice
},
j = 0;
(!this.data.bestOffers || this.data.isAvito) && this.data.shops && this.data.shops.length > 1 && (j = 1), this.data.popupsImages = [];
var k = mbr.settings.isWildberries() || mbr.settings.isLamoda();
k || (this.data.bestShop = this.data.shops.splice(j, 1, this.data.shops[0])[0], this.data.bestShop.url = mbr.hasoffersTracking.wrapPopupURL(this.data.bestShop.url, 0, {
isPriceDefined: !!this.original.productPrice
}, g), this.data.popupsImages.push(mbr.hasoffersTracking.wrapPopupURL(this.data.bestShop.trackingImg, 0, {
isPriceDefined: !!this.original.productPrice
}, g)), this.data.shops.splice(0, 1)), this.data.shops.forEach(function(a, b) {
a.index = b + 1, a.url = mbr.hasoffersTracking.wrapPopupURL(a.url, b + 1, i, g), this.data.popupsImages.push(mbr.hasoffersTracking.wrapPopupURL(a.trackingImg, b + 1, i, g))
}.bind(this)), k && (this.data.clothes = this.data.shops, this.data.onePage = this.data.shops.length < 4, delete this.data.shops), this.data.url = mbr.hasoffersTracking.wrapMainURL(this.data.url, i, g), this.data.trackLogo = mbr.hasoffersTracking.wrapMainURL(e.trackingImg, i, g), this.data.ab.delivery_info_delivery_info && e.delivery ? (this.data.deliveryText = "с доставкой", this.data.deliveryRequired = !0) : this.data.deliveryText = this.data.ab.delivery_info_delivery_info && "" || "в вашем регионе"
}
if ("avia" === a && (this.data.originCity = e.originCity, this.data.destinationCity = e.destinationCity, this.data.departureAt = mbr.tools.formatDate(e.departureAt), this.data.returnAt = mbr.tools.formatDate(e.returnAt), this.data.routeText = this.data.originCity + " " + this.data.departureAt + " - " + this.data.destinationCity + " " + this.data.returnAt, this.data.url = mbr.hasoffersTracking.wrapAviaURL(this.data.url, {
isLowest: this.data.isLowestPrice,
optInShown: this.data.showOffer,
isBrightOptIn: this.data.showOfferInvert
}, g), this.data.trackLogo = mbr.hasoffersTracking.wrapAviaURL(e.trackingImg, {
isLowest: this.data.isLowestPrice,
optInShown: this.data.showOffer,
isBrightOptIn: this.data.showOfferInvert
}, g)), e.price && (this.data.priceText = mbr.tools.formatPrice(e.price.value, e.price.currencyName || "")), this.data.comparePopup) {
if (this.data.showOffer) return void mbr.log("do not show a pricebar if offer has not accepted");
if (this.data.shops && 0 === this.data.shops.length || this.data.clothes && this.data.clothes.length < 2) return void mbr.log("do not show a pricebar if we have only one offer")
}
return this._randomizer = new Randomizer(this._getHTMLFromTemplate(), !mbr.settings.needRandomize()), this._render(), this
},
_getTypeOffer: function(a) {
return a.mostRelevant ? "BestCPC" : a.guaranteedLowestPrice ? "Lowest" : "Profitable"
},
_injectCSS: function(a) {
var b = document.createElement("style");
b.textContent = a, b.text = a, document.body.appendChild(b)
},
_prepareExistingStyle: function() {
var a, b = document.styleSheets;
if (b) {
for (var c = 0; c < b.length; c++)
if (b[c].ownerNode && "mbrstl" === b[c].ownerNode.id) {
a = b[c];
break
}
if (a && a.cssRules && a.cssRules.length)
for (var d, e, f = a.cssRules.length; f--;) d = a.cssRules[0], e = d.selectorText || "", a.insertRule(d.cssText.replace(e, this._randomizer.randomize(e)), a.cssRules.length), a.deleteRule(0)
}
},
_loadTemplate: function() {
var a = "",
b = document.getElementById("mbrtmplt");
return b ? (a = b.innerHTML, b.parentNode.removeChild(b), a) : a
},
_getHTMLFromTemplate: function() {
return this.html || (this.template = this.template || this._loadTemplate(), this.template && (this.html = mbr.Mustache.render(this.template, this.data))), this.html
},
_render: function() {
this.css ? this._injectCSS(this._randomizer.randomize(this.css)) : this._prepareExistingStyle();
var a = window.document.createElement("div"),
b = this._randomizer.randomize(this._getHTMLFromTemplate());
if (b) {
a.innerHTML = b, this.el = a.childNodes[0], this.el.style.top = "-40px", window.document.body.appendChild(this.el);
var c = document.querySelector("." + this._randomizer.randomize(this.classes.text)),
d = mbr.tools.getTextContents(c);
d = d.replace(this.data.productName, this.data.originalProductName), c.setAttribute("title", d), this.data.showOffer ? (this._fixOfferPosition(), mbr.hub.trigger("pricebar:optInShow", this.data.showOfferInvert, this.type)) : this.data.comparePopup || mbr.hub.trigger("pricebar:show", this.type), this._bindEvents(), this._animateShow(), this._startPricebarHighlighting(), mbr.hub.trigger("pricebar:render", (new Date).getTime())
}
},
_animateShow: function() {
var a = -39,
b = parseInt(document.documentElement.style.marginTop, 10) || 0;
document.documentElement.setAttribute("mbr-initial-margin-top", b), document.documentElement.setAttribute("mbr-initial-position", document.documentElement.style.position), mbr.settings.canAddRelativePosition(mbr.tools.getHostname(document)) && (document.documentElement.style.position = "relative");
var c = this.el,
d = setInterval(function() {
a += 2, b += 2, -1 === a && clearInterval(d), c.style.top = a + "px", document.documentElement.style.setProperty("margin-top", b + "px", "important")
}, 15)
},
_fixOfferPosition: function() {
var a = this._getElementById(this.ids.price),
b = this._getElementById(this.ids.offerPopup);
a && b && (b.style.left = Math.round(a.offsetLeft - a.offsetWidth / 2) - 140 + "px")
},
_bindEvents: function() {
var a, b = /^(\S+)\s(.+)$/;
for (var c in this.events) this.events.hasOwnProperty(c) && (a = b.exec(c), a && a.length > 2 && this._addEventListener(a[2], a[1], this.events[c]))
},
_getElementById: function(a) {
return document.getElementById(this._randomizer.randomize(a))
},
_querySelectorAll: function(a) {
return document.querySelectorAll(this._randomizer.randomize(a))
},
_addEventListener: function(a, b, c) {
if ("function" == typeof this[c] && (a = "string" == typeof a && this._querySelectorAll(a) || a)) {
var d = this[c].bind(this);
if (a && a[0] == window) window.addEventListener(b, d, !1);
else
for (var e = 0; e < a.length; e++) a[e].addEventListener ? a[e].addEventListener(b, d, !1) : a[e].attachEvent && a[e].attachEvent("on" + b, d)
}
},
hidePopup: function() {
this.el.style.setProperty("display", "none", "important");
var a = document.documentElement.getAttribute("mbr-initial-margin-top") || 0;
document.documentElement.style.removeProperty("margin-top"), document.documentElement.style.marginTop = a + "px";
var b = document.documentElement.getAttribute("mbr-initial-position") || "";
document.documentElement.style.position = b
},
_toggleInfo: function(a) {
var b = this._getElementById(this.ids.popoverInfo),
c = "block" === b.style.display;
return this._hidePopovers(), b.style.display = c ? "none" : "block", c || (mbr.hub.trigger("pricebar:showInfoPopup", this.type), mbr.hub.trigger("pricebar:click", this.type, !1, "FeedbackButton")), a.stopPropagation(), !1
},
_toggleSettings: function(a) {
var b = this._getElementById(this.ids.popoverSettings),
c = "block" === b.style.display;
return this._hidePopovers(), b.style.display = c ? "none" : "block", c || (mbr.hub.trigger("pricebar:showSettingsPopup", this.type), mbr.hub.trigger("pricebar:click", this.type, !1, "SettingsButton")), a.stopPropagation(), !1
},
_getShopsPopover: function() {
return this._getElementById(this.ids.popoverShops) || this._getElementById(this.ids.popoverClothes)
},
_toggleShops: function(a) {
var b = this._getShopsPopover();
if (b) {
var c = this._isShopsPopupVisible();
return this._hidePopovers(), a && mbr.hub.trigger("shop:allButtonClicked"), c ? this._hideShopsPopup() : (this._showShopsPopup(), mbr.hub.trigger("shop:openList", !!this.data.shops)), a && a.stopPropagation(), !1
}
},
_showShopsPopup: function() {
if (!this._isShopsPopupVisible() && !this._isSomePopupVisible() && -1 === this.el.className.indexOf(this._randomizer.randomize(this.classes.offerShown))) {
this._hidePopovers();
var a = this._getShopsPopover();
a && (this.el.className += " " + this._randomizer.randomize(this.classes.shoplist), mbr.hub.trigger("shop:openList", !!this.data.shops), this.data.popupsImages && (this.data.popupsImages.forEach(function(b) {
var c = document.createElement("img");
c.src = b, c.width = 1, c.height = 1, c.style.position = "absolute", c.style.bottom = 0, c.style.right = 0, c.style.visibility = "hidden", c.style.zIndex = 0, a.appendChild(c)
}), this.data.popupsImages = null))
}
},
_hideShopsPopup: function() {
this._showShopsTimeout = null;
var a = this._getShopsPopover();
a && (this.el.className = this.el.className.replace(" " + this._randomizer.randomize(this.classes.shoplist), ""))
},
_isShopsPopupVisible: function() {
return this._getShopsPopover() && this.el.className.indexOf(this._randomizer.randomize(this.classes.shoplist)) > -1
},
_isSomePopupVisible: function() {
var a = this._getElementById(this.ids.popoverInfo),
b = this._getElementById(this.ids.popoverSettings);
return this._isShopsPopupVisible() || a && "none" !== a.style.display || b && "none" !== b.style.display || this.el.className.indexOf(this._randomizer.randomize(this.classes.offerShown)) > -1
},
_acceptOffer: function(a) {
return mbr.hub.trigger("pricebar:optInAccept", this.data.showOfferInvert, this.type), this.data.comparePopup || mbr.hub.trigger("pricebar:show", this.type), mbr.iframeStorage.set("mbr.offerAccepted", !0).then(function() {
this._offerAccepted = !0, mbr.hub.trigger("script:offer", !0), this.el.className = this.el.className.replace(this._randomizer.randomize(this.classes.offerShown), "")
}.bind(this)), this._openUrl(null, !0), a.stopPropagation(), !1
},
_declineOffer: function(a) {
return mbr.hub.trigger("pricebar:optInDecline", this.data.showOfferInvert, this.type), mbr.iframeStorage.set("mbr.offerAccepted", !1).then(function() {
this.hidePopup(), mbr.hub.trigger("script:offer", !1)
}.bind(this)), a.stopPropagation(), !1
},
_closePopup: function(a) {
return mbr.hub.trigger("pricebar:close", this.type), this.hidePopup(), "avia" === this.type && mbr.cookie.set("flights_context_not_show", !0, null, "/"), a.stopPropagation(), !1
},
_openUrl: function(a, b) {
if (!this.data.showOffer || this._offerAccepted || b)
if (this.data.comparePopup) this._showShopsPopup(), this._showShopsTimeout = null;
else {
var c = !1;
if (a) {
var d = a.srcElement || a.target;
c = d.className === this._randomizer.randomize(this.classes.buttonGo)
}
mbr.hub.trigger("pricebar:click", this.type, c, this.type), window.open(this.data.url), b || (this._showShopsPopup(), this._showShopsTimeout = null)
} else {
var e = this._getElementById(this.ids.offerYesButton),
f = this._randomizer.randomize(" pb-btn-attention");
e.className += f, setTimeout(function() {
e.className = e.className.replace(f, "")
}, 300)
}
return a && a.stopPropagation(), !1
},
_toggleDisallowDomain: function(a) {
this._getElementById(this.ids.checkboxDoNotShow);
return this.domainDisallowed = !this.domainDisallowed, mbr.iframeStorage.set(mbr.tools.getHostname(document), this.domainDisallowed), this.domainDisallowed && mbr.hub.trigger("pricebar:disallowDomain", this.type), a.stopPropagation(), !1
},
_hidePopovers: function(a) {
var b = this._getElementById(this.ids.popoverInfo);
b.style.display = "none";
var c = this._getElementById(this.ids.popoverSettings);
c.style.display = "none";
var d = this._getShopsPopover();
d && (this.el.className = this.el.className.replace(" " + this._randomizer.randomize(this.classes.shoplist), ""));
var e = this._getElementById(this.ids.popoverThanks);
e && (e.style.display = "none");
var f = this._getElementById(this.ids.formError);
f && (f.className = f.className.replace(/form-error-shown/g, ""));
var g = a && (a.target || a.srcElement);
g && g.parentNode && g.parentNode === d && mbr.hub.trigger("shop:closeButtonClicked", !!this.data.shops)
},
_onBodyClick: function() {
this._hidePopovers()
},
_shopOpened: function(a) {
for (var b = a.target || a.srcElement; !b.className || -1 === b.className.indexOf(this._randomizer.randomize("shop-url"));) b = b.parentNode;
mbr.hub.trigger("shop:opened", b.getAttribute("data-type-shop"), b.getAttribute("data-type-offer"), !!this.data.shops), a.stopPropagation()
},
_initShowShops: function(a) {
a.srcElement || a.target;
this.data.autoShowShopList && !this._showingShopsPrevented && (this._hideShopsTimeout && (clearTimeout(this._hideShopsTimeout), this._hideShopsTimeout = null), this._showShopsTimeout = setTimeout(function() {
this._showShopsPopup()
}.bind(this), 0))
},
_cancelHideShops: function() {
this._hideShopsTimeout && clearTimeout(this._hideShopsTimeout)
},
_cancelShowShops: function() {
this.data.autoShowShopList && this._showShopsTimeout && (clearTimeout(this._showShopsTimeout), this._showShopsTimeout = null, this._isShopsPopupVisible() && (this._hideShopsTimeout = setTimeout(function() {
this._isShopsPopupVisible() && this._hideShopsPopup()
}.bind(this), 1e3)))
},
_onPopoverClick: function(a) {
return a.stopPropagation(), !1
},
_sendError: function(a) {
var b = a.srcElement || a.target;
if (b) {
var c = {
isAvito: this.data.isAvito,
isDefaultScript: this.data.isDefaultScript,
isMbrApplication: this.data.isMbrApplication,
appName: this.data.appName,
showOffer: this.data.showOffer,
showOfferInvert: this.data.showOfferInvert,
autoShowShopList: this.data.autoShowShopList,
viewModificators: this.data.viewModificators,
customLogo: this.data.customLogo
};
if (b.className.indexOf(this._randomizer.randomize("high-price")) > -1) {
if (this.data.bestOffers || this.data.isAvito) {
var d = b.nextSibling;
d && (d.style.display = d.style.display ? "" : "block")
} else mbr.feedback.trackHighPrice(document.URL, this.data.productName || this.data.routeText, this.data.priceText, this.extractMethod, this.serverResponse, this.original, c), this._showPopoverThanks();
mbr.hub.trigger("pricebar:errorClick", "HighPrice")
} else if (b.className.indexOf(this._randomizer.randomize("wrong-product")) > -1) mbr.feedback.trackWrongProduct(document.URL, this.data.productName || this.data.routeText, this.data.priceText, this.extractMethod, this.serverResponse, this.original, c), this._showPopoverThanks(), mbr.hub.trigger("pricebar:errorClick", "WrongOffer");
else if (b.className.indexOf(this._randomizer.randomize("unknown-error")) > -1) {
var e = b.nextSibling;
e.className += " error-shown", e.getElementsByTagName("textarea")[0].focus()
} else if (b.className.indexOf(this._randomizer.randomize("form-feedback")) > -1) {
var f = b.getElementsByTagName("textarea")[0];
f.value ? (mbr.feedback.trackUnknownError(f.value, document.URL, this.data.productName || this.data.routeText, this.data.priceText, this.extractMethod, this.serverResponse, this.original, c), this._showPopoverThanks(), f.value = "", mbr.hub.trigger("pricebar:errorClick", "OtherError")) : f.focus()
} else b.className.indexOf(this._randomizer.randomize("wrong-region")) > -1 && (d = b.nextSibling, d && (d.style.display = d.style.display ? "" : "block"), mbr.hub.trigger("pricebar:errorClick", "WrongRegion"))
}
a.preventDefault(), a.stopPropagation()
},
_showPopoverThanks: function() {
this._hidePopovers();
var a = this._getElementById(this.ids.popoverThanks);
a && (a.style.display = "block", setTimeout(function() {
a && "block" === a.style.display && (a.style.display = "none")
}, 5e3))
},
_preventShowShops: function() {
this._showingShopsPrevented = !0
},
_stopPreventingShowShops: function() {
this._showingShopsPrevented = !1
},
_carouselControlClick: function(a) {
var b = a.srcElement || a.target,
c = this._randomizer.randomize(this.classes.carouselDisabled);
if (b && -1 === b.className.indexOf(c)) {
var d = this._getElementById(this.ids.clothesCarousel);
if (d) {
var e = b.className.indexOf(this._randomizer.randomize(this.classes.carouselPrev)) > -1 ? "0px" : "-100%";
d.style.left = e;
var f = document.querySelectorAll(this._randomizer.randomize("." + this.classes.clothesCarouselControl));
[].slice.call(f).forEach(function(a) {
a.className = a.className.replace(c, "")
}), b.className += " " + c
}
}
},
_startPricebarHighlighting: function() {
var a = [];
mbr.view.nameElement && a.push(mbr.view.nameElement), mbr.view.priceElement && a.push(mbr.view.priceElement), this._addEventListener(a, "mouseenter", "_highlightPricebar"), this._addEventListener(a, "mouseleave", "_normalizePricebar")
},
_highlightPricebar: function() {
this.el.className += " hover"
},
_normalizePricebar: function() {
this.el.className = this.el.className.replace(/\shover/g, "")
}
};
mbr.PriceBar = mbr.PriceBar || function(a, b, c) {
return pricebar.clean(), pricebar.init(a, b, c)
}, mbr.view = mbr.view || {
_onProductOfferFound: function(a) {
mbr.pricebar = mbr.pricebar || new mbr.PriceBar("product", a)
},
_onAviaFound: function(a) {
mbr.pricebar = mbr.pricebar || new mbr.PriceBar("avia", a)
},
_onCouponsFound: function(a) {
mbr.couponsView && mbr.couponsView.showPopup(a)
},
init: function() {
mbr.hub.on("suggest:productOfferFound", this._onProductOfferFound, null, this), mbr.hub.on("suggest:aviaFound", this._onAviaFound, null, this), mbr.hub.on("coupons:found", this._onCouponsFound, null, this), mbr.hub.on("productPrice:found", function(a) {
mbr.view.priceElement = a
}), mbr.hub.on("productName:found", function(a) {
mbr.view.nameElement = a
})
}
}, mbr.require = {
_getScript: function(a, b) {
mbr.xhr.get(b, {}, function(b) {
this._evalScript(a, b)
}.bind(this))
},
_evalScript: function(name, script) {
if (script) {
var exports = {},
module = {
exports: exports
};
eval(script), mbr[name] = exports[name] || module.exports[name] || module.exports || exports, this._runNext()
} else this._errorCallback()
},
_runNext: function() {
if (0 === this._scripts.length) this._successCallback();
else {
var a = this._scripts.shift();
this._require(a.name, a.url)
}
},
_require: function(a, b) {
a in mbr ? this._successCallback() : this._getScript(a, b)
},
requireAll: function(a, b, c) {
var d = "",
e = mbr.tools.getPriceContextElement();
e && e.src && (d = e.src.replace(/[^\/]+$/, "")), this._scripts = a, this._successCallback = b, this._errorCallback = c, this._runNext()
}
};
var started = !1;
mbr.require.requireAll([{
name: "Mustache",
path: "mustache.js"
}, {
name: "Mediator",
path: "mediator.js"
}, {
name: "Promise",
path: "promiscuous.js"
}], function() {
"complete" === window.document.readyState || "interactive" === window.document.readyState ? start() : window.document.addEventListener ? (window.document.addEventListener("DOMContentLoaded", start, !1), window.addEventListener("load", start, !1)) : document.attachEvent && window.attachEvent("onload", start)
}, function() {
mbr.log("error of loading module")
})
}(function() {
return window.RegExp ? window : Function("return this")()
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment