Guest User

Untitled

a guest
Jan 30th, 2015
2,966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.53 KB | None | 0 0
  1. /*
  2. * if google autosuggest or autocomplete is on, then the following code does not work properly when proxyMode is partiallyOn
  3. * Eg: if user types aol it immediately hits google server for autosuggest and mustEnableProxy function below returns true since,
  4. * google is in proxyEnabledSites list. This connects thru proxy for aol.com which is wrong.
  5. * Autosuggest is disabled in epic so no prob currently.
  6. */
  7.  
  8.  
  9. //infospace - inspcloud.com
  10. 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'];
  11. 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'];
  12.  
  13. chrome.tabs.onCreated.addListener(function(d){
  14.  
  15. chrome.privacy.services.proxy_page_action.get({}, function (d) {
  16. if(d.value==1)
  17. chrome.runtime.reload();
  18. });
  19.  
  20. })
  21.  
  22. function getRandomInt (min, max) {
  23. return Math.floor(Math.random() * (max - min + 1)) + min;
  24. }
  25.  
  26. var rand = getRandomInt(0,100);
  27. rand = 54;
  28.  
  29. /**
  30. * Returns a random integer between min and max
  31. * Using Math.round() will give you a non-uniform distribution!
  32. */
  33. // function getRandomInt (min, max) {
  34. // return Math.floor(Math.random() * (max - min + 1)) + min;
  35. // }
  36.  
  37. var proxy_utils = {
  38. list_visisted: [],
  39. isTabvisited: function (d) {
  40. //Here we have to check for repeted url
  41. //if(this.list_visisted[i].tabId==d.tabId && this.list_visisted[i].url ==d.url)
  42. for (var i = 0; i < this.list_visisted.length; i++)
  43. if (this.list_visisted[i].tabId == d.tabId && this.list_visisted[i].enabled == false)
  44. return true;
  45. return false;
  46.  
  47. },
  48. get_stripped_url: function (url) {
  49. var taburl;
  50. taburl += url;
  51. taburl = taburl.match(/^[\w-]+:\/*\[?([\w\.:-]+)\]?(?::\d+)?/)[1];
  52. return taburl;
  53. }
  54.  
  55. };
  56.  
  57. var proxy = {
  58. globalTabUrl: "",
  59. checkAndEnableProxy: function (obj) {
  60. if (!proxy_utils.isTabvisited(obj)) {
  61.  
  62. obj.enabled = proxy.mustEnableProxy(obj.url);
  63. // if(obj.url=='google.co.in'){
  64. // alert("yes Im google.co.in")
  65. // }
  66. // alert("here " +obj.url)
  67. console.log('At mustEnableProxy' + obj.enabled)
  68. return obj.enabled
  69. }
  70. return false;
  71. },
  72.  
  73. getEpicDomain: function (t) {
  74. mm = t.replace('||', '').replace('@@', '').replace('-', '').match(/^([\w]+:\/{0,2})?([\w]+\.|.*@)?([\w]+\.[\w]{2,3})(\/?)(.*)?(^)?/);
  75. if ((mm && mm[3]) != null) {
  76.  
  77.  
  78. return (mm && mm[3]);
  79. } else if ((mm && mm[3]) == null) {
  80. //Not a proper Domain
  81. //Goes to others
  82. }
  83. return "sorry";
  84. },
  85.  
  86. mustEnableProxy: function (url) {
  87.  
  88. for (var i = 0; i < proxyExceptionSites.length; i++) {
  89.  
  90. if (url.indexOf(proxyExceptionSites[i]) != -1) {
  91.  
  92. return false
  93. }
  94.  
  95. }
  96.  
  97.  
  98.  
  99. kf = proxy.getEpicDomain(url);
  100.  
  101. if(kf.indexOf('yandex') > -1)
  102. return true;
  103.  
  104.  
  105. if (kf.indexOf('mail') > -1)
  106. return false;
  107. for (var i = 0; i < proxyEnabledSites.length; i++) {
  108. if (url.indexOf("google.com") > -1) {
  109. //IF http req is google/ gstatic and tab url is google.com
  110. //return true;
  111.  
  112. var fk = proxy.getEpicDomain(proxy.globalTabUrl)
  113. // alert(fk)
  114. //console.log('uk check :'+ url)
  115. if (fk == "google.com" || fk == "gstatic.com" || fk == "google.co" || fk=="www.google.com") {
  116. return true;
  117. } //else {
  118. // return false;
  119. // }
  120.  
  121. }
  122. console.log("fake car: "+kf)
  123. if (kf == proxyEnabledSites[i] ||kf == 'google.co' || fk == "google.com" || kf == "gstatic.com" )
  124. return true;
  125.  
  126.  
  127. }
  128.  
  129. return false;
  130. },
  131.  
  132. proxySettings: function (config) {
  133. chrome.proxy.settings.set({
  134. value: config,
  135. scope: 'regular'
  136. }, function () {});
  137. },
  138.  
  139. connectThruProxy: function () {
  140.  
  141.  
  142.  
  143. var config_faisla_in = {
  144. mode: "pac_script",
  145. pacScript: {
  146. data: "function FindProxyForURL(url, host) {\n" +
  147.  
  148. "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" +
  149. " return 'HTTPS www.faisla.in:44300;HTTPS faisla.net:44300;';\n" +
  150. "else if(host=='www.epicsearch.in') \n" +
  151. " return 'HTTPS www.faisla.in:44300; DIRECT;';\n" +
  152. "else return DIRECT\n" +
  153. "}"
  154. }
  155. };
  156.  
  157.  
  158. var config_epicbrowser_net = {
  159. mode: "pac_script",
  160. pacScript: {
  161. data: "function FindProxyForURL(url, host) {\n" +
  162.  
  163. "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" +
  164. " return 'HTTPS epicbrowser.net:44300;HTTPS faisla.net:44300;';\n" +
  165. "else if(host=='www.epicsearch.in') \n" +
  166. " return 'HTTPS epicbrowser.net:44300; DIRECT;';\n" +
  167. "else return DIRECT\n" +
  168. "}"
  169. }
  170. };
  171.  
  172. var config_odecide_com = {
  173. mode: "pac_script",
  174. pacScript: {
  175. data: "function FindProxyForURL(url, host) {\n" +
  176.  
  177. "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" +
  178. " return 'HTTPS www.odecide.com:44300;HTTPS faisla.net:44300;';\n" +
  179. "else if(host=='www.epicsearch.in') \n" +
  180. " return 'HTTPS www.odecide.com:44300; DIRECT;';\n" +
  181. "else return DIRECT\n" +
  182. "}"
  183. }
  184. };
  185.  
  186.  
  187.  
  188.  
  189. if(rand <=50){
  190.  
  191. proxy.proxySettings(config_epicbrowser_net);
  192.  
  193. }else if(rand>50 && rand <=75){
  194.  
  195. proxy.proxySettings(config_faisla_in);
  196.  
  197. }else {
  198.  
  199. proxy.proxySettings(config_odecide_com);
  200.  
  201. }
  202.  
  203. },
  204.  
  205. connect_global: function () {
  206.  
  207.  
  208. var config_global_faisla_in = {
  209. mode: "pac_script",
  210. pacScript: {
  211. data: "function FindProxyForURL(url, host) {\n" +
  212. "if(host=='www.epicsearch.in') \n" +
  213. "return 'HTTPS www.faisla.in:44300;DIRECT;';\n" +
  214. " return 'HTTPS www.faisla.in:44300;HTTPS faisla.net:44300;';\n" +
  215.  
  216. "}"
  217. }
  218. };
  219.  
  220.  
  221.  
  222.  
  223. var config_global_epicbrowser_net = {
  224. mode: "pac_script",
  225. pacScript: {
  226. data: "function FindProxyForURL(url, host) {\n" +
  227. "if(host=='www.epicsearch.in') \n" +
  228. "return 'HTTPS epicbrowser.net:44300;DIRECT;';\n" +
  229. " return 'HTTPS epicbrowser.net:44300;HTTPS faisla.net:44300;';\n" +
  230.  
  231. "}"
  232. }
  233. };
  234.  
  235. var config_global_odecide_com = {
  236. mode: "pac_script",
  237. pacScript: {
  238. data: "function FindProxyForURL(url, host) {\n" +
  239. "if(host=='www.epicsearch.in') \n" +
  240. "return 'HTTPS www.odecide.com:44300;DIRECT;';\n" +
  241. " return 'HTTPS www.odecide.com:44300;HTTPS faisla.net:44300;';\n" +
  242.  
  243. "}"
  244. }
  245. };
  246.  
  247.  
  248. if(rand <=50){
  249.  
  250. proxy.proxySettings(config_global_epicbrowser_net);
  251.  
  252. }else if(rand>50 && rand <=75){
  253.  
  254. proxy.proxySettings(config_global_faisla_in);
  255.  
  256. }else {
  257.  
  258. proxy.proxySettings(config_global_odecide_com);
  259.  
  260. }
  261. },
  262.  
  263. connectDirectly: function () {
  264. //alert('commect directly')
  265. proxy.proxySettings({
  266. mode: "direct"
  267. });
  268. }
  269. };
  270.  
  271. var requestFilter = {
  272. urls: ["<all_urls>"]
  273. };
  274.  
  275. setProxy = function (details) {
  276. var obj = {};
  277. obj.tabId = details.tabId;
  278. obj.url = proxy_utils.get_stripped_url(details.url)
  279. obj.enabled = false;
  280. if (localStorage.getItem('proxyMode') == "on") {
  281. proxy.connect_global();
  282. } else if (proxy.checkAndEnableProxy(obj)) {
  283. proxy.connectThruProxy();
  284. } else
  285. proxy.connectDirectly();
  286. return {};
  287. };
  288.  
  289. setUserAgent = function (details) {
  290. var headers = details.requestHeaders;
  291. blockingResponse = {};
  292.  
  293. //console.log(a.hostname);
  294. if (localStorage.getItem('proxyMode') == "on" || proxy.mustEnableProxy(details.url)) {
  295.  
  296. for (var i = 0; i < headers.length; ++i) {
  297.  
  298. if (headers[i].name == 'User-Agent') {
  299. if(details.url.indexOf('netflix.com') != -1){
  300.  
  301. 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"
  302. }
  303.  
  304. blockingResponse.requestHeaders = headers;
  305. return blockingResponse;
  306.  
  307. }
  308.  
  309. //if(headers[i].name=="X-Forwarded-For")
  310. // alert(headers[i].value)
  311.  
  312. }
  313. }
  314.  
  315.  
  316.  
  317.  
  318. blockingResponse.requestHeaders = headers;
  319. return blockingResponse;
  320. };
  321.  
  322.  
  323. chrome.webRequest.onBeforeSendHeaders.addListener(setUserAgent, requestFilter, ['requestHeaders', 'blocking']);
  324. chrome.webRequest.onBeforeRequest.addListener(setProxy, requestFilter, ['blocking']);
  325.  
  326. var ProxyIcon = {
  327. setPageAction: function (tabId, title, iconPath) {
  328. chrome.pageAction.setTitle({
  329. tabId: tabId,
  330. title: title
  331. })
  332. chrome.pageAction.setIcon({
  333. tabId: tabId,
  334. path: iconPath
  335. })
  336. chrome.pageAction.show(tabId)
  337. },
  338.  
  339. setProxyIcon: function (tabId) {
  340. chrome.tabs.get(tabId, function (tab) {
  341. try {
  342. var tabUrl = tab.url;
  343. proxy.globalTabUrl = tab.url;
  344. var proxyEnabledSite = false;
  345. for (var i = 0; i < proxyEnabledSites.length; i++) {
  346. if (tabUrl.indexOf(proxyEnabledSites[i]) > -1) {
  347. proxyEnabledSite = true;
  348. break;
  349. }
  350. }
  351. if (tabUrl.indexOf('mail') > -1) {
  352. proxyEnabledSite = false;
  353. // break;
  354. }
  355.  
  356. for (var i = 0; i < proxyExceptionSites.length; i++) {
  357. //console.log(proxyExceptionSites[i]+"<------------>"+tabUrl);
  358. if (tabUrl.indexOf(proxyExceptionSites[i]) != -1)
  359. proxyEnabledSite = false
  360. }
  361.  
  362.  
  363. if (proxyEnabledSite)
  364. ProxyIcon.setPageAction(tabId, "this site is being accessed via proxy. Click to enable proxy globally", "images/proxyon.png")
  365. else
  366. ProxyIcon.setPageAction(tabId, "Click to enable proxy globally", "images/ic24_off.png")
  367. } catch (e) {}
  368. });
  369. },
  370.  
  371. onTabFocus: function (tabId) {
  372. if (localStorage.getItem('proxyMode') == 'on') {
  373. ProxyIcon.setPageAction(tabId, "Click to disable proxy globally", "images/ic24_on.png")
  374. return;
  375. }
  376. ProxyIcon.setProxyIcon(tabId);
  377. },
  378.  
  379. toggleProxyAndIcon: function (tabId) {
  380. if (localStorage.getItem('proxyMode') == 'on') {
  381. localStorage.setItem('proxyMode', 'partiallyOn')
  382. ProxyIcon.setProxyIcon(tabId);
  383. } else {
  384. ProxyIcon.setPageAction(tabId, "Click to disable proxy globally", "images/ic24_on.png")
  385. localStorage.setItem('proxyMode', 'on')
  386. }
  387. }
  388. };
  389.  
  390.  
  391. chrome.tabs.onActivated.addListener(function (info) {
  392. setTimeout(function () {
  393. ProxyIcon.onTabFocus(info.tabId);
  394. }, 500);
  395. //ProxyIcon.onTabFocus(info.tabId);
  396. });
  397.  
  398. chrome.tabs.onUpdated.addListener(function (tabId) {
  399. ProxyIcon.onTabFocus(tabId);
  400. for (var i = 0; i < proxy_utils.list_visisted.length; i++)
  401. if (proxy_utils.list_visisted[i].tabId == tabId.id)
  402. proxy_utils.list_visisted[i].enabled = false;
  403. });
  404.  
  405. chrome.pageAction.onClicked.addListener(function (tab) {
  406. ProxyIcon.toggleProxyAndIcon(tab.id);
  407. });
  408.  
  409. chrome.tabs.query({
  410. active: true
  411. }, function (tabs) {
  412.  
  413. ProxyIcon.onTabFocus(tabs[0].id)
  414. });
Advertisement
Add Comment
Please, Sign In to add comment