Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
!function (a) {
function b() {
}
function c(a) {
wdgt.observer.notify("yandex.clckStatistics.send", {pid: 12, cid: 72213, action: "on" + i.hostId + "." + a, common: !0})
}
var d = {google: {input_name: "q", offset: 0}, mail: {input_name: "q", offset: 0}, bing: {input_name: "q", offset: 0}, yahoo: {input_name: "p", offset: 160}};
if (!a.altsearch) {
a.altsearch = !0;
const e = "1003";
var f = function () {
};
b("injected!");
var g = "includes/altsearch", h = {getLoadDataFn: function (a, b, c, d) {
return function () {
a[b] ? d() : a[c](function (c) {
a[b] = c, d()
})
}
}, getScrollMaxY: function () {
var b = a.innerHeight ? a.innerHeight : document.body.clientHeight;
return yWithScroll = a.innerHeight && a.scrollMaxY ? a.innerHeight + a.scrollMaxY : document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight, yWithScroll - b
}}, i = {visible: !1, hostId: null, query: null, localeData: null, prefData: null, needUpdate: !1, configure: function (a, b) {
(this.hostId !== a || this.query !== b) && (this.hostId = a, this.query = b, this.needUpdate = !0)
}, show: function () {
if (this.hostId && this.query) {
var b = !1;
if (this.host || (this.render(), b = !0), this.visible || (this.host.style.display = "", this.fpanel.style.display = "", this.visible = !0, b = !0), b && a.scrollTo(a.scrollX, a.scrollY), this.needUpdate) {
var c = h.getLoadDataFn(this, "localeData", "onNeedLocaleData", this.setContent.bind(this)), d = h.getLoadDataFn(this, "prefData", "onNeedPrefData", c);
d()
}
}
}, render: function () {
var b = document.createElement("div"), c = b.createShadowRoot ? b.createShadowRoot() : b.webkitCreateShadowRoot();
c.resetStyleInheritance = !0;
var e = document.createElement("style"), f = g + "/altsearch.css";
e.innerText = '@import url("' + chrome.extension.getURL(f) + '");', c.appendChild(e);
var h = document.createElement("div");
h.classList.add("panel"), h.classList.add("panel-fixed"), c.appendChild(h);
var i = document.createElement("span");
i.style.backgroundImage = "url(" + chrome.extension.getURL(g + "/close.png") + ")", i.classList.add("icon"), i.classList.add("close"), i.addEventListener("click", this.closeClick.bind(this)), h.appendChild(i);
var j = document.createElement("span");
j.style.backgroundImage = "url(" + chrome.extension.getURL(g + "/settings.png") + ")", j.classList.add("icon"), j.addEventListener("click", this.settingsClick.bind(this)), h.appendChild(j);
var k = document.createElement("div");
k.classList.add("text-content"), h.appendChild(k);
var l = document.createElement("span");
k.appendChild(l);
var m, n = d[this.hostId];
if (n && (m = document.querySelector("input[name='" + n.input_name + "']"))) {
var o = m.getBoundingClientRect().left + a.pageXOffset + n.offset, p = k.style;
p.textAlign = "left", p.paddingLeft = o + "px"
}
var q = document.createElement("span");
k.appendChild(q), document.body.appendChild(b);
var r = document.createElement("div");
r.style.minHeight = "35px", document.body.appendChild(r), this.host = b, this.root = c, this.panel = h, this.label = l, this.engines = q, this.fpanel = r, this.onRender()
}, setContent: function () {
var a = ("" + this.query).replace(/[\n\t]/g, " "), b = 20;
a.length > b && (a = a.substring(0, b) + "...");
var c = document.createElement("div");
c.innerText = a, this.label.innerHTML = this.localeData.label.replace("[0]", "<b>" + c.innerHTML + "</b>"), this.engines.innerHTML = "", this.localeData.engines.forEach(function (a) {
if (a.id !== this.hostId) {
var b = document.createElement("a");
b.classList.add("engine"), b.setAttribute("target", "_blank"), b.setAttribute("data-engine", a.id);
var c = a.query.replace("{searchTerms}", encodeURIComponent(this.query));
"yandex" === a.id && (c = c.replace("{clid}", this.prefData.clid10 + "-" + e)), b.setAttribute("href", c), b.innerText = this.localeData.names[a.id], b.addEventListener("click", this.onEngineClick.bind(this)), this.engines.appendChild(b)
}
}.bind(this)), this.needUpdate = !1
}, hide: function () {
this.visible = !1, this.host && this.fpanel && (this.host.style.display = "none", this.fpanel.style.display = "none")
}, remove: function () {
this.hide(), this.host.parentNode.removeChild(this.host), this.fpanel.parentNode.removeChild(this.fpanel), this.host = null, this.fpanel = null, this.configure(null, null)
}, closeClick: function () {
this.beforeCloseClick(), this.remove(), this.onCloseClick()
}, settingsClick: function () {
this.onSettingsClick()
}, onNeedLocaleData: f, onNeedPrefData: f, onRender: f, onEngineClick: f, onSettingsClick: f, onCloseClick: f, beforeCloseClick: f}, j = {urlRe: /^https?:\/\/(?:www\.)?(go\.(mail)\.ru|(bing)\.com|(?:[a-z]{2}\.)?search\.(yahoo)\.com|(google)(?:\.com)?\.[a-z]{2,3})\/(?:search|webhp)?[;#&?]/i, phraseRe: null, enabled: !1, init: function () {
this.bind = {check: this.check.bind(this)}, this.setEnabled(!0)
}, setEnabled: function (b) {
if (b !== this.enabled) {
this.enabled = b;
var c = b ? "addEventListener" : "removeEventListener";
a[c]("hashchange", this.bind.check, !1)
}
}, check: function () {
var b = a.location.href, c = b.match(this.urlRe), e = String(c).split(",").splice(2).join("").toLowerCase(), f = a.location.search;
"google" === e && (a.location.hash && /[#&]q=/.test("#" + a.location.hash) && (f = "#" + a.location.hash), /[\?&#]tbm=/.test(f) && (e = ""));
var g;
if (e) {
if (!this.phraseRe) {
var h = d[e].input_name;
this.phraseRe = new RegExp("[?&#]" + h + "=([^#&?]*)")
}
var i = f.match(this.phraseRe);
if (i && (g = decodeURIComponent(i[1].replace(/\+/g, " "))), "google" === e && !i && (this.advPhraseRe = this.advPhraseRe || new RegExp("[?&#]as_q="), f.match(this.advPhraseRe))) {
var j = document.querySelector('input[name="q"]');
j && j.value && (g = j.value)
}
}
this.onChange(e || null, g)
}, onChange: f}, k = {enabled: !1, init: function () {
this.bind = {check: this.check.bind(this)}
}, setEnabled: function (b) {
if (this.enabled !== b) {
this.enabled = b;
var c = b ? "addEventListener" : "removeEventListener";
a[c]("scroll", this.bind.check), a[c]("resize", this.bind.check)
}
}, isBottom: function () {
var b = h.getScrollMaxY();
return a.scrollY >= .95 * b
}, check: function () {
this.isBottom() && this.onScrolledBottom()
}, onScrolledBottom: f};
j.onChange = function (a, c) {
b("onChange", a, c), a && c ? (i.configure(a, c), i.hide(), setTimeout(function () {
k.isBottom() && i.show()
}, 2e3), k.setEnabled(!0)) : (i.hide(), k.setEnabled(!1))
}, i.onNeedLocaleData = function (a) {
b("onNeedLocaleData"), wdgt.observer.observe("wdgt.i18n.retrieved", function (b, c, d) {
var e = {};
if (d && "altsearch" === d.sign) {
var f = [];
for (var g in c.messages["altsearch.engines"])f.push(c.messages["altsearch.engines"][g]);
f.sort(function (a, b) {
return a.action > b.action ? 1 : -1
}), e = {label: c.messages["altsearch.panel-text"], engines: f, names: c.messages["altsearch.engine-names"]}
}
a(e)
}.bind(this), {once: !0}), wdgt.observer.notify("wdgt.i18n.retrieve", ["altsearch.panel-text", "altsearch.engines", "altsearch.engine-names"], {sign: "altsearch"})
}, i.onNeedPrefData = function (a) {
wdgt.observer.observe("wdgt.preferences.getted", function (b, c) {
"yandex.statistics.clid.10" === c.name && a({clid10: c.value})
}.bind(this), {once: !0}), wdgt.observer.notify("wdgt.preferences.get", {name: "yandex.statistics.clid.10"})
}, i.onEngineClick = function (a) {
var d = a.target.getAttribute("data-engine");
c(d), b("onEngineClick")
}, i.beforeCloseClick = function () {
c("close")
}, i.onCloseClick = function () {
j.setEnabled(!1), k.setEnabled(!1)
}, i.onSettingsClick = function () {
wdgt.observer.notify("wdgt.browser.navigate", {url: chrome.extension.getURL("options/options.html")}), c("set"), b("onSettingsClick")
}, i.onRender = function () {
c("show"), b("onRender")
}, k.onScrolledBottom = function () {
b("onScrolledBottom"), i.show()
}, j.init(), k.init(), j.check()
}
}(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment