Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * if google autosuggest or autocomplete is on, then the following code does not work properly when proxyMode is partiallyOn
- * Eg: if user types aol it immediately hits google server for autosuggest and mustEnableProxy function below returns true since,
- * google is in proxyEnabledSites list. This connects thru proxy for aol.com which is wrong.
- * Autosuggest is disabled in epic so no prob currently.
- */
- //infospace - inspcloud.com
- var proxyEnabledSites = ['infospace.com','google.com','google.co.in', 'inspcloud.com','dogpile.com', 'ixquick.com', 'google.co.uk', 'bing.com', 'duckduckgo.com', 'yandex','yandex.com','yandex.ru','yandex.rt', 'epicsearch.in', 'google.com', 'naver.com', 'naver.net','daum.net', 'daumcdn.net' ,'blekko.com', 'nate.com', 'baidu.com', 'ask.com', 'sogou.com', 'soso.com', 'so.com', 'sezname.cz', 'vinden.nl', 'onet.pl'];
- var proxyExceptionSites = ['mail.google.com', 'plus.google.com', 'play.google.com', 'news.google.com', 'maps.google.com', 'maps.static.com', 'mts1.google.com', 'mts0.google.com', 'googleusercontent.com', 'ytimg.com', 'drive.goo'];
- chrome.tabs.onCreated.addListener(function(d){
- chrome.privacy.services.proxy_page_action.get({}, function (d) {
- if(d.value==1)
- chrome.runtime.reload();
- });
- })
- function getRandomInt (min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- var rand = getRandomInt(0,100);
- rand = 54;
- /**
- * Returns a random integer between min and max
- * Using Math.round() will give you a non-uniform distribution!
- */
- // function getRandomInt (min, max) {
- // return Math.floor(Math.random() * (max - min + 1)) + min;
- // }
- var proxy_utils = {
- list_visisted: [],
- isTabvisited: function (d) {
- //Here we have to check for repeted url
- //if(this.list_visisted[i].tabId==d.tabId && this.list_visisted[i].url ==d.url)
- for (var i = 0; i < this.list_visisted.length; i++)
- if (this.list_visisted[i].tabId == d.tabId && this.list_visisted[i].enabled == false)
- return true;
- return false;
- },
- get_stripped_url: function (url) {
- var taburl;
- taburl += url;
- taburl = taburl.match(/^[\w-]+:\/*\[?([\w\.:-]+)\]?(?::\d+)?/)[1];
- return taburl;
- }
- };
- var proxy = {
- globalTabUrl: "",
- checkAndEnableProxy: function (obj) {
- if (!proxy_utils.isTabvisited(obj)) {
- obj.enabled = proxy.mustEnableProxy(obj.url);
- // if(obj.url=='google.co.in'){
- // alert("yes Im google.co.in")
- // }
- // alert("here " +obj.url)
- console.log('At mustEnableProxy' + obj.enabled)
- return obj.enabled
- }
- return false;
- },
- getEpicDomain: function (t) {
- mm = t.replace('||', '').replace('@@', '').replace('-', '').match(/^([\w]+:\/{0,2})?([\w]+\.|.*@)?([\w]+\.[\w]{2,3})(\/?)(.*)?(^)?/);
- if ((mm && mm[3]) != null) {
- return (mm && mm[3]);
- } else if ((mm && mm[3]) == null) {
- //Not a proper Domain
- //Goes to others
- }
- return "sorry";
- },
- mustEnableProxy: function (url) {
- for (var i = 0; i < proxyExceptionSites.length; i++) {
- if (url.indexOf(proxyExceptionSites[i]) != -1) {
- return false
- }
- }
- kf = proxy.getEpicDomain(url);
- if(kf.indexOf('yandex') > -1)
- return true;
- if (kf.indexOf('mail') > -1)
- return false;
- for (var i = 0; i < proxyEnabledSites.length; i++) {
- if (url.indexOf("google.com") > -1) {
- //IF http req is google/ gstatic and tab url is google.com
- //return true;
- var fk = proxy.getEpicDomain(proxy.globalTabUrl)
- // alert(fk)
- //console.log('uk check :'+ url)
- if (fk == "google.com" || fk == "gstatic.com" || fk == "google.co" || fk=="www.google.com") {
- return true;
- } //else {
- // return false;
- // }
- }
- console.log("fake car: "+kf)
- if (kf == proxyEnabledSites[i] ||kf == 'google.co' || fk == "google.com" || kf == "gstatic.com" )
- return true;
- }
- return false;
- },
- proxySettings: function (config) {
- chrome.proxy.settings.set({
- value: config,
- scope: 'regular'
- }, function () {});
- },
- connectThruProxy: function () {
- var config_faisla_in = {
- mode: "pac_script",
- pacScript: {
- data: "function FindProxyForURL(url, host) {\n" +
- "if(host=='duckduckgo.com' || host=='www.google.com' || host=='www.google.co.in' || host=='blekko.com' || host=='encrypted.google.com' || host=='www.bing.com'|| host=='live.com' || host=='infospace.com' || host=='www.google.co.uk' || host=='ixquick.com' || host=='dogpile.com' || host=='inspcloud.com' || host=='yandex.com' ||host=='yandex.ru' || host=='yandex.rt' || host=='naver.com' || host=='naver.net' || host=='nate.com'|| host=='baidu.com'|| host=='ask.com'|| host=='sogou.com'||host=='soso.com'|| host=='so.com'||host=='sezname.cz' || host=='vinden.nl' || host=='onet.pl') \n" +
- " return 'HTTPS www.faisla.in:44300;HTTPS faisla.net:44300;';\n" +
- "else if(host=='www.epicsearch.in') \n" +
- " return 'HTTPS www.faisla.in:44300; DIRECT;';\n" +
- "else return DIRECT\n" +
- "}"
- }
- };
- var config_epicbrowser_net = {
- mode: "pac_script",
- pacScript: {
- data: "function FindProxyForURL(url, host) {\n" +
- "if(host=='duckduckgo.com' || host=='www.google.com' || host=='www.google.co.in' || host=='blekko.com' || host=='encrypted.google.com' || host=='www.bing.com'|| host=='live.com' || host=='infospace.com' || host=='www.google.co.uk' || host=='ixquick.com' || host=='dogpile.com' || host=='inspcloud.com' || host=='yandex.com' ||host=='yandex.ru' || host=='yandex.rt' || host=='naver.com' || host=='naver.net' || host=='nate.com'|| host=='baidu.com'|| host=='ask.com'|| host=='sogou.com'||host=='soso.com'|| host=='so.com'||host=='sezname.cz' || host=='vinden.nl' || host=='onet.pl') \n" +
- " return 'HTTPS epicbrowser.net:44300;HTTPS faisla.net:44300;';\n" +
- "else if(host=='www.epicsearch.in') \n" +
- " return 'HTTPS epicbrowser.net:44300; DIRECT;';\n" +
- "else return DIRECT\n" +
- "}"
- }
- };
- var config_odecide_com = {
- mode: "pac_script",
- pacScript: {
- data: "function FindProxyForURL(url, host) {\n" +
- "if(host=='duckduckgo.com' || host=='www.google.com' || host=='www.google.co.in' || host=='blekko.com' || host=='encrypted.google.com' || host=='www.bing.com'|| host=='live.com' || host=='infospace.com' || host=='www.google.co.uk' || host=='ixquick.com' || host=='dogpile.com' || host=='inspcloud.com' || host=='yandex.com' ||host=='yandex.ru' || host=='yandex.rt' || host=='naver.com' || host=='naver.net' || host=='nate.com'|| host=='baidu.com'|| host=='ask.com'|| host=='sogou.com'||host=='soso.com'|| host=='so.com'||host=='sezname.cz' || host=='vinden.nl' || host=='onet.pl') \n" +
- " return 'HTTPS www.odecide.com:44300;HTTPS faisla.net:44300;';\n" +
- "else if(host=='www.epicsearch.in') \n" +
- " return 'HTTPS www.odecide.com:44300; DIRECT;';\n" +
- "else return DIRECT\n" +
- "}"
- }
- };
- if(rand <=50){
- proxy.proxySettings(config_epicbrowser_net);
- }else if(rand>50 && rand <=75){
- proxy.proxySettings(config_faisla_in);
- }else {
- proxy.proxySettings(config_odecide_com);
- }
- },
- connect_global: function () {
- var config_global_faisla_in = {
- mode: "pac_script",
- pacScript: {
- data: "function FindProxyForURL(url, host) {\n" +
- "if(host=='www.epicsearch.in') \n" +
- "return 'HTTPS www.faisla.in:44300;DIRECT;';\n" +
- " return 'HTTPS www.faisla.in:44300;HTTPS faisla.net:44300;';\n" +
- "}"
- }
- };
- var config_global_epicbrowser_net = {
- mode: "pac_script",
- pacScript: {
- data: "function FindProxyForURL(url, host) {\n" +
- "if(host=='www.epicsearch.in') \n" +
- "return 'HTTPS epicbrowser.net:44300;DIRECT;';\n" +
- " return 'HTTPS epicbrowser.net:44300;HTTPS faisla.net:44300;';\n" +
- "}"
- }
- };
- var config_global_odecide_com = {
- mode: "pac_script",
- pacScript: {
- data: "function FindProxyForURL(url, host) {\n" +
- "if(host=='www.epicsearch.in') \n" +
- "return 'HTTPS www.odecide.com:44300;DIRECT;';\n" +
- " return 'HTTPS www.odecide.com:44300;HTTPS faisla.net:44300;';\n" +
- "}"
- }
- };
- if(rand <=50){
- proxy.proxySettings(config_global_epicbrowser_net);
- }else if(rand>50 && rand <=75){
- proxy.proxySettings(config_global_faisla_in);
- }else {
- proxy.proxySettings(config_global_odecide_com);
- }
- },
- connectDirectly: function () {
- //alert('commect directly')
- proxy.proxySettings({
- mode: "direct"
- });
- }
- };
- var requestFilter = {
- urls: ["<all_urls>"]
- };
- setProxy = function (details) {
- var obj = {};
- obj.tabId = details.tabId;
- obj.url = proxy_utils.get_stripped_url(details.url)
- obj.enabled = false;
- if (localStorage.getItem('proxyMode') == "on") {
- proxy.connect_global();
- } else if (proxy.checkAndEnableProxy(obj)) {
- proxy.connectThruProxy();
- } else
- proxy.connectDirectly();
- return {};
- };
- setUserAgent = function (details) {
- var headers = details.requestHeaders;
- blockingResponse = {};
- //console.log(a.hostname);
- if (localStorage.getItem('proxyMode') == "on" || proxy.mustEnableProxy(details.url)) {
- for (var i = 0; i < headers.length; ++i) {
- if (headers[i].name == 'User-Agent') {
- if(details.url.indexOf('netflix.com') != -1){
- headers[i].value ="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1771.0 Safari/537.36"
- }
- blockingResponse.requestHeaders = headers;
- return blockingResponse;
- }
- //if(headers[i].name=="X-Forwarded-For")
- // alert(headers[i].value)
- }
- }
- blockingResponse.requestHeaders = headers;
- return blockingResponse;
- };
- chrome.webRequest.onBeforeSendHeaders.addListener(setUserAgent, requestFilter, ['requestHeaders', 'blocking']);
- chrome.webRequest.onBeforeRequest.addListener(setProxy, requestFilter, ['blocking']);
- var ProxyIcon = {
- setPageAction: function (tabId, title, iconPath) {
- chrome.pageAction.setTitle({
- tabId: tabId,
- title: title
- })
- chrome.pageAction.setIcon({
- tabId: tabId,
- path: iconPath
- })
- chrome.pageAction.show(tabId)
- },
- setProxyIcon: function (tabId) {
- chrome.tabs.get(tabId, function (tab) {
- try {
- var tabUrl = tab.url;
- proxy.globalTabUrl = tab.url;
- var proxyEnabledSite = false;
- for (var i = 0; i < proxyEnabledSites.length; i++) {
- if (tabUrl.indexOf(proxyEnabledSites[i]) > -1) {
- proxyEnabledSite = true;
- break;
- }
- }
- if (tabUrl.indexOf('mail') > -1) {
- proxyEnabledSite = false;
- // break;
- }
- for (var i = 0; i < proxyExceptionSites.length; i++) {
- //console.log(proxyExceptionSites[i]+"<------------>"+tabUrl);
- if (tabUrl.indexOf(proxyExceptionSites[i]) != -1)
- proxyEnabledSite = false
- }
- if (proxyEnabledSite)
- ProxyIcon.setPageAction(tabId, "this site is being accessed via proxy. Click to enable proxy globally", "images/proxyon.png")
- else
- ProxyIcon.setPageAction(tabId, "Click to enable proxy globally", "images/ic24_off.png")
- } catch (e) {}
- });
- },
- onTabFocus: function (tabId) {
- if (localStorage.getItem('proxyMode') == 'on') {
- ProxyIcon.setPageAction(tabId, "Click to disable proxy globally", "images/ic24_on.png")
- return;
- }
- ProxyIcon.setProxyIcon(tabId);
- },
- toggleProxyAndIcon: function (tabId) {
- if (localStorage.getItem('proxyMode') == 'on') {
- localStorage.setItem('proxyMode', 'partiallyOn')
- ProxyIcon.setProxyIcon(tabId);
- } else {
- ProxyIcon.setPageAction(tabId, "Click to disable proxy globally", "images/ic24_on.png")
- localStorage.setItem('proxyMode', 'on')
- }
- }
- };
- chrome.tabs.onActivated.addListener(function (info) {
- setTimeout(function () {
- ProxyIcon.onTabFocus(info.tabId);
- }, 500);
- //ProxyIcon.onTabFocus(info.tabId);
- });
- chrome.tabs.onUpdated.addListener(function (tabId) {
- ProxyIcon.onTabFocus(tabId);
- for (var i = 0; i < proxy_utils.list_visisted.length; i++)
- if (proxy_utils.list_visisted[i].tabId == tabId.id)
- proxy_utils.list_visisted[i].enabled = false;
- });
- chrome.pageAction.onClicked.addListener(function (tab) {
- ProxyIcon.toggleProxyAndIcon(tab.id);
- });
- chrome.tabs.query({
- active: true
- }, function (tabs) {
- ProxyIcon.onTabFocus(tabs[0].id)
- });
Advertisement
Add Comment
Please, Sign In to add comment