You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

abp.js 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /* eslint-disable */
  2. // Was generated by gfwlist2pac in precise mode
  3. // https://github.com/clowwindy/gfwlist2pac
  4. // 2019-10-06: More 'javascript' way to interaction with main program
  5. // 2019-02-08: Updated to support shadowsocks-windows user rules.
  6. var proxy = __PROXY__;
  7. var userrules = __USERRULES__;
  8. var rules = __RULES__;
  9. /*
  10. * This file is part of Adblock Plus <http://adblockplus.org/>,
  11. * Copyright (C) 2006-2014 Eyeo GmbH
  12. *
  13. * Adblock Plus is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 3 as
  15. * published by the Free Software Foundation.
  16. *
  17. * Adblock Plus is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. function createDict()
  26. {
  27. var result = {};
  28. result.__proto__ = null;
  29. return result;
  30. }
  31. function getOwnPropertyDescriptor(obj, key)
  32. {
  33. if (obj.hasOwnProperty(key))
  34. {
  35. return obj[key];
  36. }
  37. return null;
  38. }
  39. function extend(subclass, superclass, definition)
  40. {
  41. if (Object.__proto__)
  42. {
  43. definition.__proto__ = superclass.prototype;
  44. subclass.prototype = definition;
  45. }
  46. else
  47. {
  48. var tmpclass = function(){}, ret;
  49. tmpclass.prototype = superclass.prototype;
  50. subclass.prototype = new tmpclass();
  51. subclass.prototype.constructor = superclass;
  52. for (var i in definition)
  53. {
  54. if (definition.hasOwnProperty(i))
  55. {
  56. subclass.prototype[i] = definition[i];
  57. }
  58. }
  59. }
  60. }
  61. function Filter(text)
  62. {
  63. this.text = text;
  64. this.subscriptions = [];
  65. }
  66. Filter.prototype = {
  67. text: null,
  68. subscriptions: null,
  69. toString: function()
  70. {
  71. return this.text;
  72. }
  73. };
  74. Filter.knownFilters = createDict();
  75. Filter.elemhideRegExp = /^([^\/\*\|\@"!]*?)#(\@)?(?:([\w\-]+|\*)((?:\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\))*)|#([^{}]+))$/;
  76. Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?:=[^,\s]+)?)*)?$/;
  77. Filter.optionsRegExp = /\$(~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?:=[^,\s]+)?)*)$/;
  78. Filter.fromText = function(text)
  79. {
  80. if (text in Filter.knownFilters)
  81. {
  82. return Filter.knownFilters[text];
  83. }
  84. var ret;
  85. if (text.charAt(0) == "!")
  86. {
  87. ret = new CommentFilter(text);
  88. }
  89. else
  90. {
  91. ret = RegExpFilter.fromText(text);
  92. }
  93. Filter.knownFilters[ret.text] = ret;
  94. return ret;
  95. };
  96. function InvalidFilter(text, reason)
  97. {
  98. Filter.call(this, text);
  99. this.reason = reason;
  100. }
  101. extend(InvalidFilter, Filter, {
  102. reason: null
  103. });
  104. function CommentFilter(text)
  105. {
  106. Filter.call(this, text);
  107. }
  108. extend(CommentFilter, Filter, {
  109. });
  110. function ActiveFilter(text, domains)
  111. {
  112. Filter.call(this, text);
  113. this.domainSource = domains;
  114. }
  115. extend(ActiveFilter, Filter, {
  116. domainSource: null,
  117. domainSeparator: null,
  118. ignoreTrailingDot: true,
  119. domainSourceIsUpperCase: false,
  120. getDomains: function()
  121. {
  122. var prop = getOwnPropertyDescriptor(this, "domains");
  123. if (prop)
  124. {
  125. return prop;
  126. }
  127. var domains = null;
  128. if (this.domainSource)
  129. {
  130. var source = this.domainSource;
  131. if (!this.domainSourceIsUpperCase)
  132. {
  133. source = source.toUpperCase();
  134. }
  135. var list = source.split(this.domainSeparator);
  136. if (list.length == 1 && (list[0]).charAt(0) != "~")
  137. {
  138. domains = createDict();
  139. domains[""] = false;
  140. if (this.ignoreTrailingDot)
  141. {
  142. list[0] = list[0].replace(/\.+$/, "");
  143. }
  144. domains[list[0]] = true;
  145. }
  146. else
  147. {
  148. var hasIncludes = false;
  149. for (var i = 0; i < list.length; i++)
  150. {
  151. var domain = list[i];
  152. if (this.ignoreTrailingDot)
  153. {
  154. domain = domain.replace(/\.+$/, "");
  155. }
  156. if (domain == "")
  157. {
  158. continue;
  159. }
  160. var include;
  161. if (domain.charAt(0) == "~")
  162. {
  163. include = false;
  164. domain = domain.substr(1);
  165. }
  166. else
  167. {
  168. include = true;
  169. hasIncludes = true;
  170. }
  171. if (!domains)
  172. {
  173. domains = createDict();
  174. }
  175. domains[domain] = include;
  176. }
  177. domains[""] = !hasIncludes;
  178. }
  179. this.domainSource = null;
  180. }
  181. return this.domains;
  182. },
  183. sitekeys: null,
  184. isActiveOnDomain: function(docDomain, sitekey)
  185. {
  186. if (this.getSitekeys() && (!sitekey || this.getSitekeys().indexOf(sitekey.toUpperCase()) < 0))
  187. {
  188. return false;
  189. }
  190. if (!this.getDomains())
  191. {
  192. return true;
  193. }
  194. if (!docDomain)
  195. {
  196. return this.getDomains()[""];
  197. }
  198. if (this.ignoreTrailingDot)
  199. {
  200. docDomain = docDomain.replace(/\.+$/, "");
  201. }
  202. docDomain = docDomain.toUpperCase();
  203. while (true)
  204. {
  205. if (docDomain in this.getDomains())
  206. {
  207. return this.domains[docDomain];
  208. }
  209. var nextDot = docDomain.indexOf(".");
  210. if (nextDot < 0)
  211. {
  212. break;
  213. }
  214. docDomain = docDomain.substr(nextDot + 1);
  215. }
  216. return this.domains[""];
  217. },
  218. isActiveOnlyOnDomain: function(docDomain)
  219. {
  220. if (!docDomain || !this.getDomains() || this.getDomains()[""])
  221. {
  222. return false;
  223. }
  224. if (this.ignoreTrailingDot)
  225. {
  226. docDomain = docDomain.replace(/\.+$/, "");
  227. }
  228. docDomain = docDomain.toUpperCase();
  229. for (var domain in this.getDomains())
  230. {
  231. if (this.domains[domain] && domain != docDomain && (domain.length <= docDomain.length || domain.indexOf("." + docDomain) != domain.length - docDomain.length - 1))
  232. {
  233. return false;
  234. }
  235. }
  236. return true;
  237. }
  238. });
  239. function RegExpFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys)
  240. {
  241. ActiveFilter.call(this, text, domains, sitekeys);
  242. if (contentType != null)
  243. {
  244. this.contentType = contentType;
  245. }
  246. if (matchCase)
  247. {
  248. this.matchCase = matchCase;
  249. }
  250. if (thirdParty != null)
  251. {
  252. this.thirdParty = thirdParty;
  253. }
  254. if (sitekeys != null)
  255. {
  256. this.sitekeySource = sitekeys;
  257. }
  258. if (regexpSource.length >= 2 && regexpSource.charAt(0) == "/" && regexpSource.charAt(regexpSource.length - 1) == "/")
  259. {
  260. var regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), this.matchCase ? "" : "i");
  261. this.regexp = regexp;
  262. }
  263. else
  264. {
  265. this.regexpSource = regexpSource;
  266. }
  267. }
  268. extend(RegExpFilter, ActiveFilter, {
  269. domainSourceIsUpperCase: true,
  270. length: 1,
  271. domainSeparator: "|",
  272. regexpSource: null,
  273. getRegexp: function()
  274. {
  275. var prop = getOwnPropertyDescriptor(this, "regexp");
  276. if (prop)
  277. {
  278. return prop;
  279. }
  280. var source = this.regexpSource.replace(/\*+/g, "*").replace(/\^\|$/, "^").replace(/\W/g, "\\$&").replace(/\\\*/g, ".*").replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F]|$)").replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?").replace(/^\\\|/, "^").replace(/\\\|$/, "$").replace(/^(\.\*)/, "").replace(/(\.\*)$/, "");
  281. var regexp = new RegExp(source, this.matchCase ? "" : "i");
  282. this.regexp = regexp;
  283. return regexp;
  284. },
  285. contentType: 2147483647,
  286. matchCase: false,
  287. thirdParty: null,
  288. sitekeySource: null,
  289. getSitekeys: function()
  290. {
  291. var prop = getOwnPropertyDescriptor(this, "sitekeys");
  292. if (prop)
  293. {
  294. return prop;
  295. }
  296. var sitekeys = null;
  297. if (this.sitekeySource)
  298. {
  299. sitekeys = this.sitekeySource.split("|");
  300. this.sitekeySource = null;
  301. }
  302. this.sitekeys = sitekeys;
  303. return this.sitekeys;
  304. },
  305. matches: function(location, contentType, docDomain, thirdParty, sitekey)
  306. {
  307. if (this.getRegexp().test(location) && this.isActiveOnDomain(docDomain, sitekey))
  308. {
  309. return true;
  310. }
  311. return false;
  312. }
  313. });
  314. RegExpFilter.prototype["0"] = "#this";
  315. RegExpFilter.fromText = function(text)
  316. {
  317. var blocking = true;
  318. var origText = text;
  319. if (text.indexOf("@@") == 0)
  320. {
  321. blocking = false;
  322. text = text.substr(2);
  323. }
  324. var contentType = null;
  325. var matchCase = null;
  326. var domains = null;
  327. var sitekeys = null;
  328. var thirdParty = null;
  329. var collapse = null;
  330. var options;
  331. var match = text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null;
  332. if (match)
  333. {
  334. options = match[1].toUpperCase().split(",");
  335. text = match.input.substr(0, match.index);
  336. for (var _loopIndex6 = 0; _loopIndex6 < options.length; ++_loopIndex6)
  337. {
  338. var option = options[_loopIndex6];
  339. var value = null;
  340. var separatorIndex = option.indexOf("=");
  341. if (separatorIndex >= 0)
  342. {
  343. value = option.substr(separatorIndex + 1);
  344. option = option.substr(0, separatorIndex);
  345. }
  346. option = option.replace(/-/, "_");
  347. if (option in RegExpFilter.typeMap)
  348. {
  349. if (contentType == null)
  350. {
  351. contentType = 0;
  352. }
  353. contentType |= RegExpFilter.typeMap[option];
  354. }
  355. else if (option.charAt(0) == "~" && option.substr(1) in RegExpFilter.typeMap)
  356. {
  357. if (contentType == null)
  358. {
  359. contentType = RegExpFilter.prototype.contentType;
  360. }
  361. contentType &= ~RegExpFilter.typeMap[option.substr(1)];
  362. }
  363. else if (option == "MATCH_CASE")
  364. {
  365. matchCase = true;
  366. }
  367. else if (option == "~MATCH_CASE")
  368. {
  369. matchCase = false;
  370. }
  371. else if (option == "DOMAIN" && typeof value != "undefined")
  372. {
  373. domains = value;
  374. }
  375. else if (option == "THIRD_PARTY")
  376. {
  377. thirdParty = true;
  378. }
  379. else if (option == "~THIRD_PARTY")
  380. {
  381. thirdParty = false;
  382. }
  383. else if (option == "COLLAPSE")
  384. {
  385. collapse = true;
  386. }
  387. else if (option == "~COLLAPSE")
  388. {
  389. collapse = false;
  390. }
  391. else if (option == "SITEKEY" && typeof value != "undefined")
  392. {
  393. sitekeys = value;
  394. }
  395. else
  396. {
  397. return new InvalidFilter(origText, "Unknown option " + option.toLowerCase());
  398. }
  399. }
  400. }
  401. if (!blocking && (contentType == null || contentType & RegExpFilter.typeMap.DOCUMENT) && (!options || options.indexOf("DOCUMENT") < 0) && !/^\|?[\w\-]+:/.test(text))
  402. {
  403. if (contentType == null)
  404. {
  405. contentType = RegExpFilter.prototype.contentType;
  406. }
  407. contentType &= ~RegExpFilter.typeMap.DOCUMENT;
  408. }
  409. try
  410. {
  411. if (blocking)
  412. {
  413. return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse);
  414. }
  415. else
  416. {
  417. return new WhitelistFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys);
  418. }
  419. }
  420. catch (e)
  421. {
  422. return new InvalidFilter(origText, e);
  423. }
  424. };
  425. RegExpFilter.typeMap = {
  426. OTHER: 1,
  427. SCRIPT: 2,
  428. IMAGE: 4,
  429. STYLESHEET: 8,
  430. OBJECT: 16,
  431. SUBDOCUMENT: 32,
  432. DOCUMENT: 64,
  433. XBL: 1,
  434. PING: 1,
  435. XMLHTTPREQUEST: 2048,
  436. OBJECT_SUBREQUEST: 4096,
  437. DTD: 1,
  438. MEDIA: 16384,
  439. FONT: 32768,
  440. BACKGROUND: 4,
  441. POPUP: 268435456,
  442. ELEMHIDE: 1073741824
  443. };
  444. RegExpFilter.prototype.contentType &= ~ (RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP);
  445. function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys, collapse)
  446. {
  447. RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys);
  448. this.collapse = collapse;
  449. }
  450. extend(BlockingFilter, RegExpFilter, {
  451. collapse: null
  452. });
  453. function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys)
  454. {
  455. RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys);
  456. }
  457. extend(WhitelistFilter, RegExpFilter, {
  458. });
  459. function Matcher()
  460. {
  461. this.clear();
  462. }
  463. Matcher.prototype = {
  464. filterByKeyword: null,
  465. keywordByFilter: null,
  466. clear: function()
  467. {
  468. this.filterByKeyword = createDict();
  469. this.keywordByFilter = createDict();
  470. },
  471. add: function(filter)
  472. {
  473. if (filter.text in this.keywordByFilter)
  474. {
  475. return;
  476. }
  477. var keyword = this.findKeyword(filter);
  478. var oldEntry = this.filterByKeyword[keyword];
  479. if (typeof oldEntry == "undefined")
  480. {
  481. this.filterByKeyword[keyword] = filter;
  482. }
  483. else if (oldEntry.length == 1)
  484. {
  485. this.filterByKeyword[keyword] = [oldEntry, filter];
  486. }
  487. else
  488. {
  489. oldEntry.push(filter);
  490. }
  491. this.keywordByFilter[filter.text] = keyword;
  492. },
  493. remove: function(filter)
  494. {
  495. if (!(filter.text in this.keywordByFilter))
  496. {
  497. return;
  498. }
  499. var keyword = this.keywordByFilter[filter.text];
  500. var list = this.filterByKeyword[keyword];
  501. if (list.length <= 1)
  502. {
  503. delete this.filterByKeyword[keyword];
  504. }
  505. else
  506. {
  507. var index = list.indexOf(filter);
  508. if (index >= 0)
  509. {
  510. list.splice(index, 1);
  511. if (list.length == 1)
  512. {
  513. this.filterByKeyword[keyword] = list[0];
  514. }
  515. }
  516. }
  517. delete this.keywordByFilter[filter.text];
  518. },
  519. findKeyword: function(filter)
  520. {
  521. var result = "";
  522. var text = filter.text;
  523. if (Filter.regexpRegExp.test(text))
  524. {
  525. return result;
  526. }
  527. var match = Filter.optionsRegExp.exec(text);
  528. if (match)
  529. {
  530. text = match.input.substr(0, match.index);
  531. }
  532. if (text.substr(0, 2) == "@@")
  533. {
  534. text = text.substr(2);
  535. }
  536. var candidates = text.toLowerCase().match(/[^a-z0-9%*][a-z0-9%]{3,}(?=[^a-z0-9%*])/g);
  537. if (!candidates)
  538. {
  539. return result;
  540. }
  541. var hash = this.filterByKeyword;
  542. var resultCount = 16777215;
  543. var resultLength = 0;
  544. for (var i = 0, l = candidates.length; i < l; i++)
  545. {
  546. var candidate = candidates[i].substr(1);
  547. var count = candidate in hash ? hash[candidate].length : 0;
  548. if (count < resultCount || count == resultCount && candidate.length > resultLength)
  549. {
  550. result = candidate;
  551. resultCount = count;
  552. resultLength = candidate.length;
  553. }
  554. }
  555. return result;
  556. },
  557. hasFilter: function(filter)
  558. {
  559. return filter.text in this.keywordByFilter;
  560. },
  561. getKeywordForFilter: function(filter)
  562. {
  563. if (filter.text in this.keywordByFilter)
  564. {
  565. return this.keywordByFilter[filter.text];
  566. }
  567. else
  568. {
  569. return null;
  570. }
  571. },
  572. _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdParty, sitekey)
  573. {
  574. var list = this.filterByKeyword[keyword];
  575. for (var i = 0; i < list.length; i++)
  576. {
  577. var filter = list[i];
  578. if (filter == "#this")
  579. {
  580. filter = list;
  581. }
  582. if (filter.matches(location, contentType, docDomain, thirdParty, sitekey))
  583. {
  584. return filter;
  585. }
  586. }
  587. return null;
  588. },
  589. matchesAny: function(location, contentType, docDomain, thirdParty, sitekey)
  590. {
  591. var candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);
  592. if (candidates === null)
  593. {
  594. candidates = [];
  595. }
  596. candidates.push("");
  597. for (var i = 0, l = candidates.length; i < l; i++)
  598. {
  599. var substr = candidates[i];
  600. if (substr in this.filterByKeyword)
  601. {
  602. var result = this._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);
  603. if (result)
  604. {
  605. return result;
  606. }
  607. }
  608. }
  609. return null;
  610. }
  611. };
  612. function CombinedMatcher()
  613. {
  614. this.blacklist = new Matcher();
  615. this.whitelist = new Matcher();
  616. this.resultCache = createDict();
  617. }
  618. CombinedMatcher.maxCacheEntries = 1000;
  619. CombinedMatcher.prototype = {
  620. blacklist: null,
  621. whitelist: null,
  622. resultCache: null,
  623. cacheEntries: 0,
  624. clear: function()
  625. {
  626. this.blacklist.clear();
  627. this.whitelist.clear();
  628. this.resultCache = createDict();
  629. this.cacheEntries = 0;
  630. },
  631. add: function(filter)
  632. {
  633. if (filter instanceof WhitelistFilter)
  634. {
  635. this.whitelist.add(filter);
  636. }
  637. else
  638. {
  639. this.blacklist.add(filter);
  640. }
  641. if (this.cacheEntries > 0)
  642. {
  643. this.resultCache = createDict();
  644. this.cacheEntries = 0;
  645. }
  646. },
  647. remove: function(filter)
  648. {
  649. if (filter instanceof WhitelistFilter)
  650. {
  651. this.whitelist.remove(filter);
  652. }
  653. else
  654. {
  655. this.blacklist.remove(filter);
  656. }
  657. if (this.cacheEntries > 0)
  658. {
  659. this.resultCache = createDict();
  660. this.cacheEntries = 0;
  661. }
  662. },
  663. findKeyword: function(filter)
  664. {
  665. if (filter instanceof WhitelistFilter)
  666. {
  667. return this.whitelist.findKeyword(filter);
  668. }
  669. else
  670. {
  671. return this.blacklist.findKeyword(filter);
  672. }
  673. },
  674. hasFilter: function(filter)
  675. {
  676. if (filter instanceof WhitelistFilter)
  677. {
  678. return this.whitelist.hasFilter(filter);
  679. }
  680. else
  681. {
  682. return this.blacklist.hasFilter(filter);
  683. }
  684. },
  685. getKeywordForFilter: function(filter)
  686. {
  687. if (filter instanceof WhitelistFilter)
  688. {
  689. return this.whitelist.getKeywordForFilter(filter);
  690. }
  691. else
  692. {
  693. return this.blacklist.getKeywordForFilter(filter);
  694. }
  695. },
  696. isSlowFilter: function(filter)
  697. {
  698. var matcher = filter instanceof WhitelistFilter ? this.whitelist : this.blacklist;
  699. if (matcher.hasFilter(filter))
  700. {
  701. return !matcher.getKeywordForFilter(filter);
  702. }
  703. else
  704. {
  705. return !matcher.findKeyword(filter);
  706. }
  707. },
  708. matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sitekey)
  709. {
  710. var candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);
  711. if (candidates === null)
  712. {
  713. candidates = [];
  714. }
  715. candidates.push("");
  716. var blacklistHit = null;
  717. for (var i = 0, l = candidates.length; i < l; i++)
  718. {
  719. var substr = candidates[i];
  720. if (substr in this.whitelist.filterByKeyword)
  721. {
  722. var result = this.whitelist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);
  723. if (result)
  724. {
  725. return result;
  726. }
  727. }
  728. if (substr in this.blacklist.filterByKeyword && blacklistHit === null)
  729. {
  730. blacklistHit = this.blacklist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);
  731. }
  732. }
  733. return blacklistHit;
  734. },
  735. matchesAny: function(location, docDomain)
  736. {
  737. var key = location + " " + docDomain + " ";
  738. if (key in this.resultCache)
  739. {
  740. return this.resultCache[key];
  741. }
  742. var result = this.matchesAnyInternal(location, 0, docDomain, null, null);
  743. if (this.cacheEntries >= CombinedMatcher.maxCacheEntries)
  744. {
  745. this.resultCache = createDict();
  746. this.cacheEntries = 0;
  747. }
  748. this.resultCache[key] = result;
  749. this.cacheEntries++;
  750. return result;
  751. }
  752. };
  753. var userrulesMatcher = new CombinedMatcher();
  754. var defaultMatcher = new CombinedMatcher();
  755. var direct = 'DIRECT;';
  756. for (var i = 0; i < userrules.length; i++) {
  757. userrulesMatcher.add(Filter.fromText(userrules[i]));
  758. }
  759. for (var i = 0; i < rules.length; i++) {
  760. defaultMatcher.add(Filter.fromText(rules[i]));
  761. }
  762. function FindProxyForURL(url, host) {
  763. if (userrulesMatcher.matchesAny(url, host) instanceof BlockingFilter) {
  764. return proxy;
  765. }
  766. if (userrulesMatcher.matchesAny(url, host) instanceof WhitelistFilter) {
  767. return direct;
  768. }
  769. if (defaultMatcher.matchesAny(url, host) instanceof BlockingFilter) {
  770. return proxy;
  771. }
  772. return direct;
  773. }