linkify-plus-plus-core

A JavaScript library for linkification stuff. Used by linkify-plus-plus.

当前为 2017-03-04 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/27630/178765/linkify-plus-plus-core.js

  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.linkifyPlusPlusCore = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. var _require = require("./lib/url-matcher"),
  3. UrlMatcher = _require.UrlMatcher,
  4. _require2 = require("./lib/linkifier"),
  5. INVALID_TAGS = _require2.INVALID_TAGS,
  6. Linkifier = _require2.Linkifier;
  7.  
  8. module.exports = {
  9. UrlMatcher,
  10. Linkifier,
  11. INVALID_TAGS
  12. };
  13.  
  14. },{"./lib/linkifier":2,"./lib/url-matcher":4}],2:[function(require,module,exports){
  15. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16.  
  17. /* eslint-env browser */
  18. var INVALID_TAGS = {
  19. A: true,
  20. NOSCRIPT: true,
  21. OPTION: true,
  22. SCRIPT: true,
  23. STYLE: true,
  24. TEXTAREA: true,
  25. SVG: true,
  26. CANVAS: true,
  27. BUTTON: true,
  28. SELECT: true,
  29. TEMPLATE: true,
  30. METER: true,
  31. PROGRESS: true,
  32. MATH: true,
  33. TIME: true
  34. };
  35.  
  36. var doc = document,
  37. time = Date.now;
  38.  
  39. var Pos = function () {
  40. function Pos(container, offset) {
  41. var i = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  42.  
  43. _classCallCheck(this, Pos);
  44.  
  45. this.container = container;
  46. this.offset = offset;
  47. this.i = i;
  48. }
  49.  
  50. Pos.prototype.add = function add(change) {
  51. var cont = this.container,
  52. offset = this.offset;
  53.  
  54. this.i += change;
  55.  
  56. // If the container is #text.parentNode
  57. if (cont.childNodes.length) {
  58. cont = cont.childNodes[offset];
  59. offset = 0;
  60. }
  61.  
  62. // If the container is #text
  63. while (cont) {
  64. if (cont.nodeType == 3) {
  65. if (!cont.LEN) {
  66. cont.LEN = cont.nodeValue.length;
  67. }
  68. if (offset + change <= cont.LEN) {
  69. this.container = cont;
  70. this.offset = offset + change;
  71. return;
  72. }
  73. change = offset + change - cont.LEN;
  74. offset = 0;
  75. }
  76. cont = cont.nextSibling;
  77. }
  78. };
  79.  
  80. Pos.prototype.moveTo = function moveTo(offset) {
  81. this.add(offset - this.i);
  82. };
  83.  
  84. return Pos;
  85. }();
  86.  
  87. function* generateRanges(node, filter) {
  88. // Generate linkified ranges.
  89. var walker = doc.createTreeWalker(node, NodeFilter.SHOW_TEXT + NodeFilter.SHOW_ELEMENT, filter),
  90. start,
  91. end,
  92. current,
  93. range;
  94.  
  95. end = start = walker.nextNode();
  96. if (!start) {
  97. return;
  98. }
  99. range = doc.createRange();
  100. range.setStartBefore(start);
  101. while (current = walker.nextNode()) {
  102. if (end.nextSibling == current) {
  103. end = current;
  104. continue;
  105. }
  106. range.setEndAfter(end);
  107. yield range;
  108.  
  109. end = start = current;
  110. range.setStartBefore(start);
  111. }
  112. range.setEndAfter(end);
  113. yield range;
  114. }
  115.  
  116. function createFilter(customValidator) {
  117. return {
  118. acceptNode: function (node) {
  119. if (customValidator && !customValidator(node)) {
  120. return NodeFilter.FILTER_REJECT;
  121. }
  122. if (INVALID_TAGS[node.nodeName]) {
  123. return NodeFilter.FILTER_REJECT;
  124. }
  125. if (node.nodeName == "WBR") {
  126. return NodeFilter.FILTER_ACCEPT;
  127. }
  128. if (node.nodeType == 3) {
  129. return NodeFilter.FILTER_ACCEPT;
  130. }
  131. return NodeFilter.FILTER_SKIP;
  132. }
  133. };
  134. }
  135.  
  136. function cloneContents(range) {
  137. if (range.startContainer == range.endContainer) {
  138. return doc.createTextNode(range.toString());
  139. }
  140. return range.cloneContents();
  141. }
  142.  
  143. function* generateChunks(_ref) {
  144. var ranges = _ref.ranges,
  145. matcher = _ref.matcher,
  146. _ref$newTab = _ref.newTab,
  147. newTab = _ref$newTab === undefined ? true : _ref$newTab,
  148. _ref$embedImage = _ref.embedImage,
  149. embedImage = _ref$embedImage === undefined ? true : _ref$embedImage;
  150.  
  151. for (var range of ranges) {
  152. var frag = null,
  153. pos = null,
  154. text = range.toString(),
  155. textRange = null;
  156. for (var result of matcher.match(text)) {
  157. if (!frag) {
  158. frag = doc.createDocumentFragment();
  159. pos = new Pos(range.startContainer, range.startOffset);
  160. textRange = range.cloneRange();
  161. }
  162. // clone text
  163. pos.moveTo(result.start);
  164. textRange.setEnd(pos.container, pos.offset);
  165. frag.appendChild(cloneContents(textRange));
  166.  
  167. // clone link
  168. textRange.collapse();
  169. pos.moveTo(result.end);
  170. textRange.setEnd(pos.container, pos.offset);
  171.  
  172. var link = doc.createElement("a");
  173. link.href = result.url;
  174. link.title = "Linkify Plus Plus";
  175. link.className = "linkifyplus";
  176. if (newTab) {
  177. link.target = "_blank";
  178. }
  179. var child;
  180. if (embedImage && /^[^?#]+\.(?:jpg|png|gif|jpeg)(?:$|[?#])/i.test(result.url)) {
  181. child = new Image();
  182. child.src = result.url;
  183. child.alt = result.text;
  184. } else {
  185. child = cloneContents(textRange);
  186. }
  187. link.appendChild(child);
  188.  
  189. textRange.collapse();
  190.  
  191. frag.appendChild(link);
  192. }
  193. if (pos) {
  194. pos.moveTo(text.length);
  195. textRange.setEnd(pos.container, pos.offset);
  196. frag.appendChild(cloneContents(textRange));
  197.  
  198. range.deleteContents();
  199. range.insertNode(frag);
  200. }
  201. yield;
  202. }
  203. }
  204.  
  205. var Linkifier = function () {
  206. function Linkifier(options) {
  207. _classCallCheck(this, Linkifier);
  208.  
  209. this.options = options;
  210. }
  211.  
  212. Linkifier.prototype.linkify = function linkify(root) {
  213. return new Promise((resolve, reject) => {
  214. var _options = this.options,
  215. matcher = _options.matcher,
  216. validator = _options.validator,
  217. _options$maxRunTime = _options.maxRunTime,
  218. maxRunTime = _options$maxRunTime === undefined ? 100 : _options$maxRunTime,
  219. _options$timeout = _options.timeout,
  220. timeout = _options$timeout === undefined ? 10000 : _options$timeout,
  221. newTab = _options.newTab,
  222. embedImage = _options.embedImage,
  223. ranges = generateRanges(root, createFilter(validator)),
  224. chunks = generateChunks({ matcher, newTab, embedImage, ranges }),
  225. linkifyStart = time();
  226.  
  227.  
  228. function next() {
  229. var nextStart = time(),
  230. now;
  231.  
  232. do {
  233. if (chunks.next().done) {
  234. resolve(time() - linkifyStart);
  235. return;
  236. }
  237. } while ((now = time()) - nextStart < maxRunTime);
  238.  
  239. if (now - linkifyStart > timeout) {
  240. reject(new Error(`max execution time exceeded: ${now - linkifyStart}, on ${root}`));
  241. return;
  242. }
  243.  
  244. setTimeout(next);
  245. }
  246.  
  247. setTimeout(next);
  248. });
  249. };
  250.  
  251. return Linkifier;
  252. }();
  253.  
  254. module.exports = {
  255. INVALID_TAGS,
  256. Linkifier
  257. };
  258.  
  259. },{}],3:[function(require,module,exports){
  260. module.exports={
  261. "maxLength": 22,
  262. "chars": "セール佛山慈善集团在线한국八卦موقعবাংল公司网站移动我爱你москвақзнлйтрбгеファッションストア삼성சிங்கபூர商标城дию新闻家電中文信国國భారత్ලංකාクラウドભારતभारत店संगठन餐厅络у香港食品飞利浦台湾灣手机الجزئرنیتبپکسدية澳門닷컴شكგე构健康ไทยфみんなελ世界書籍址넷コム息صط广东இலைநதயாհայ加坡ف",
  263. "table": {
  264. "aarp": true,
  265. "abb": true,
  266. "abbott": true,
  267. "abc": true,
  268. "abogado": true,
  269. "ac": true,
  270. "academy": true,
  271. "accenture": true,
  272. "accountant": true,
  273. "accountants": true,
  274. "aco": true,
  275. "active": true,
  276. "actor": true,
  277. "ad": true,
  278. "adult": true,
  279. "ae": true,
  280. "aeg": true,
  281. "aero": true,
  282. "af": true,
  283. "afamilycompany": true,
  284. "afl": true,
  285. "africa": true,
  286. "ag": true,
  287. "agency": true,
  288. "ai": true,
  289. "aig": true,
  290. "airbus": true,
  291. "airforce": true,
  292. "al": true,
  293. "alsace": true,
  294. "am": true,
  295. "amica": true,
  296. "amsterdam": true,
  297. "ao": true,
  298. "apartments": true,
  299. "aq": true,
  300. "aquarelle": true,
  301. "ar": true,
  302. "archi": true,
  303. "army": true,
  304. "art": true,
  305. "arte": true,
  306. "as": true,
  307. "asia": true,
  308. "associates": true,
  309. "at": true,
  310. "attorney": true,
  311. "au": true,
  312. "auction": true,
  313. "audi": true,
  314. "audio": true,
  315. "auto": true,
  316. "autos": true,
  317. "aw": true,
  318. "aws": true,
  319. "ax": true,
  320. "axa": true,
  321. "az": true,
  322. "azure": true,
  323. "ba": true,
  324. "baby": true,
  325. "baidu": true,
  326. "band": true,
  327. "bank": true,
  328. "bar": true,
  329. "barcelona": true,
  330. "barclaycard": true,
  331. "barclays": true,
  332. "bargains": true,
  333. "bayern": true,
  334. "bb": true,
  335. "bbva": true,
  336. "bd": true,
  337. "be": true,
  338. "beer": true,
  339. "bentley": true,
  340. "berlin": true,
  341. "best": true,
  342. "bet": true,
  343. "bf": true,
  344. "bg": true,
  345. "bh": true,
  346. "bi": true,
  347. "bible": true,
  348. "bid": true,
  349. "bike": true,
  350. "bing": true,
  351. "bingo": true,
  352. "bio": true,
  353. "biz": true,
  354. "bj": true,
  355. "black": true,
  356. "blackfriday": true,
  357. "blanco": true,
  358. "blog": true,
  359. "bloomberg": true,
  360. "blue": true,
  361. "bm": true,
  362. "bms": true,
  363. "bmw": true,
  364. "bn": true,
  365. "bnpparibas": true,
  366. "bo": true,
  367. "boats": true,
  368. "bosch": true,
  369. "boutique": true,
  370. "br": true,
  371. "bradesco": true,
  372. "bridgestone": true,
  373. "broadway": true,
  374. "broker": true,
  375. "brother": true,
  376. "brussels": true,
  377. "bs": true,
  378. "bt": true,
  379. "bugatti": true,
  380. "build": true,
  381. "builders": true,
  382. "business": true,
  383. "buzz": true,
  384. "bw": true,
  385. "by": true,
  386. "bz": true,
  387. "bzh": true,
  388. "ca": true,
  389. "cab": true,
  390. "cafe": true,
  391. "cam": true,
  392. "camera": true,
  393. "camp": true,
  394. "cancerresearch": true,
  395. "canon": true,
  396. "capetown": true,
  397. "capital": true,
  398. "car": true,
  399. "cards": true,
  400. "care": true,
  401. "career": true,
  402. "careers": true,
  403. "cars": true,
  404. "casa": true,
  405. "cash": true,
  406. "casino": true,
  407. "cat": true,
  408. "catering": true,
  409. "cba": true,
  410. "cc": true,
  411. "cd": true,
  412. "center": true,
  413. "ceo": true,
  414. "cern": true,
  415. "cf": true,
  416. "cfa": true,
  417. "cfd": true,
  418. "cg": true,
  419. "ch": true,
  420. "chanel": true,
  421. "chase": true,
  422. "chat": true,
  423. "cheap": true,
  424. "christmas": true,
  425. "church": true,
  426. "ci": true,
  427. "cisco": true,
  428. "citic": true,
  429. "city": true,
  430. "ck": true,
  431. "cl": true,
  432. "claims": true,
  433. "cleaning": true,
  434. "click": true,
  435. "clinic": true,
  436. "clothing": true,
  437. "cloud": true,
  438. "club": true,
  439. "clubmed": true,
  440. "cm": true,
  441. "cn": true,
  442. "co": true,
  443. "coach": true,
  444. "codes": true,
  445. "coffee": true,
  446. "college": true,
  447. "cologne": true,
  448. "com": true,
  449. "community": true,
  450. "company": true,
  451. "computer": true,
  452. "condos": true,
  453. "construction": true,
  454. "consulting": true,
  455. "contractors": true,
  456. "cooking": true,
  457. "cool": true,
  458. "coop": true,
  459. "corsica": true,
  460. "country": true,
  461. "coupons": true,
  462. "courses": true,
  463. "cr": true,
  464. "credit": true,
  465. "creditcard": true,
  466. "cricket": true,
  467. "crown": true,
  468. "crs": true,
  469. "cruises": true,
  470. "csc": true,
  471. "cu": true,
  472. "cuisinella": true,
  473. "cv": true,
  474. "cw": true,
  475. "cx": true,
  476. "cy": true,
  477. "cymru": true,
  478. "cz": true,
  479. "dabur": true,
  480. "dance": true,
  481. "date": true,
  482. "dating": true,
  483. "de": true,
  484. "deals": true,
  485. "degree": true,
  486. "delivery": true,
  487. "dell": true,
  488. "deloitte": true,
  489. "democrat": true,
  490. "dental": true,
  491. "dentist": true,
  492. "desi": true,
  493. "design": true,
  494. "dhl": true,
  495. "diamonds": true,
  496. "diet": true,
  497. "digital": true,
  498. "direct": true,
  499. "directory": true,
  500. "discount": true,
  501. "dj": true,
  502. "dk": true,
  503. "dm": true,
  504. "dnp": true,
  505. "do": true,
  506. "doctor": true,
  507. "dog": true,
  508. "domains": true,
  509. "download": true,
  510. "dubai": true,
  511. "durban": true,
  512. "dvag": true,
  513. "dz": true,
  514. "earth": true,
  515. "ec": true,
  516. "eco": true,
  517. "edeka": true,
  518. "edu": true,
  519. "education": true,
  520. "ee": true,
  521. "eg": true,
  522. "email": true,
  523. "emerck": true,
  524. "energy": true,
  525. "engineer": true,
  526. "engineering": true,
  527. "enterprises": true,
  528. "equipment": true,
  529. "er": true,
  530. "erni": true,
  531. "es": true,
  532. "estate": true,
  533. "et": true,
  534. "eu": true,
  535. "eurovision": true,
  536. "eus": true,
  537. "events": true,
  538. "everbank": true,
  539. "exchange": true,
  540. "expert": true,
  541. "exposed": true,
  542. "express": true,
  543. "extraspace": true,
  544. "fage": true,
  545. "fail": true,
  546. "fairwinds": true,
  547. "faith": true,
  548. "family": true,
  549. "fan": true,
  550. "fans": true,
  551. "farm": true,
  552. "fashion": true,
  553. "feedback": true,
  554. "ferrero": true,
  555. "fi": true,
  556. "film": true,
  557. "finance": true,
  558. "financial": true,
  559. "firmdale": true,
  560. "fish": true,
  561. "fishing": true,
  562. "fit": true,
  563. "fitness": true,
  564. "fj": true,
  565. "fk": true,
  566. "flights": true,
  567. "florist": true,
  568. "flowers": true,
  569. "fm": true,
  570. "fo": true,
  571. "foo": true,
  572. "football": true,
  573. "forex": true,
  574. "forsale": true,
  575. "forum": true,
  576. "foundation": true,
  577. "fox": true,
  578. "fr": true,
  579. "fresenius": true,
  580. "frl": true,
  581. "frogans": true,
  582. "fun": true,
  583. "fund": true,
  584. "furniture": true,
  585. "futbol": true,
  586. "fyi": true,
  587. "ga": true,
  588. "gal": true,
  589. "gallery": true,
  590. "game": true,
  591. "games": true,
  592. "garden": true,
  593. "gd": true,
  594. "gdn": true,
  595. "ge": true,
  596. "gent": true,
  597. "gf": true,
  598. "gg": true,
  599. "gh": true,
  600. "gi": true,
  601. "gift": true,
  602. "gifts": true,
  603. "gives": true,
  604. "gl": true,
  605. "glass": true,
  606. "global": true,
  607. "globo": true,
  608. "gm": true,
  609. "gmail": true,
  610. "gmbh": true,
  611. "gmo": true,
  612. "gn": true,
  613. "gold": true,
  614. "golf": true,
  615. "goo": true,
  616. "goog": true,
  617. "google": true,
  618. "gop": true,
  619. "gov": true,
  620. "gp": true,
  621. "gq": true,
  622. "gr": true,
  623. "graphics": true,
  624. "gratis": true,
  625. "green": true,
  626. "gripe": true,
  627. "group": true,
  628. "gs": true,
  629. "gt": true,
  630. "gu": true,
  631. "gucci": true,
  632. "guide": true,
  633. "guitars": true,
  634. "guru": true,
  635. "gw": true,
  636. "gy": true,
  637. "hamburg": true,
  638. "haus": true,
  639. "healthcare": true,
  640. "help": true,
  641. "here": true,
  642. "hiphop": true,
  643. "hitachi": true,
  644. "hiv": true,
  645. "hk": true,
  646. "hm": true,
  647. "hn": true,
  648. "hockey": true,
  649. "holdings": true,
  650. "holiday": true,
  651. "homes": true,
  652. "horse": true,
  653. "host": true,
  654. "hosting": true,
  655. "hoteles": true,
  656. "hotmail": true,
  657. "house": true,
  658. "how": true,
  659. "hr": true,
  660. "ht": true,
  661. "hu": true,
  662. "ice": true,
  663. "id": true,
  664. "ie": true,
  665. "ifm": true,
  666. "ikano": true,
  667. "il": true,
  668. "im": true,
  669. "immo": true,
  670. "immobilien": true,
  671. "in": true,
  672. "industries": true,
  673. "info": true,
  674. "ink": true,
  675. "institute": true,
  676. "insurance": true,
  677. "insure": true,
  678. "int": true,
  679. "international": true,
  680. "investments": true,
  681. "io": true,
  682. "ipiranga": true,
  683. "iq": true,
  684. "ir": true,
  685. "irish": true,
  686. "is": true,
  687. "iselect": true,
  688. "ist": true,
  689. "istanbul": true,
  690. "it": true,
  691. "itv": true,
  692. "java": true,
  693. "jcb": true,
  694. "je": true,
  695. "jetzt": true,
  696. "jewelry": true,
  697. "jll": true,
  698. "jm": true,
  699. "jmp": true,
  700. "jo": true,
  701. "jobs": true,
  702. "joburg": true,
  703. "jp": true,
  704. "jprs": true,
  705. "juegos": true,
  706. "kaufen": true,
  707. "ke": true,
  708. "kg": true,
  709. "kh": true,
  710. "ki": true,
  711. "kim": true,
  712. "kinder": true,
  713. "kitchen": true,
  714. "kiwi": true,
  715. "km": true,
  716. "kn": true,
  717. "koeln": true,
  718. "komatsu": true,
  719. "kp": true,
  720. "kpn": true,
  721. "kr": true,
  722. "krd": true,
  723. "kred": true,
  724. "kw": true,
  725. "ky": true,
  726. "kyoto": true,
  727. "kz": true,
  728. "la": true,
  729. "lamborghini": true,
  730. "lancaster": true,
  731. "land": true,
  732. "lat": true,
  733. "latrobe": true,
  734. "law": true,
  735. "lawyer": true,
  736. "lb": true,
  737. "lc": true,
  738. "lease": true,
  739. "leclerc": true,
  740. "legal": true,
  741. "lexus": true,
  742. "lgbt": true,
  743. "li": true,
  744. "lidl": true,
  745. "life": true,
  746. "lighting": true,
  747. "limited": true,
  748. "limo": true,
  749. "linde": true,
  750. "link": true,
  751. "live": true,
  752. "lixil": true,
  753. "lk": true,
  754. "loan": true,
  755. "loans": true,
  756. "locus": true,
  757. "lol": true,
  758. "london": true,
  759. "lotto": true,
  760. "love": true,
  761. "lr": true,
  762. "ls": true,
  763. "lt": true,
  764. "ltd": true,
  765. "ltda": true,
  766. "lu": true,
  767. "luxury": true,
  768. "lv": true,
  769. "ly": true,
  770. "ma": true,
  771. "maif": true,
  772. "maison": true,
  773. "makeup": true,
  774. "man": true,
  775. "management": true,
  776. "mango": true,
  777. "market": true,
  778. "marketing": true,
  779. "markets": true,
  780. "marriott": true,
  781. "mba": true,
  782. "mc": true,
  783. "md": true,
  784. "me": true,
  785. "med": true,
  786. "media": true,
  787. "melbourne": true,
  788. "memorial": true,
  789. "men": true,
  790. "menu": true,
  791. "mg": true,
  792. "mh": true,
  793. "miami": true,
  794. "microsoft": true,
  795. "mil": true,
  796. "mini": true,
  797. "mk": true,
  798. "ml": true,
  799. "mm": true,
  800. "mma": true,
  801. "mn": true,
  802. "mo": true,
  803. "mobi": true,
  804. "moda": true,
  805. "moe": true,
  806. "moi": true,
  807. "mom": true,
  808. "monash": true,
  809. "money": true,
  810. "mortgage": true,
  811. "moscow": true,
  812. "motorcycles": true,
  813. "movie": true,
  814. "mp": true,
  815. "mq": true,
  816. "mr": true,
  817. "ms": true,
  818. "mt": true,
  819. "mtn": true,
  820. "mtr": true,
  821. "mu": true,
  822. "museum": true,
  823. "mv": true,
  824. "mw": true,
  825. "mx": true,
  826. "my": true,
  827. "mz": true,
  828. "na": true,
  829. "nadex": true,
  830. "nagoya": true,
  831. "name": true,
  832. "natura": true,
  833. "navy": true,
  834. "nc": true,
  835. "ne": true,
  836. "nec": true,
  837. "net": true,
  838. "network": true,
  839. "neustar": true,
  840. "new": true,
  841. "news": true,
  842. "nf": true,
  843. "ng": true,
  844. "ngo": true,
  845. "ni": true,
  846. "nico": true,
  847. "ninja": true,
  848. "nl": true,
  849. "no": true,
  850. "nokia": true,
  851. "np": true,
  852. "nr": true,
  853. "nra": true,
  854. "nrw": true,
  855. "ntt": true,
  856. "nu": true,
  857. "nyc": true,
  858. "nz": true,
  859. "okinawa": true,
  860. "om": true,
  861. "omega": true,
  862. "one": true,
  863. "ong": true,
  864. "onl": true,
  865. "online": true,
  866. "ooo": true,
  867. "oracle": true,
  868. "orange": true,
  869. "org": true,
  870. "organic": true,
  871. "osaka": true,
  872. "otsuka": true,
  873. "ovh": true,
  874. "pa": true,
  875. "page": true,
  876. "paris": true,
  877. "partners": true,
  878. "parts": true,
  879. "party": true,
  880. "pe": true,
  881. "pet": true,
  882. "pf": true,
  883. "pg": true,
  884. "ph": true,
  885. "pharmacy": true,
  886. "philips": true,
  887. "photo": true,
  888. "photography": true,
  889. "photos": true,
  890. "physio": true,
  891. "pics": true,
  892. "pictet": true,
  893. "pictures": true,
  894. "pink": true,
  895. "pizza": true,
  896. "pk": true,
  897. "pl": true,
  898. "place": true,
  899. "plumbing": true,
  900. "plus": true,
  901. "pm": true,
  902. "pn": true,
  903. "poker": true,
  904. "porn": true,
  905. "post": true,
  906. "pr": true,
  907. "praxi": true,
  908. "press": true,
  909. "pro": true,
  910. "productions": true,
  911. "promo": true,
  912. "properties": true,
  913. "property": true,
  914. "protection": true,
  915. "pru": true,
  916. "ps": true,
  917. "pt": true,
  918. "pub": true,
  919. "pw": true,
  920. "py": true,
  921. "qa": true,
  922. "qpon": true,
  923. "quebec": true,
  924. "racing": true,
  925. "radio": true,
  926. "re": true,
  927. "realtor": true,
  928. "realty": true,
  929. "recipes": true,
  930. "red": true,
  931. "redstone": true,
  932. "rehab": true,
  933. "reise": true,
  934. "reisen": true,
  935. "reit": true,
  936. "ren": true,
  937. "rent": true,
  938. "rentals": true,
  939. "repair": true,
  940. "report": true,
  941. "republican": true,
  942. "rest": true,
  943. "restaurant": true,
  944. "review": true,
  945. "reviews": true,
  946. "rich": true,
  947. "ricoh": true,
  948. "rio": true,
  949. "rip": true,
  950. "ro": true,
  951. "rocks": true,
  952. "rodeo": true,
  953. "rs": true,
  954. "ru": true,
  955. "ruhr": true,
  956. "run": true,
  957. "rw": true,
  958. "ryukyu": true,
  959. "sa": true,
  960. "saarland": true,
  961. "sale": true,
  962. "salon": true,
  963. "samsung": true,
  964. "sandvik": true,
  965. "sandvikcoromant": true,
  966. "sap": true,
  967. "sarl": true,
  968. "saxo": true,
  969. "sb": true,
  970. "sc": true,
  971. "sca": true,
  972. "scb": true,
  973. "schmidt": true,
  974. "school": true,
  975. "schule": true,
  976. "schwarz": true,
  977. "science": true,
  978. "scot": true,
  979. "sd": true,
  980. "se": true,
  981. "seat": true,
  982. "security": true,
  983. "sener": true,
  984. "services": true,
  985. "seven": true,
  986. "sew": true,
  987. "sex": true,
  988. "sexy": true,
  989. "sfr": true,
  990. "sg": true,
  991. "sh": true,
  992. "sharp": true,
  993. "shell": true,
  994. "shiksha": true,
  995. "shoes": true,
  996. "shop": true,
  997. "shopping": true,
  998. "show": true,
  999. "shriram": true,
  1000. "si": true,
  1001. "singles": true,
  1002. "site": true,
  1003. "sk": true,
  1004. "ski": true,
  1005. "skin": true,
  1006. "sky": true,
  1007. "skype": true,
  1008. "sl": true,
  1009. "sm": true,
  1010. "smart": true,
  1011. "sn": true,
  1012. "sncf": true,
  1013. "so": true,
  1014. "soccer": true,
  1015. "social": true,
  1016. "software": true,
  1017. "sohu": true,
  1018. "solar": true,
  1019. "solutions": true,
  1020. "sony": true,
  1021. "soy": true,
  1022. "space": true,
  1023. "spreadbetting": true,
  1024. "sr": true,
  1025. "srl": true,
  1026. "st": true,
  1027. "stada": true,
  1028. "stc": true,
  1029. "storage": true,
  1030. "store": true,
  1031. "stream": true,
  1032. "studio": true,
  1033. "study": true,
  1034. "style": true,
  1035. "su": true,
  1036. "sucks": true,
  1037. "supplies": true,
  1038. "supply": true,
  1039. "support": true,
  1040. "surf": true,
  1041. "surgery": true,
  1042. "suzuki": true,
  1043. "sv": true,
  1044. "swatch": true,
  1045. "swiss": true,
  1046. "sx": true,
  1047. "sy": true,
  1048. "sydney": true,
  1049. "systems": true,
  1050. "sz": true,
  1051. "taipei": true,
  1052. "tatamotors": true,
  1053. "tatar": true,
  1054. "tattoo": true,
  1055. "tax": true,
  1056. "taxi": true,
  1057. "tc": true,
  1058. "td": true,
  1059. "team": true,
  1060. "tech": true,
  1061. "technology": true,
  1062. "tel": true,
  1063. "tennis": true,
  1064. "teva": true,
  1065. "tf": true,
  1066. "tg": true,
  1067. "th": true,
  1068. "theater": true,
  1069. "theatre": true,
  1070. "tickets": true,
  1071. "tienda": true,
  1072. "tips": true,
  1073. "tires": true,
  1074. "tirol": true,
  1075. "tj": true,
  1076. "tk": true,
  1077. "tl": true,
  1078. "tm": true,
  1079. "tn": true,
  1080. "to": true,
  1081. "today": true,
  1082. "tokyo": true,
  1083. "tools": true,
  1084. "top": true,
  1085. "toray": true,
  1086. "toshiba": true,
  1087. "total": true,
  1088. "tours": true,
  1089. "town": true,
  1090. "toyota": true,
  1091. "toys": true,
  1092. "tr": true,
  1093. "trade": true,
  1094. "trading": true,
  1095. "training": true,
  1096. "travel": true,
  1097. "travelers": true,
  1098. "trust": true,
  1099. "tt": true,
  1100. "tube": true,
  1101. "tv": true,
  1102. "tw": true,
  1103. "tz": true,
  1104. "ua": true,
  1105. "ug": true,
  1106. "uk": true,
  1107. "university": true,
  1108. "uno": true,
  1109. "uol": true,
  1110. "us": true,
  1111. "uy": true,
  1112. "uz": true,
  1113. "va": true,
  1114. "vacations": true,
  1115. "vc": true,
  1116. "ve": true,
  1117. "vegas": true,
  1118. "ventures": true,
  1119. "versicherung": true,
  1120. "vet": true,
  1121. "vg": true,
  1122. "vi": true,
  1123. "viajes": true,
  1124. "video": true,
  1125. "villas": true,
  1126. "vin": true,
  1127. "vip": true,
  1128. "vision": true,
  1129. "vistaprint": true,
  1130. "vlaanderen": true,
  1131. "vn": true,
  1132. "vodka": true,
  1133. "volkswagen": true,
  1134. "vote": true,
  1135. "voting": true,
  1136. "voto": true,
  1137. "voyage": true,
  1138. "vu": true,
  1139. "wales": true,
  1140. "walter": true,
  1141. "wang": true,
  1142. "watch": true,
  1143. "webcam": true,
  1144. "weber": true,
  1145. "website": true,
  1146. "wed": true,
  1147. "wedding": true,
  1148. "weir": true,
  1149. "wf": true,
  1150. "whoswho": true,
  1151. "wien": true,
  1152. "wiki": true,
  1153. "williamhill": true,
  1154. "win": true,
  1155. "windows": true,
  1156. "wine": true,
  1157. "wme": true,
  1158. "work": true,
  1159. "works": true,
  1160. "world": true,
  1161. "ws": true,
  1162. "wtf": true,
  1163. "xbox": true,
  1164. "xin": true,
  1165. "xn--1ck2e1b": true,
  1166. "xn--1qqw23a": true,
  1167. "xn--30rr7y": true,
  1168. "xn--3bst00m": true,
  1169. "xn--3ds443g": true,
  1170. "xn--3e0b707e": true,
  1171. "xn--45q11c": true,
  1172. "xn--4gbrim": true,
  1173. "xn--54b7fta0cc": true,
  1174. "xn--55qx5d": true,
  1175. "xn--5tzm5g": true,
  1176. "xn--6frz82g": true,
  1177. "xn--6qq986b3xl": true,
  1178. "xn--80adxhks": true,
  1179. "xn--80ao21a": true,
  1180. "xn--80asehdb": true,
  1181. "xn--80aswg": true,
  1182. "xn--90a3ac": true,
  1183. "xn--90ae": true,
  1184. "xn--90ais": true,
  1185. "xn--bck1b9a5dre4c": true,
  1186. "xn--c1avg": true,
  1187. "xn--cck2b3b": true,
  1188. "xn--cg4bki": true,
  1189. "xn--clchc0ea0b2g2a9gcd": true,
  1190. "xn--czr694b": true,
  1191. "xn--czru2d": true,
  1192. "xn--d1acj3b": true,
  1193. "xn--d1alf": true,
  1194. "xn--e1a4c": true,
  1195. "xn--efvy88h": true,
  1196. "xn--fct429k": true,
  1197. "xn--fiq228c5hs": true,
  1198. "xn--fiq64b": true,
  1199. "xn--fiqs8s": true,
  1200. "xn--fiqz9s": true,
  1201. "xn--fpcrj9c3d": true,
  1202. "xn--fzc2c9e2c": true,
  1203. "xn--gckr3f0f": true,
  1204. "xn--gecrj9c": true,
  1205. "xn--h2brj9c": true,
  1206. "xn--hxt814e": true,
  1207. "xn--i1b6b1a6a2e": true,
  1208. "xn--imr513n": true,
  1209. "xn--io0a7i": true,
  1210. "xn--j1amh": true,
  1211. "xn--j6w193g": true,
  1212. "xn--jvr189m": true,
  1213. "xn--kcrx77d1x4a": true,
  1214. "xn--kprw13d": true,
  1215. "xn--kpry57d": true,
  1216. "xn--kput3i": true,
  1217. "xn--l1acc": true,
  1218. "xn--lgbbat1ad8j": true,
  1219. "xn--mgb9awbf": true,
  1220. "xn--mgba3a4f16a": true,
  1221. "xn--mgbaam7a8h": true,
  1222. "xn--mgbab2bd": true,
  1223. "xn--mgbai9azgqp6j": true,
  1224. "xn--mgbayh7gpa": true,
  1225. "xn--mgberp4a5d4ar": true,
  1226. "xn--mgbtx2b": true,
  1227. "xn--mix891f": true,
  1228. "xn--mk1bu44c": true,
  1229. "xn--ngbc5azd": true,
  1230. "xn--node": true,
  1231. "xn--nqv7f": true,
  1232. "xn--nyqy26a": true,
  1233. "xn--o3cw4h": true,
  1234. "xn--ogbpf8fl": true,
  1235. "xn--p1acf": true,
  1236. "xn--p1ai": true,
  1237. "xn--pgbs0dh": true,
  1238. "xn--q9jyb4c": true,
  1239. "xn--qxam": true,
  1240. "xn--rhqv96g": true,
  1241. "xn--rovu88b": true,
  1242. "xn--ses554g": true,
  1243. "xn--t60b56a": true,
  1244. "xn--tckwe": true,
  1245. "xn--vuq861b": true,
  1246. "xn--wgbh1c": true,
  1247. "xn--wgbl6a": true,
  1248. "xn--xhq521b": true,
  1249. "xn--xkc2al3hye2a": true,
  1250. "xn--xkc2dl3a5ee0h": true,
  1251. "xn--y9a3aq": true,
  1252. "xn--yfro4i67o": true,
  1253. "xn--ygbi2ammx": true,
  1254. "xperia": true,
  1255. "xxx": true,
  1256. "xyz": true,
  1257. "yachts": true,
  1258. "yandex": true,
  1259. "ye": true,
  1260. "yoga": true,
  1261. "yokohama": true,
  1262. "yt": true,
  1263. "za": true,
  1264. "zm": true,
  1265. "zone": true,
  1266. "zw": true,
  1267. "セール": true,
  1268. "佛山": true,
  1269. "慈善": true,
  1270. "集团": true,
  1271. "在线": true,
  1272. "한국": true,
  1273. "八卦": true,
  1274. "موقع": true,
  1275. "বাংলা": true,
  1276. "公司": true,
  1277. "网站": true,
  1278. "移动": true,
  1279. "我爱你": true,
  1280. "москва": true,
  1281. "қаз": true,
  1282. "онлайн": true,
  1283. "сайт": true,
  1284. "срб": true,
  1285. "бг": true,
  1286. "бел": true,
  1287. "ファッション": true,
  1288. "орг": true,
  1289. "ストア": true,
  1290. "삼성": true,
  1291. "சிங்கப்பூர்": true,
  1292. "商标": true,
  1293. "商城": true,
  1294. "дети": true,
  1295. "мкд": true,
  1296. "ею": true,
  1297. "新闻": true,
  1298. "家電": true,
  1299. "中文网": true,
  1300. "中信": true,
  1301. "中国": true,
  1302. "中國": true,
  1303. "భారత్": true,
  1304. "ලංකා": true,
  1305. "クラウド": true,
  1306. "ભારત": true,
  1307. "भारत": true,
  1308. "网店": true,
  1309. "संगठन": true,
  1310. "餐厅": true,
  1311. "网络": true,
  1312. "укр": true,
  1313. "香港": true,
  1314. "食品": true,
  1315. "飞利浦": true,
  1316. "台湾": true,
  1317. "台灣": true,
  1318. "手机": true,
  1319. "мон": true,
  1320. "الجزائر": true,
  1321. "عمان": true,
  1322. "ایران": true,
  1323. "امارات": true,
  1324. "بازار": true,
  1325. "پاکستان": true,
  1326. "الاردن": true,
  1327. "السعودية": true,
  1328. "عراق": true,
  1329. "澳門": true,
  1330. "닷컴": true,
  1331. "شبكة": true,
  1332. "გე": true,
  1333. "机构": true,
  1334. "健康": true,
  1335. "ไทย": true,
  1336. "سورية": true,
  1337. "рус": true,
  1338. "рф": true,
  1339. "تونس": true,
  1340. "みんな": true,
  1341. "ελ": true,
  1342. "世界": true,
  1343. "書籍": true,
  1344. "网址": true,
  1345. "닷넷": true,
  1346. "コム": true,
  1347. "信息": true,
  1348. "مصر": true,
  1349. "قطر": true,
  1350. "广东": true,
  1351. "இலங்கை": true,
  1352. "இந்தியா": true,
  1353. "հայ": true,
  1354. "新加坡": true,
  1355. "فلسطين": true
  1356. }
  1357. }
  1358. },{}],4:[function(require,module,exports){
  1359. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1360.  
  1361. var tlds = require("./tlds.json"),
  1362. RE = {
  1363. PROTOCOL: "([a-z][-a-z*]+://)?",
  1364. USER: "(?:([\\w:.+-]+)@)?",
  1365. DOMAIN_UNI: `([a-z0-9-.\\u00A0-\\uFFFF]+\\.[a-z0-9-${tlds.chars}]{1,${tlds.maxLength}})`,
  1366. DOMAIN: `([a-z0-9-.]+\\.[a-z0-9-]{1,${tlds.maxLength}})`,
  1367. PORT: "(:\\d+\\b)?",
  1368. PATH_UNI: "([/?#]\\S*)?",
  1369. PATH: "([/?#][\\w-.~!$&*+;=:@%/?#(),'\\[\\]]*)?"
  1370. },
  1371. TLD_TABLE = tlds.table;
  1372.  
  1373. function regexEscape(text) {
  1374. return text.replace(/[\[\]\\^-]/g, "\\$&");
  1375. }
  1376.  
  1377. function buildRegex(_ref) {
  1378. var _ref$unicode = _ref.unicode,
  1379. unicode = _ref$unicode === undefined ? false : _ref$unicode,
  1380. _ref$customRules = _ref.customRules,
  1381. customRules = _ref$customRules === undefined ? [] : _ref$customRules,
  1382. _ref$standalone = _ref.standalone,
  1383. standalone = _ref$standalone === undefined ? false : _ref$standalone,
  1384. boundaryLeft = _ref.boundaryLeft,
  1385. boundaryRight = _ref.boundaryRight;
  1386.  
  1387. var pattern = RE.PROTOCOL + RE.USER;
  1388.  
  1389. if (unicode) {
  1390. pattern += RE.DOMAIN_UNI + RE.PORT + RE.PATH_UNI;
  1391. } else {
  1392. pattern += RE.DOMAIN + RE.PORT + RE.PATH;
  1393. }
  1394.  
  1395. if (customRules.length) {
  1396. pattern = "(?:" + pattern + "|(" + customRules.join("|") + "))";
  1397. } else {
  1398. pattern += "()";
  1399. }
  1400.  
  1401. var prefix, suffix, invalidSuffix;
  1402. if (standalone) {
  1403. if (boundaryLeft) {
  1404. prefix = "((?:^|\\s)[" + regexEscape(boundaryLeft) + "]*?)";
  1405. } else {
  1406. prefix = "(^|\\s)";
  1407. }
  1408. if (boundaryRight) {
  1409. suffix = "([" + regexEscape(boundaryRight) + "]*(?:$|\\s))";
  1410. } else {
  1411. suffix = "($|\\s)";
  1412. }
  1413. invalidSuffix = "[^\\s" + regexEscape(boundaryRight) + "]";
  1414. } else {
  1415. prefix = "(^|\\b|_)";
  1416. suffix = "()";
  1417. }
  1418.  
  1419. pattern = prefix + pattern + suffix;
  1420.  
  1421. return {
  1422. url: new RegExp(pattern, "igm"),
  1423. invalidSuffix: invalidSuffix && new RegExp(invalidSuffix),
  1424. mustache: /\{\{[\s\S]+?\}\}/g
  1425. };
  1426. }
  1427.  
  1428. function pathStrip(m, re, repl) {
  1429. var s = m.path.replace(re, repl);
  1430.  
  1431. if (s == m.path) return;
  1432.  
  1433. m.end -= m.path.length - s.length;
  1434. m.suffix = m.path.slice(s.length) + m.suffix;
  1435. m.path = s;
  1436. }
  1437.  
  1438. function pathStripQuote(m, c) {
  1439. var i = 0,
  1440. s = m.path,
  1441. end,
  1442. pos = 0;
  1443.  
  1444. if (!s.endsWith(c)) return;
  1445.  
  1446. while ((pos = s.indexOf(c, pos)) >= 0) {
  1447. if (i % 2) {
  1448. end = null;
  1449. } else {
  1450. end = pos;
  1451. }
  1452. pos++;
  1453. i++;
  1454. }
  1455.  
  1456. if (!end) return;
  1457.  
  1458. m.end -= s.length - end;
  1459. m.path = s.slice(0, end);
  1460. m.suffix = s.slice(end) + m.suffix;
  1461. }
  1462.  
  1463. function pathStripBrace(m, left, right) {
  1464. var str = m.path,
  1465. re = new RegExp("[\\" + left + "\\" + right + "]", "g"),
  1466. match,
  1467. count = 0,
  1468. end;
  1469.  
  1470. // Match loop
  1471. while (match = re.exec(str)) {
  1472. if (count % 2 == 0) {
  1473. end = match.index;
  1474. if (match[0] == right) {
  1475. break;
  1476. }
  1477. } else {
  1478. if (match[0] == left) {
  1479. break;
  1480. }
  1481. }
  1482. count++;
  1483. }
  1484.  
  1485. if (!match && count % 2 == 0) {
  1486. return;
  1487. }
  1488.  
  1489. m.end -= m.path.length - end;
  1490. m.path = str.slice(0, end);
  1491. m.suffix = str.slice(end) + m.suffix;
  1492. }
  1493.  
  1494. function isIP(s) {
  1495. var m, i;
  1496. if (!(m = s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/))) {
  1497. return false;
  1498. }
  1499. for (i = 1; i < m.length; i++) {
  1500. if (+m[i] > 255 || m[i].length > 1 && m[i][0] == "0") {
  1501. return false;
  1502. }
  1503. }
  1504. return true;
  1505. }
  1506.  
  1507. function isDomain(d) {
  1508. return (/^[^.-]/.test(d) && d.indexOf("..") < 0
  1509. );
  1510. }
  1511.  
  1512. function inTLDS(domain) {
  1513. var match = domain.match(/\.([^.]+)$/);
  1514. if (!match) {
  1515. return false;
  1516. }
  1517. var key = match[1].toLowerCase();
  1518. return TLD_TABLE.hasOwnProperty(key);
  1519. }
  1520.  
  1521. var UrlMatcher = function () {
  1522. function UrlMatcher() {
  1523. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1524.  
  1525. _classCallCheck(this, UrlMatcher);
  1526.  
  1527. this.options = options;
  1528. this.regex = buildRegex(options);
  1529. }
  1530.  
  1531. UrlMatcher.prototype.match = function* match(text) {
  1532. var _options = this.options,
  1533. _options$fuzzyIp = _options.fuzzyIp,
  1534. fuzzyIp = _options$fuzzyIp === undefined ? true : _options$fuzzyIp,
  1535. _options$ignoreMustac = _options.ignoreMustache,
  1536. ignoreMustache = _options$ignoreMustac === undefined ? false : _options$ignoreMustac,
  1537. _regex = this.regex,
  1538. url = _regex.url,
  1539. invalidSuffix = _regex.invalidSuffix,
  1540. mustache = _regex.mustache,
  1541. urlLastIndex,
  1542. mustacheLastIndex;
  1543.  
  1544.  
  1545. mustache.lastIndex = 0;
  1546. url.lastIndex = 0;
  1547.  
  1548. var mustacheMatch, mustacheRange;
  1549. if (ignoreMustache) {
  1550. mustacheMatch = mustache.exec(text);
  1551. if (mustacheMatch) {
  1552. mustacheRange = {
  1553. start: mustacheMatch.index,
  1554. end: mustache.lastIndex
  1555. };
  1556. }
  1557. }
  1558.  
  1559. var urlMatch;
  1560. while (urlMatch = url.exec(text)) {
  1561. var result;
  1562. if (urlMatch[7]) {
  1563. // custom rules
  1564. result = {
  1565. start: urlMatch.index,
  1566. end: url.lastIndex,
  1567.  
  1568. text: urlMatch[0],
  1569. url: urlMatch[0],
  1570.  
  1571. custom: urlMatch[7]
  1572. };
  1573. } else {
  1574. result = {
  1575. start: urlMatch.index + urlMatch[1].length,
  1576. end: url.lastIndex - urlMatch[8].length,
  1577.  
  1578. text: null,
  1579. url: null,
  1580.  
  1581. prefix: urlMatch[1],
  1582. protocol: urlMatch[2],
  1583. auth: urlMatch[3] || "",
  1584. domain: urlMatch[4],
  1585. port: urlMatch[5] || "",
  1586. path: urlMatch[6] || "",
  1587. custom: urlMatch[7],
  1588. suffix: urlMatch[8]
  1589. };
  1590. }
  1591.  
  1592. if (mustacheRange && mustacheRange.end <= result.start) {
  1593. mustacheMatch = mustache.exec(text);
  1594. if (mustacheMatch) {
  1595. mustacheRange.start = mustacheMatch.index;
  1596. mustacheRange.end = mustache.lastIndex;
  1597. } else {
  1598. mustacheRange = null;
  1599. }
  1600. }
  1601.  
  1602. // ignore urls inside mustache pair
  1603. if (mustacheRange && result.start < mustacheRange.end && result.end >= mustacheRange.start) {
  1604. continue;
  1605. }
  1606.  
  1607. if (!result.custom) {
  1608. // adjust path and suffix
  1609. if (result.path) {
  1610. // Strip BBCode
  1611. pathStrip(result, /\[\/?(b|i|u|url|img|quote|code|size|color)\].*/i, "");
  1612.  
  1613. // Strip braces
  1614. pathStripBrace(result, "(", ")");
  1615. pathStripBrace(result, "[", "]");
  1616. pathStripBrace(result, "{", "}");
  1617.  
  1618. // Strip quotes
  1619. pathStripQuote(result, "'");
  1620. pathStripQuote(result, '"');
  1621.  
  1622. // Remove trailing ".,?"
  1623. pathStrip(result, /(^|[^-_])[.,?]+$/, "$1");
  1624. }
  1625.  
  1626. // check suffix
  1627. if (invalidSuffix && invalidSuffix.test(result.suffix)) {
  1628. if (/\s$/.test(result.suffix)) {
  1629. url.lastIndex--;
  1630. }
  1631. continue;
  1632. }
  1633.  
  1634. // check domain
  1635. if (isIP(result.domain)) {
  1636. if (!fuzzyIp && !result.protocol && !result.auth && !result.path) {
  1637. continue;
  1638. }
  1639. } else if (isDomain(result.domain)) {
  1640. if (!inTLDS(result.domain)) {
  1641. continue;
  1642. }
  1643. } else {
  1644. continue;
  1645. }
  1646.  
  1647. // mailto protocol
  1648. if (!result.protocol && result.auth) {
  1649. var matchMail = result.auth.match(/^mailto:(.+)/);
  1650. if (matchMail) {
  1651. result.protocol = "mailto:";
  1652. result.auth = matchMail[1];
  1653. }
  1654. }
  1655.  
  1656. // http alias
  1657. if (result.protocol && result.protocol.match(/^(hxxp|h\*\*p|ttp)/)) {
  1658. result.protocol = "http://";
  1659. }
  1660.  
  1661. // guess protocol
  1662. if (!result.protocol) {
  1663. var domainMatch;
  1664. if (domainMatch = result.domain.match(/^(ftp|irc)/)) {
  1665. result.protocol = domainMatch[0] + "://";
  1666. } else if (result.domain.match(/^(www|web)/)) {
  1667. result.protocol = "http://";
  1668. } else if (result.auth && result.auth.indexOf(":") < 0 && !result.path) {
  1669. result.protocol = "mailto:";
  1670. } else {
  1671. result.protocol = "http://";
  1672. }
  1673. }
  1674.  
  1675. // Create URL
  1676. result.url = result.protocol + (result.auth && result.auth + "@") + result.domain + result.port + result.path;
  1677. result.text = text.slice(result.start, result.end);
  1678. }
  1679.  
  1680. // since regex is shared with other parse generators, cache lastIndex position and restore later
  1681. mustacheLastIndex = mustache.lastIndex;
  1682. urlLastIndex = url.lastIndex;
  1683.  
  1684. yield result;
  1685.  
  1686. url.lastIndex = urlLastIndex;
  1687. mustache.lastIndex = mustacheLastIndex;
  1688. }
  1689. };
  1690.  
  1691. return UrlMatcher;
  1692. }();
  1693.  
  1694. module.exports = {
  1695. UrlMatcher
  1696. };
  1697.  
  1698. },{"./tlds.json":3}]},{},[1])(1)
  1699. });