remove the jump link in BAIDU (ECMA6)

去除百度搜索跳转链接

目前为 2016-06-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name remove the jump link in BAIDU (ECMA6)
  3. // @author axetroy
  4. // @collaborator axetroy
  5. // @description 去除百度搜索跳转链接
  6. // @version 2016.6.4
  7. // @grant GM_xmlhttpRequest
  8. // @include *www.baidu.com*
  9. // @connect *
  10. // @compatible chrome 完美运行
  11. // @compatible firefox 完美运行
  12. // @supportURL http://www.burningall.com
  13. // @run-at document-start
  14. // @contributionURL troy450409405@gmail.com|alipay.com
  15. // @namespace https://greasyfork.org/zh-CN/users/3400-axetroy
  16. // @license The MIT License (MIT); http://opensource.org/licenses/MIT
  17. // ==/UserScript==
  18.  
  19. /*
  20.  
  21. Github源码:https://github.com/axetroy/GMscript
  22.  
  23. */
  24. /******/ (function(modules) { // webpackBootstrap
  25. /******/ // The module cache
  26. /******/ var installedModules = {};
  27.  
  28. /******/ // The require function
  29. /******/ function __webpack_require__(moduleId) {
  30.  
  31. /******/ // Check if module is in cache
  32. /******/ if(installedModules[moduleId])
  33. /******/ return installedModules[moduleId].exports;
  34.  
  35. /******/ // Create a new module (and put it into the cache)
  36. /******/ var module = installedModules[moduleId] = {
  37. /******/ exports: {},
  38. /******/ id: moduleId,
  39. /******/ loaded: false
  40. /******/ };
  41.  
  42. /******/ // Execute the module function
  43. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  44.  
  45. /******/ // Flag the module as loaded
  46. /******/ module.loaded = true;
  47.  
  48. /******/ // Return the exports of the module
  49. /******/ return module.exports;
  50. /******/ }
  51.  
  52.  
  53. /******/ // expose the modules object (__webpack_modules__)
  54. /******/ __webpack_require__.m = modules;
  55.  
  56. /******/ // expose the module cache
  57. /******/ __webpack_require__.c = installedModules;
  58.  
  59. /******/ // __webpack_public_path__
  60. /******/ __webpack_require__.p = "";
  61.  
  62. /******/ // Load entry module and return exports
  63. /******/ return __webpack_require__(0);
  64. /******/ })
  65. /************************************************************************/
  66. /******/ ([
  67. /* 0 */
  68. /***/ function(module, exports, __webpack_require__) {
  69.  
  70. 'use strict';
  71.  
  72. var _jqLite = __webpack_require__(1);
  73.  
  74. var _jqLite2 = _interopRequireDefault(_jqLite);
  75.  
  76. var _init = __webpack_require__(42);
  77.  
  78. var _init2 = _interopRequireDefault(_init);
  79.  
  80. var _observe = __webpack_require__(50);
  81.  
  82. var _observe2 = _interopRequireDefault(_observe);
  83.  
  84. var _mouseover = __webpack_require__(53);
  85.  
  86. var _mouseover2 = _interopRequireDefault(_mouseover);
  87.  
  88. var _scroll = __webpack_require__(54);
  89.  
  90. var _scroll2 = _interopRequireDefault(_scroll);
  91.  
  92. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  93.  
  94. (0, _jqLite2.default)(function () {
  95.  
  96. // init
  97. (0, _init2.default)();
  98.  
  99. // observe the document
  100. (0, _observe2.default)();
  101.  
  102. // when mouse over on a A Tag and request
  103. (0, _mouseover2.default)();
  104.  
  105. // scroll and request
  106. (0, _scroll2.default)();
  107.  
  108. console.info('去baidu搜索跳转链接启动');
  109. });
  110.  
  111. /***/ },
  112. /* 1 */
  113. /***/ function(module, exports, __webpack_require__) {
  114.  
  115. 'use strict';
  116.  
  117. // es6 Array.from
  118.  
  119. Object.defineProperty(exports, "__esModule", {
  120. value: true
  121. });
  122.  
  123. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
  124.  
  125. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  126. // es6 Object.assign
  127.  
  128.  
  129. __webpack_require__(2);
  130.  
  131. __webpack_require__(30);
  132.  
  133. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  134.  
  135. var noop = function noop(x) {
  136. return x;
  137. };
  138.  
  139. var jqLite = function () {
  140. function jqLite() {
  141. var _this = this;
  142.  
  143. var selectors = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
  144. var context = arguments.length <= 1 || arguments[1] === undefined ? document : arguments[1];
  145.  
  146. _classCallCheck(this, jqLite);
  147.  
  148. this.selectors = selectors;
  149. this.context = context;
  150. this.length = 0;
  151.  
  152. switch (typeof selectors === 'undefined' ? 'undefined' : _typeof(selectors)) {
  153. case 'undefined':
  154. break;
  155. case 'string':
  156. Array.from(context.querySelectorAll(selectors), function (ele, i) {
  157. _this[i] = ele;
  158. _this.length++;
  159. }, this);
  160. break;
  161. case 'object':
  162. if (selectors.length) {
  163. Array.from(selectors, function (ele, i) {
  164. _this[i] = ele;
  165. _this.length++;
  166. }, this);
  167. } else {
  168. this[0] = selectors;
  169. this.length = 1;
  170. }
  171. break;
  172. case 'function':
  173. this.ready(selectors);
  174. break;
  175. default:
  176.  
  177. }
  178. }
  179.  
  180. _createClass(jqLite, [{
  181. key: 'eq',
  182. value: function eq() {
  183. var n = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
  184.  
  185. return new jqLite(this[n]);
  186. }
  187. }, {
  188. key: 'find',
  189. value: function find(selectors) {
  190. return new jqLite(selectors, this[0]);
  191. }
  192. }, {
  193. key: 'each',
  194. value: function each() {
  195. var fn = arguments.length <= 0 || arguments[0] === undefined ? noop : arguments[0];
  196.  
  197. for (var i = 0; i < this.length; i++) {
  198. fn.call(this, this[i], i);
  199. }
  200. return this;
  201. }
  202. }, {
  203. key: 'bind',
  204. value: function bind() {
  205. var types = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
  206. var fn = arguments.length <= 1 || arguments[1] === undefined ? noop : arguments[1];
  207.  
  208. this.each(function (ele) {
  209. types.trim().split(/\s{1,}/).forEach(function (type) {
  210. ele.addEventListener(type, function (e) {
  211. var target = e.target || e.srcElement;
  212. if (fn.call(target, e) === false) {
  213. e.returnValue = true;
  214. e.cancelBubble = true;
  215. e.preventDefault && e.preventDefault();
  216. e.stopPropagation && e.stopPropagation();
  217. return false;
  218. }
  219. }, false);
  220. });
  221. });
  222. }
  223. }, {
  224. key: 'click',
  225. value: function click() {
  226. var fn = arguments.length <= 0 || arguments[0] === undefined ? noop : arguments[0];
  227.  
  228. this.bind('click', fn);
  229. return this;
  230. }
  231. }, {
  232. key: 'ready',
  233. value: function ready() {
  234. var _this2 = this;
  235.  
  236. var fn = arguments.length <= 0 || arguments[0] === undefined ? noop : arguments[0];
  237.  
  238. window.addEventListener('DOMContentLoaded', function (e) {
  239. fn.call(_this2, e);
  240. }, false);
  241. }
  242. }, {
  243. key: 'observe',
  244. value: function observe() {
  245. var _this3 = this;
  246.  
  247. var fn = arguments.length <= 0 || arguments[0] === undefined ? noop : arguments[0];
  248. var config = arguments.length <= 1 || arguments[1] === undefined ? { childList: true, subtree: true } : arguments[1];
  249.  
  250. this.each(function (ele) {
  251. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  252. var observer = new MutationObserver(function (mutations) {
  253. mutations.forEach(function (mutation) {
  254. fn.call(_this3, mutation.target, mutation.addedNodes, mutation.removedNodes);
  255. });
  256. });
  257. observer.observe(ele, config);
  258. });
  259. return this;
  260. }
  261. }, {
  262. key: 'attr',
  263. value: function (_attr) {
  264. function attr(_x, _x2) {
  265. return _attr.apply(this, arguments);
  266. }
  267.  
  268. attr.toString = function () {
  269. return _attr.toString();
  270. };
  271.  
  272. return attr;
  273. }(function (attr, value) {
  274. // one agm
  275. if (arguments.length === 1) {
  276. // get attr value
  277. if (typeof attr === 'string') {
  278. return this[0].getAttribute(attr);
  279. }
  280. // set attr with a json
  281. else if ((typeof attr === 'undefined' ? 'undefined' : _typeof(attr)) === 'object') {
  282. this.each(function (ele) {
  283. for (var at in attr) {
  284. if (attr.hasOwnProperty(at)) {
  285. ele.setAttribute(at, value);
  286. }
  287. }
  288. });
  289. return value;
  290. }
  291. }
  292. // set
  293. else if (arguments.length === 2) {
  294. this.each(function (ele) {
  295. ele.setAttribute(attr, value);
  296. });
  297. return this;
  298. } else {
  299. return this;
  300. }
  301. })
  302. }, {
  303. key: 'removeAttr',
  304. value: function removeAttr(attr) {
  305. if (arguments.length === 1) {
  306. this.each(function (ele) {
  307. ele.removeAttribute(attr);
  308. });
  309. }
  310. return this;
  311. }
  312. }, {
  313. key: 'remove',
  314. value: function remove() {
  315. this.each(function (ele) {
  316. ele.remove();
  317. });
  318. this.length = 0;
  319. return this;
  320. }
  321.  
  322. // get the element style
  323.  
  324. }, {
  325. key: 'style',
  326. value: function style(attr) {
  327. return this[0].currentStyle ? this[0].currentStyle[attr] : getComputedStyle(this[0])[attr];
  328. }
  329.  
  330. // (attr,value) || 'string' || {}
  331.  
  332. }, {
  333. key: 'css',
  334. value: function css() {
  335. for (var _len = arguments.length, agm = Array(_len), _key = 0; _key < _len; _key++) {
  336. agm[_key] = arguments[_key];
  337. }
  338.  
  339. if (agm.length === 1) {
  340. // get style
  341. if (typeof agm[0] === 'string') {
  342. // set style as a long text
  343. if (/:/ig.test(agm[0])) {
  344. this.each(function (ele) {
  345. ele.style.cssText = attr;
  346. });
  347. } else {
  348. return this[0].currentStyle ? this[0].currentStyle[agm[0]] : getComputedStyle(this[0])[agm[0]];
  349. }
  350. }
  351. // set style as a object
  352. else {
  353. this.each(function (ele) {
  354. for (var _attr2 in agm[0]) {
  355. if (agm[0].hasOwnProperty(_attr2)) {
  356. ele.style[_attr2] = agm[0][_attr2];
  357. }
  358. }
  359. });
  360. }
  361. }
  362. // set as (key,value)
  363. else if (agm.length === 2) {
  364. this.each(function (ele) {
  365. ele.style[agm[0]] = agm[1];
  366. });
  367. }
  368. return this;
  369. }
  370. }, {
  371. key: 'width',
  372. value: function width(value) {
  373. var element = this[0];
  374. // window or document
  375. if (element.window === element || element.body) {
  376. return document.body.scrollWidth > document.documentElement.scrollWidth ? document.body.scrollWidth : document.documentElement.scrollWidth;
  377. }
  378. // set width
  379. else if (value) {
  380. this.each(function (ele) {
  381. ele.style.width = value + 'px';
  382. });
  383. return this;
  384. }
  385. // get width
  386. else {
  387. return this[0].offsetWidth || parseFloat(this.style('width'));
  388. }
  389. }
  390. }, {
  391. key: 'height',
  392. value: function height(value) {
  393. var ele = this[0];
  394. // window or document
  395. if (ele.window === ele || ele.body) {
  396. return document.body.scrollHeight > document.documentElement.scrollHeight ? document.body.scrollHeight : document.documentElement.scrollHeight;
  397. }
  398. // set height
  399. else if (value) {
  400. this.each(function (ele) {
  401. ele.style.height = value + 'px';
  402. });
  403. return this;
  404. }
  405. // get height
  406. else {
  407. return this[0].offsetHeight || parseFloat(this.style('height'));
  408. }
  409. }
  410. }, {
  411. key: 'html',
  412. value: function html(value) {
  413. if (value !== undefined) {
  414. this.each(function (ele) {
  415. ele.innerHTML = typeof value === 'function' ? value(ele) : value;
  416. });
  417. } else {
  418. return this[0].innerHTML;
  419. }
  420. return this;
  421. }
  422. }, {
  423. key: 'text',
  424. value: function text(value) {
  425. if (value === undefined) return this[0].innerText || this[0].textContent;
  426.  
  427. this.each(function (ele) {
  428. ele.innerText = ele.textContent = value;
  429. });
  430. return this;
  431. }
  432. }, {
  433. key: 'val',
  434. value: function val(value) {
  435. if (value === undefined) return this[0].value;
  436. this.each(function (ele) {
  437. ele.value = value;
  438. });
  439. return this;
  440. }
  441. }, {
  442. key: 'show',
  443. value: function show() {
  444. this.each(function (ele) {
  445. ele.style.display = '';
  446. });
  447. return this;
  448. }
  449. }, {
  450. key: 'hide',
  451. value: function hide() {
  452. this.each(function (ele) {
  453. ele.style.display = 'none';
  454. });
  455. return this;
  456. }
  457.  
  458. // content str || jqLite Object || DOM
  459. // here is jqLite Object
  460.  
  461. }, {
  462. key: 'append',
  463. value: function append(content) {
  464. this.each(function (ele) {
  465. ele.appendChild(content[0]);
  466. });
  467. return this;
  468. }
  469. }, {
  470. key: 'prepend',
  471.  
  472.  
  473. // content str || jqLite Object || DOM
  474. // here is jqLite Object
  475. value: function prepend(content) {
  476. this.each(function (ele) {
  477. ele.insertBefore(content[0], ele.children[0]);
  478. });
  479. return this;
  480. }
  481. }, {
  482. key: 'hasClass',
  483. value: function hasClass(className) {
  484. if (!this[0]) return false;
  485. return this[0].classList.contains(className);
  486. }
  487. }, {
  488. key: 'addClass',
  489. value: function addClass(className) {
  490. this.each(function (ele) {
  491. ele.classList.add(className);
  492. });
  493. return this;
  494. }
  495. }, {
  496. key: 'removeClass',
  497. value: function removeClass(className) {
  498. this.each(function (ele) {
  499. ele.classList.remove(className);
  500. });
  501. return this;
  502. }
  503. }, {
  504. key: 'index',
  505. get: function get() {
  506. var index = 0;
  507. var brothers = this[0].parentNode.children;
  508. for (var i = 0; i < brothers.length; i++) {
  509. if (brothers[i] == this[0]) {
  510. index = i;
  511. break;
  512. }
  513. }
  514. return index;
  515. }
  516. }], [{
  517. key: 'fn',
  518. get: function get() {
  519. var visible = function visible(ele) {
  520. var pos = ele.getBoundingClientRect();
  521. var w = void 0;
  522. var h = void 0;
  523. var inViewPort = void 0;
  524. var docEle = document.documentElement;
  525. var docBody = document.body;
  526. if (docEle.getBoundingClientRect) {
  527. w = docEle.clientWidth || docBody.clientWidth;
  528. h = docEle.clientHeight || docBody.clientHeight;
  529. inViewPort = pos.top > h || pos.bottom < 0 || pos.left > w || pos.right < 0;
  530. return inViewPort ? false : true;
  531. }
  532. };
  533. var merge = function merge() {
  534. for (var _len2 = arguments.length, sources = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  535. sources[_key2] = arguments[_key2];
  536. }
  537.  
  538. return Object.assign.apply(Object, [{}].concat(sources));
  539. };
  540. return {
  541. visible: visible,
  542. merge: merge
  543. };
  544. }
  545. }]);
  546.  
  547. return jqLite;
  548. }();
  549.  
  550. var $ = function $() {
  551. var selectors = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
  552. var context = arguments.length <= 1 || arguments[1] === undefined ? document : arguments[1];
  553.  
  554. return new jqLite(selectors, context);
  555. };
  556. $.fn = jqLite.fn;
  557.  
  558. exports.default = $;
  559.  
  560. /***/ },
  561. /* 2 */
  562. /***/ function(module, exports, __webpack_require__) {
  563.  
  564. 'use strict';
  565. var ctx = __webpack_require__(3)
  566. , $export = __webpack_require__(5)
  567. , toObject = __webpack_require__(15)
  568. , call = __webpack_require__(17)
  569. , isArrayIter = __webpack_require__(20)
  570. , toLength = __webpack_require__(24)
  571. , getIterFn = __webpack_require__(26);
  572. $export($export.S + $export.F * !__webpack_require__(29)(function(iter){ Array.from(iter); }), 'Array', {
  573. // 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined)
  574. from: function from(arrayLike/*, mapfn = undefined, thisArg = undefined*/){
  575. var O = toObject(arrayLike)
  576. , C = typeof this == 'function' ? this : Array
  577. , $$ = arguments
  578. , $$len = $$.length
  579. , mapfn = $$len > 1 ? $$[1] : undefined
  580. , mapping = mapfn !== undefined
  581. , index = 0
  582. , iterFn = getIterFn(O)
  583. , length, result, step, iterator;
  584. if(mapping)mapfn = ctx(mapfn, $$len > 2 ? $$[2] : undefined, 2);
  585. // if object isn't iterable or it's array with default iterator - use simple case
  586. if(iterFn != undefined && !(C == Array && isArrayIter(iterFn))){
  587. for(iterator = iterFn.call(O), result = new C; !(step = iterator.next()).done; index++){
  588. result[index] = mapping ? call(iterator, mapfn, [step.value, index], true) : step.value;
  589. }
  590. } else {
  591. length = toLength(O.length);
  592. for(result = new C(length); length > index; index++){
  593. result[index] = mapping ? mapfn(O[index], index) : O[index];
  594. }
  595. }
  596. result.length = index;
  597. return result;
  598. }
  599. });
  600.  
  601.  
  602. /***/ },
  603. /* 3 */
  604. /***/ function(module, exports, __webpack_require__) {
  605.  
  606. // optional / simple context binding
  607. var aFunction = __webpack_require__(4);
  608. module.exports = function(fn, that, length){
  609. aFunction(fn);
  610. if(that === undefined)return fn;
  611. switch(length){
  612. case 1: return function(a){
  613. return fn.call(that, a);
  614. };
  615. case 2: return function(a, b){
  616. return fn.call(that, a, b);
  617. };
  618. case 3: return function(a, b, c){
  619. return fn.call(that, a, b, c);
  620. };
  621. }
  622. return function(/* ...args */){
  623. return fn.apply(that, arguments);
  624. };
  625. };
  626.  
  627. /***/ },
  628. /* 4 */
  629. /***/ function(module, exports) {
  630.  
  631. module.exports = function(it){
  632. if(typeof it != 'function')throw TypeError(it + ' is not a function!');
  633. return it;
  634. };
  635.  
  636. /***/ },
  637. /* 5 */
  638. /***/ function(module, exports, __webpack_require__) {
  639.  
  640. var global = __webpack_require__(6)
  641. , core = __webpack_require__(7)
  642. , hide = __webpack_require__(8)
  643. , redefine = __webpack_require__(13)
  644. , ctx = __webpack_require__(3)
  645. , PROTOTYPE = 'prototype';
  646.  
  647. var $export = function(type, name, source){
  648. var IS_FORCED = type & $export.F
  649. , IS_GLOBAL = type & $export.G
  650. , IS_STATIC = type & $export.S
  651. , IS_PROTO = type & $export.P
  652. , IS_BIND = type & $export.B
  653. , target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE]
  654. , exports = IS_GLOBAL ? core : core[name] || (core[name] = {})
  655. , expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {})
  656. , key, own, out, exp;
  657. if(IS_GLOBAL)source = name;
  658. for(key in source){
  659. // contains in native
  660. own = !IS_FORCED && target && key in target;
  661. // export native or passed
  662. out = (own ? target : source)[key];
  663. // bind timers to global for call from export context
  664. exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
  665. // extend global
  666. if(target && !own)redefine(target, key, out);
  667. // export
  668. if(exports[key] != out)hide(exports, key, exp);
  669. if(IS_PROTO && expProto[key] != out)expProto[key] = out;
  670. }
  671. };
  672. global.core = core;
  673. // type bitmap
  674. $export.F = 1; // forced
  675. $export.G = 2; // global
  676. $export.S = 4; // static
  677. $export.P = 8; // proto
  678. $export.B = 16; // bind
  679. $export.W = 32; // wrap
  680. module.exports = $export;
  681.  
  682. /***/ },
  683. /* 6 */
  684. /***/ function(module, exports) {
  685.  
  686. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  687. var global = module.exports = typeof window != 'undefined' && window.Math == Math
  688. ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
  689. if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
  690.  
  691. /***/ },
  692. /* 7 */
  693. /***/ function(module, exports) {
  694.  
  695. var core = module.exports = {version: '1.2.6'};
  696. if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
  697.  
  698. /***/ },
  699. /* 8 */
  700. /***/ function(module, exports, __webpack_require__) {
  701.  
  702. var $ = __webpack_require__(9)
  703. , createDesc = __webpack_require__(10);
  704. module.exports = __webpack_require__(11) ? function(object, key, value){
  705. return $.setDesc(object, key, createDesc(1, value));
  706. } : function(object, key, value){
  707. object[key] = value;
  708. return object;
  709. };
  710.  
  711. /***/ },
  712. /* 9 */
  713. /***/ function(module, exports) {
  714.  
  715. var $Object = Object;
  716. module.exports = {
  717. create: $Object.create,
  718. getProto: $Object.getPrototypeOf,
  719. isEnum: {}.propertyIsEnumerable,
  720. getDesc: $Object.getOwnPropertyDescriptor,
  721. setDesc: $Object.defineProperty,
  722. setDescs: $Object.defineProperties,
  723. getKeys: $Object.keys,
  724. getNames: $Object.getOwnPropertyNames,
  725. getSymbols: $Object.getOwnPropertySymbols,
  726. each: [].forEach
  727. };
  728.  
  729. /***/ },
  730. /* 10 */
  731. /***/ function(module, exports) {
  732.  
  733. module.exports = function(bitmap, value){
  734. return {
  735. enumerable : !(bitmap & 1),
  736. configurable: !(bitmap & 2),
  737. writable : !(bitmap & 4),
  738. value : value
  739. };
  740. };
  741.  
  742. /***/ },
  743. /* 11 */
  744. /***/ function(module, exports, __webpack_require__) {
  745.  
  746. // Thank's IE8 for his funny defineProperty
  747. module.exports = !__webpack_require__(12)(function(){
  748. return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7;
  749. });
  750.  
  751. /***/ },
  752. /* 12 */
  753. /***/ function(module, exports) {
  754.  
  755. module.exports = function(exec){
  756. try {
  757. return !!exec();
  758. } catch(e){
  759. return true;
  760. }
  761. };
  762.  
  763. /***/ },
  764. /* 13 */
  765. /***/ function(module, exports, __webpack_require__) {
  766.  
  767. // add fake Function#toString
  768. // for correct work wrapped methods / constructors with methods like LoDash isNative
  769. var global = __webpack_require__(6)
  770. , hide = __webpack_require__(8)
  771. , SRC = __webpack_require__(14)('src')
  772. , TO_STRING = 'toString'
  773. , $toString = Function[TO_STRING]
  774. , TPL = ('' + $toString).split(TO_STRING);
  775.  
  776. __webpack_require__(7).inspectSource = function(it){
  777. return $toString.call(it);
  778. };
  779.  
  780. (module.exports = function(O, key, val, safe){
  781. if(typeof val == 'function'){
  782. val.hasOwnProperty(SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
  783. val.hasOwnProperty('name') || hide(val, 'name', key);
  784. }
  785. if(O === global){
  786. O[key] = val;
  787. } else {
  788. if(!safe)delete O[key];
  789. hide(O, key, val);
  790. }
  791. })(Function.prototype, TO_STRING, function toString(){
  792. return typeof this == 'function' && this[SRC] || $toString.call(this);
  793. });
  794.  
  795. /***/ },
  796. /* 14 */
  797. /***/ function(module, exports) {
  798.  
  799. var id = 0
  800. , px = Math.random();
  801. module.exports = function(key){
  802. return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
  803. };
  804.  
  805. /***/ },
  806. /* 15 */
  807. /***/ function(module, exports, __webpack_require__) {
  808.  
  809. // 7.1.13 ToObject(argument)
  810. var defined = __webpack_require__(16);
  811. module.exports = function(it){
  812. return Object(defined(it));
  813. };
  814.  
  815. /***/ },
  816. /* 16 */
  817. /***/ function(module, exports) {
  818.  
  819. // 7.2.1 RequireObjectCoercible(argument)
  820. module.exports = function(it){
  821. if(it == undefined)throw TypeError("Can't call method on " + it);
  822. return it;
  823. };
  824.  
  825. /***/ },
  826. /* 17 */
  827. /***/ function(module, exports, __webpack_require__) {
  828.  
  829. // call something on iterator step with safe closing on error
  830. var anObject = __webpack_require__(18);
  831. module.exports = function(iterator, fn, value, entries){
  832. try {
  833. return entries ? fn(anObject(value)[0], value[1]) : fn(value);
  834. // 7.4.6 IteratorClose(iterator, completion)
  835. } catch(e){
  836. var ret = iterator['return'];
  837. if(ret !== undefined)anObject(ret.call(iterator));
  838. throw e;
  839. }
  840. };
  841.  
  842. /***/ },
  843. /* 18 */
  844. /***/ function(module, exports, __webpack_require__) {
  845.  
  846. var isObject = __webpack_require__(19);
  847. module.exports = function(it){
  848. if(!isObject(it))throw TypeError(it + ' is not an object!');
  849. return it;
  850. };
  851.  
  852. /***/ },
  853. /* 19 */
  854. /***/ function(module, exports) {
  855.  
  856. module.exports = function(it){
  857. return typeof it === 'object' ? it !== null : typeof it === 'function';
  858. };
  859.  
  860. /***/ },
  861. /* 20 */
  862. /***/ function(module, exports, __webpack_require__) {
  863.  
  864. // check on default Array iterator
  865. var Iterators = __webpack_require__(21)
  866. , ITERATOR = __webpack_require__(22)('iterator')
  867. , ArrayProto = Array.prototype;
  868.  
  869. module.exports = function(it){
  870. return it !== undefined && (Iterators.Array === it || ArrayProto[ITERATOR] === it);
  871. };
  872.  
  873. /***/ },
  874. /* 21 */
  875. /***/ function(module, exports) {
  876.  
  877. module.exports = {};
  878.  
  879. /***/ },
  880. /* 22 */
  881. /***/ function(module, exports, __webpack_require__) {
  882.  
  883. var store = __webpack_require__(23)('wks')
  884. , uid = __webpack_require__(14)
  885. , Symbol = __webpack_require__(6).Symbol;
  886. module.exports = function(name){
  887. return store[name] || (store[name] =
  888. Symbol && Symbol[name] || (Symbol || uid)('Symbol.' + name));
  889. };
  890.  
  891. /***/ },
  892. /* 23 */
  893. /***/ function(module, exports, __webpack_require__) {
  894.  
  895. var global = __webpack_require__(6)
  896. , SHARED = '__core-js_shared__'
  897. , store = global[SHARED] || (global[SHARED] = {});
  898. module.exports = function(key){
  899. return store[key] || (store[key] = {});
  900. };
  901.  
  902. /***/ },
  903. /* 24 */
  904. /***/ function(module, exports, __webpack_require__) {
  905.  
  906. // 7.1.15 ToLength
  907. var toInteger = __webpack_require__(25)
  908. , min = Math.min;
  909. module.exports = function(it){
  910. return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
  911. };
  912.  
  913. /***/ },
  914. /* 25 */
  915. /***/ function(module, exports) {
  916.  
  917. // 7.1.4 ToInteger
  918. var ceil = Math.ceil
  919. , floor = Math.floor;
  920. module.exports = function(it){
  921. return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
  922. };
  923.  
  924. /***/ },
  925. /* 26 */
  926. /***/ function(module, exports, __webpack_require__) {
  927.  
  928. var classof = __webpack_require__(27)
  929. , ITERATOR = __webpack_require__(22)('iterator')
  930. , Iterators = __webpack_require__(21);
  931. module.exports = __webpack_require__(7).getIteratorMethod = function(it){
  932. if(it != undefined)return it[ITERATOR]
  933. || it['@@iterator']
  934. || Iterators[classof(it)];
  935. };
  936.  
  937. /***/ },
  938. /* 27 */
  939. /***/ function(module, exports, __webpack_require__) {
  940.  
  941. // getting tag from 19.1.3.6 Object.prototype.toString()
  942. var cof = __webpack_require__(28)
  943. , TAG = __webpack_require__(22)('toStringTag')
  944. // ES3 wrong here
  945. , ARG = cof(function(){ return arguments; }()) == 'Arguments';
  946.  
  947. module.exports = function(it){
  948. var O, T, B;
  949. return it === undefined ? 'Undefined' : it === null ? 'Null'
  950. // @@toStringTag case
  951. : typeof (T = (O = Object(it))[TAG]) == 'string' ? T
  952. // builtinTag case
  953. : ARG ? cof(O)
  954. // ES3 arguments fallback
  955. : (B = cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
  956. };
  957.  
  958. /***/ },
  959. /* 28 */
  960. /***/ function(module, exports) {
  961.  
  962. var toString = {}.toString;
  963.  
  964. module.exports = function(it){
  965. return toString.call(it).slice(8, -1);
  966. };
  967.  
  968. /***/ },
  969. /* 29 */
  970. /***/ function(module, exports, __webpack_require__) {
  971.  
  972. var ITERATOR = __webpack_require__(22)('iterator')
  973. , SAFE_CLOSING = false;
  974.  
  975. try {
  976. var riter = [7][ITERATOR]();
  977. riter['return'] = function(){ SAFE_CLOSING = true; };
  978. Array.from(riter, function(){ throw 2; });
  979. } catch(e){ /* empty */ }
  980.  
  981. module.exports = function(exec, skipClosing){
  982. if(!skipClosing && !SAFE_CLOSING)return false;
  983. var safe = false;
  984. try {
  985. var arr = [7]
  986. , iter = arr[ITERATOR]();
  987. iter.next = function(){ safe = true; };
  988. arr[ITERATOR] = function(){ return iter; };
  989. exec(arr);
  990. } catch(e){ /* empty */ }
  991. return safe;
  992. };
  993.  
  994. /***/ },
  995. /* 30 */
  996. /***/ function(module, exports, __webpack_require__) {
  997.  
  998. // 19.1.3.1 Object.assign(target, source)
  999. var $export = __webpack_require__(5);
  1000.  
  1001. $export($export.S + $export.F, 'Object', {assign: __webpack_require__(31)});
  1002.  
  1003. /***/ },
  1004. /* 31 */
  1005. /***/ function(module, exports, __webpack_require__) {
  1006.  
  1007. // 19.1.2.1 Object.assign(target, source, ...)
  1008. var $ = __webpack_require__(9)
  1009. , toObject = __webpack_require__(15)
  1010. , IObject = __webpack_require__(32);
  1011.  
  1012. // should work with symbols and should have deterministic property order (V8 bug)
  1013. module.exports = __webpack_require__(12)(function(){
  1014. var a = Object.assign
  1015. , A = {}
  1016. , B = {}
  1017. , S = Symbol()
  1018. , K = 'abcdefghijklmnopqrst';
  1019. A[S] = 7;
  1020. K.split('').forEach(function(k){ B[k] = k; });
  1021. return a({}, A)[S] != 7 || Object.keys(a({}, B)).join('') != K;
  1022. }) ? function assign(target, source){ // eslint-disable-line no-unused-vars
  1023. var T = toObject(target)
  1024. , $$ = arguments
  1025. , $$len = $$.length
  1026. , index = 1
  1027. , getKeys = $.getKeys
  1028. , getSymbols = $.getSymbols
  1029. , isEnum = $.isEnum;
  1030. while($$len > index){
  1031. var S = IObject($$[index++])
  1032. , keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)
  1033. , length = keys.length
  1034. , j = 0
  1035. , key;
  1036. while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];
  1037. }
  1038. return T;
  1039. } : Object.assign;
  1040.  
  1041. /***/ },
  1042. /* 32 */
  1043. /***/ function(module, exports, __webpack_require__) {
  1044.  
  1045. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  1046. var cof = __webpack_require__(28);
  1047. module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){
  1048. return cof(it) == 'String' ? it.split('') : Object(it);
  1049. };
  1050.  
  1051. /***/ },
  1052. /* 33 */,
  1053. /* 34 */,
  1054. /* 35 */,
  1055. /* 36 */,
  1056. /* 37 */,
  1057. /* 38 */,
  1058. /* 39 */,
  1059. /* 40 */,
  1060. /* 41 */,
  1061. /* 42 */
  1062. /***/ function(module, exports, __webpack_require__) {
  1063.  
  1064. 'use strict';
  1065.  
  1066. Object.defineProperty(exports, "__esModule", {
  1067. value: true
  1068. });
  1069.  
  1070. var _q = __webpack_require__(43);
  1071.  
  1072. var _q2 = _interopRequireDefault(_q);
  1073.  
  1074. var _main = __webpack_require__(46);
  1075.  
  1076. var _main2 = _interopRequireDefault(_main);
  1077.  
  1078. var _config = __webpack_require__(47);
  1079.  
  1080. var _config2 = _interopRequireDefault(_config);
  1081.  
  1082. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1083.  
  1084. var init = function init() {
  1085. new _main2.default(_config2.default.rules).all().then(function () {
  1086. return _q2.default.resolve(true);
  1087. }, function () {
  1088. return _q2.default.resolve(true);
  1089. }).then(function () {
  1090. new _main2.default(_config2.default.rules).oneByOne();
  1091. });
  1092. };
  1093.  
  1094. exports.default = init;
  1095.  
  1096. /***/ },
  1097. /* 43 */
  1098. /***/ function(module, exports, __webpack_require__) {
  1099.  
  1100. /* WEBPACK VAR INJECTION */(function(process, setImmediate) {// vim:ts=4:sts=4:sw=4:
  1101. /*!
  1102. *
  1103. * Copyright 2009-2012 Kris Kowal under the terms of the MIT
  1104. * license found at http://github.com/kriskowal/q/raw/master/LICENSE
  1105. *
  1106. * With parts by Tyler Close
  1107. * Copyright 2007-2009 Tyler Close under the terms of the MIT X license found
  1108. * at http://www.opensource.org/licenses/mit-license.html
  1109. * Forked at ref_send.js version: 2009-05-11
  1110. *
  1111. * With parts by Mark Miller
  1112. * Copyright (C) 2011 Google Inc.
  1113. *
  1114. * Licensed under the Apache License, Version 2.0 (the "License");
  1115. * you may not use this file except in compliance with the License.
  1116. * You may obtain a copy of the License at
  1117. *
  1118. * http://www.apache.org/licenses/LICENSE-2.0
  1119. *
  1120. * Unless required by applicable law or agreed to in writing, software
  1121. * distributed under the License is distributed on an "AS IS" BASIS,
  1122. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1123. * See the License for the specific language governing permissions and
  1124. * limitations under the License.
  1125. *
  1126. */
  1127.  
  1128. (function (definition) {
  1129. "use strict";
  1130.  
  1131. // This file will function properly as a <script> tag, or a module
  1132. // using CommonJS and NodeJS or RequireJS module formats. In
  1133. // Common/Node/RequireJS, the module exports the Q API and when
  1134. // executed as a simple <script>, it creates a Q global instead.
  1135.  
  1136. // Montage Require
  1137. if (typeof bootstrap === "function") {
  1138. bootstrap("promise", definition);
  1139.  
  1140. // CommonJS
  1141. } else if (true) {
  1142. module.exports = definition();
  1143.  
  1144. // RequireJS
  1145. } else if (typeof define === "function" && define.amd) {
  1146. define(definition);
  1147.  
  1148. // SES (Secure EcmaScript)
  1149. } else if (typeof ses !== "undefined") {
  1150. if (!ses.ok()) {
  1151. return;
  1152. } else {
  1153. ses.makeQ = definition;
  1154. }
  1155.  
  1156. // <script>
  1157. } else if (typeof window !== "undefined" || typeof self !== "undefined") {
  1158. // Prefer window over self for add-on scripts. Use self for
  1159. // non-windowed contexts.
  1160. var global = typeof window !== "undefined" ? window : self;
  1161.  
  1162. // Get the `window` object, save the previous Q global
  1163. // and initialize Q as a global.
  1164. var previousQ = global.Q;
  1165. global.Q = definition();
  1166.  
  1167. // Add a noConflict function so Q can be removed from the
  1168. // global namespace.
  1169. global.Q.noConflict = function () {
  1170. global.Q = previousQ;
  1171. return this;
  1172. };
  1173.  
  1174. } else {
  1175. throw new Error("This environment was not anticipated by Q. Please file a bug.");
  1176. }
  1177.  
  1178. })(function () {
  1179. "use strict";
  1180.  
  1181. var hasStacks = false;
  1182. try {
  1183. throw new Error();
  1184. } catch (e) {
  1185. hasStacks = !!e.stack;
  1186. }
  1187.  
  1188. // All code after this point will be filtered from stack traces reported
  1189. // by Q.
  1190. var qStartingLine = captureLine();
  1191. var qFileName;
  1192.  
  1193. // shims
  1194.  
  1195. // used for fallback in "allResolved"
  1196. var noop = function () {};
  1197.  
  1198. // Use the fastest possible means to execute a task in a future turn
  1199. // of the event loop.
  1200. var nextTick =(function () {
  1201. // linked list of tasks (single, with head node)
  1202. var head = {task: void 0, next: null};
  1203. var tail = head;
  1204. var flushing = false;
  1205. var requestTick = void 0;
  1206. var isNodeJS = false;
  1207. // queue for late tasks, used by unhandled rejection tracking
  1208. var laterQueue = [];
  1209.  
  1210. function flush() {
  1211. /* jshint loopfunc: true */
  1212. var task, domain;
  1213.  
  1214. while (head.next) {
  1215. head = head.next;
  1216. task = head.task;
  1217. head.task = void 0;
  1218. domain = head.domain;
  1219.  
  1220. if (domain) {
  1221. head.domain = void 0;
  1222. domain.enter();
  1223. }
  1224. runSingle(task, domain);
  1225.  
  1226. }
  1227. while (laterQueue.length) {
  1228. task = laterQueue.pop();
  1229. runSingle(task);
  1230. }
  1231. flushing = false;
  1232. }
  1233. // runs a single function in the async queue
  1234. function runSingle(task, domain) {
  1235. try {
  1236. task();
  1237.  
  1238. } catch (e) {
  1239. if (isNodeJS) {
  1240. // In node, uncaught exceptions are considered fatal errors.
  1241. // Re-throw them synchronously to interrupt flushing!
  1242.  
  1243. // Ensure continuation if the uncaught exception is suppressed
  1244. // listening "uncaughtException" events (as domains does).
  1245. // Continue in next event to avoid tick recursion.
  1246. if (domain) {
  1247. domain.exit();
  1248. }
  1249. setTimeout(flush, 0);
  1250. if (domain) {
  1251. domain.enter();
  1252. }
  1253.  
  1254. throw e;
  1255.  
  1256. } else {
  1257. // In browsers, uncaught exceptions are not fatal.
  1258. // Re-throw them asynchronously to avoid slow-downs.
  1259. setTimeout(function () {
  1260. throw e;
  1261. }, 0);
  1262. }
  1263. }
  1264.  
  1265. if (domain) {
  1266. domain.exit();
  1267. }
  1268. }
  1269.  
  1270. nextTick = function (task) {
  1271. tail = tail.next = {
  1272. task: task,
  1273. domain: isNodeJS && process.domain,
  1274. next: null
  1275. };
  1276.  
  1277. if (!flushing) {
  1278. flushing = true;
  1279. requestTick();
  1280. }
  1281. };
  1282.  
  1283. if (typeof process === "object" &&
  1284. process.toString() === "[object process]" && process.nextTick) {
  1285. // Ensure Q is in a real Node environment, with a `process.nextTick`.
  1286. // To see through fake Node environments:
  1287. // * Mocha test runner - exposes a `process` global without a `nextTick`
  1288. // * Browserify - exposes a `process.nexTick` function that uses
  1289. // `setTimeout`. In this case `setImmediate` is preferred because
  1290. // it is faster. Browserify's `process.toString()` yields
  1291. // "[object Object]", while in a real Node environment
  1292. // `process.nextTick()` yields "[object process]".
  1293. isNodeJS = true;
  1294.  
  1295. requestTick = function () {
  1296. process.nextTick(flush);
  1297. };
  1298.  
  1299. } else if (typeof setImmediate === "function") {
  1300. // In IE10, Node.js 0.9+, or https://github.com/NobleJS/setImmediate
  1301. if (typeof window !== "undefined") {
  1302. requestTick = setImmediate.bind(window, flush);
  1303. } else {
  1304. requestTick = function () {
  1305. setImmediate(flush);
  1306. };
  1307. }
  1308.  
  1309. } else if (typeof MessageChannel !== "undefined") {
  1310. // modern browsers
  1311. // http://www.nonblocking.io/2011/06/windownexttick.html
  1312. var channel = new MessageChannel();
  1313. // At least Safari Version 6.0.5 (8536.30.1) intermittently cannot create
  1314. // working message ports the first time a page loads.
  1315. channel.port1.onmessage = function () {
  1316. requestTick = requestPortTick;
  1317. channel.port1.onmessage = flush;
  1318. flush();
  1319. };
  1320. var requestPortTick = function () {
  1321. // Opera requires us to provide a message payload, regardless of
  1322. // whether we use it.
  1323. channel.port2.postMessage(0);
  1324. };
  1325. requestTick = function () {
  1326. setTimeout(flush, 0);
  1327. requestPortTick();
  1328. };
  1329.  
  1330. } else {
  1331. // old browsers
  1332. requestTick = function () {
  1333. setTimeout(flush, 0);
  1334. };
  1335. }
  1336. // runs a task after all other tasks have been run
  1337. // this is useful for unhandled rejection tracking that needs to happen
  1338. // after all `then`d tasks have been run.
  1339. nextTick.runAfter = function (task) {
  1340. laterQueue.push(task);
  1341. if (!flushing) {
  1342. flushing = true;
  1343. requestTick();
  1344. }
  1345. };
  1346. return nextTick;
  1347. })();
  1348.  
  1349. // Attempt to make generics safe in the face of downstream
  1350. // modifications.
  1351. // There is no situation where this is necessary.
  1352. // If you need a security guarantee, these primordials need to be
  1353. // deeply frozen anyway, and if you don’t need a security guarantee,
  1354. // this is just plain paranoid.
  1355. // However, this **might** have the nice side-effect of reducing the size of
  1356. // the minified code by reducing x.call() to merely x()
  1357. // See Mark Miller’s explanation of what this does.
  1358. // http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming
  1359. var call = Function.call;
  1360. function uncurryThis(f) {
  1361. return function () {
  1362. return call.apply(f, arguments);
  1363. };
  1364. }
  1365. // This is equivalent, but slower:
  1366. // uncurryThis = Function_bind.bind(Function_bind.call);
  1367. // http://jsperf.com/uncurrythis
  1368.  
  1369. var array_slice = uncurryThis(Array.prototype.slice);
  1370.  
  1371. var array_reduce = uncurryThis(
  1372. Array.prototype.reduce || function (callback, basis) {
  1373. var index = 0,
  1374. length = this.length;
  1375. // concerning the initial value, if one is not provided
  1376. if (arguments.length === 1) {
  1377. // seek to the first value in the array, accounting
  1378. // for the possibility that is is a sparse array
  1379. do {
  1380. if (index in this) {
  1381. basis = this[index++];
  1382. break;
  1383. }
  1384. if (++index >= length) {
  1385. throw new TypeError();
  1386. }
  1387. } while (1);
  1388. }
  1389. // reduce
  1390. for (; index < length; index++) {
  1391. // account for the possibility that the array is sparse
  1392. if (index in this) {
  1393. basis = callback(basis, this[index], index);
  1394. }
  1395. }
  1396. return basis;
  1397. }
  1398. );
  1399.  
  1400. var array_indexOf = uncurryThis(
  1401. Array.prototype.indexOf || function (value) {
  1402. // not a very good shim, but good enough for our one use of it
  1403. for (var i = 0; i < this.length; i++) {
  1404. if (this[i] === value) {
  1405. return i;
  1406. }
  1407. }
  1408. return -1;
  1409. }
  1410. );
  1411.  
  1412. var array_map = uncurryThis(
  1413. Array.prototype.map || function (callback, thisp) {
  1414. var self = this;
  1415. var collect = [];
  1416. array_reduce(self, function (undefined, value, index) {
  1417. collect.push(callback.call(thisp, value, index, self));
  1418. }, void 0);
  1419. return collect;
  1420. }
  1421. );
  1422.  
  1423. var object_create = Object.create || function (prototype) {
  1424. function Type() { }
  1425. Type.prototype = prototype;
  1426. return new Type();
  1427. };
  1428.  
  1429. var object_hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);
  1430.  
  1431. var object_keys = Object.keys || function (object) {
  1432. var keys = [];
  1433. for (var key in object) {
  1434. if (object_hasOwnProperty(object, key)) {
  1435. keys.push(key);
  1436. }
  1437. }
  1438. return keys;
  1439. };
  1440.  
  1441. var object_toString = uncurryThis(Object.prototype.toString);
  1442.  
  1443. function isObject(value) {
  1444. return value === Object(value);
  1445. }
  1446.  
  1447. // generator related shims
  1448.  
  1449. // FIXME: Remove this function once ES6 generators are in SpiderMonkey.
  1450. function isStopIteration(exception) {
  1451. return (
  1452. object_toString(exception) === "[object StopIteration]" ||
  1453. exception instanceof QReturnValue
  1454. );
  1455. }
  1456.  
  1457. // FIXME: Remove this helper and Q.return once ES6 generators are in
  1458. // SpiderMonkey.
  1459. var QReturnValue;
  1460. if (typeof ReturnValue !== "undefined") {
  1461. QReturnValue = ReturnValue;
  1462. } else {
  1463. QReturnValue = function (value) {
  1464. this.value = value;
  1465. };
  1466. }
  1467.  
  1468. // long stack traces
  1469.  
  1470. var STACK_JUMP_SEPARATOR = "From previous event:";
  1471.  
  1472. function makeStackTraceLong(error, promise) {
  1473. // If possible, transform the error stack trace by removing Node and Q
  1474. // cruft, then concatenating with the stack trace of `promise`. See #57.
  1475. if (hasStacks &&
  1476. promise.stack &&
  1477. typeof error === "object" &&
  1478. error !== null &&
  1479. error.stack &&
  1480. error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
  1481. ) {
  1482. var stacks = [];
  1483. for (var p = promise; !!p; p = p.source) {
  1484. if (p.stack) {
  1485. stacks.unshift(p.stack);
  1486. }
  1487. }
  1488. stacks.unshift(error.stack);
  1489.  
  1490. var concatedStacks = stacks.join("\n" + STACK_JUMP_SEPARATOR + "\n");
  1491. error.stack = filterStackString(concatedStacks);
  1492. }
  1493. }
  1494.  
  1495. function filterStackString(stackString) {
  1496. var lines = stackString.split("\n");
  1497. var desiredLines = [];
  1498. for (var i = 0; i < lines.length; ++i) {
  1499. var line = lines[i];
  1500.  
  1501. if (!isInternalFrame(line) && !isNodeFrame(line) && line) {
  1502. desiredLines.push(line);
  1503. }
  1504. }
  1505. return desiredLines.join("\n");
  1506. }
  1507.  
  1508. function isNodeFrame(stackLine) {
  1509. return stackLine.indexOf("(module.js:") !== -1 ||
  1510. stackLine.indexOf("(node.js:") !== -1;
  1511. }
  1512.  
  1513. function getFileNameAndLineNumber(stackLine) {
  1514. // Named functions: "at functionName (filename:lineNumber:columnNumber)"
  1515. // In IE10 function name can have spaces ("Anonymous function") O_o
  1516. var attempt1 = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(stackLine);
  1517. if (attempt1) {
  1518. return [attempt1[1], Number(attempt1[2])];
  1519. }
  1520.  
  1521. // Anonymous functions: "at filename:lineNumber:columnNumber"
  1522. var attempt2 = /at ([^ ]+):(\d+):(?:\d+)$/.exec(stackLine);
  1523. if (attempt2) {
  1524. return [attempt2[1], Number(attempt2[2])];
  1525. }
  1526.  
  1527. // Firefox style: "function@filename:lineNumber or @filename:lineNumber"
  1528. var attempt3 = /.*@(.+):(\d+)$/.exec(stackLine);
  1529. if (attempt3) {
  1530. return [attempt3[1], Number(attempt3[2])];
  1531. }
  1532. }
  1533.  
  1534. function isInternalFrame(stackLine) {
  1535. var fileNameAndLineNumber = getFileNameAndLineNumber(stackLine);
  1536.  
  1537. if (!fileNameAndLineNumber) {
  1538. return false;
  1539. }
  1540.  
  1541. var fileName = fileNameAndLineNumber[0];
  1542. var lineNumber = fileNameAndLineNumber[1];
  1543.  
  1544. return fileName === qFileName &&
  1545. lineNumber >= qStartingLine &&
  1546. lineNumber <= qEndingLine;
  1547. }
  1548.  
  1549. // discover own file name and line number range for filtering stack
  1550. // traces
  1551. function captureLine() {
  1552. if (!hasStacks) {
  1553. return;
  1554. }
  1555.  
  1556. try {
  1557. throw new Error();
  1558. } catch (e) {
  1559. var lines = e.stack.split("\n");
  1560. var firstLine = lines[0].indexOf("@") > 0 ? lines[1] : lines[2];
  1561. var fileNameAndLineNumber = getFileNameAndLineNumber(firstLine);
  1562. if (!fileNameAndLineNumber) {
  1563. return;
  1564. }
  1565.  
  1566. qFileName = fileNameAndLineNumber[0];
  1567. return fileNameAndLineNumber[1];
  1568. }
  1569. }
  1570.  
  1571. function deprecate(callback, name, alternative) {
  1572. return function () {
  1573. if (typeof console !== "undefined" &&
  1574. typeof console.warn === "function") {
  1575. console.warn(name + " is deprecated, use " + alternative +
  1576. " instead.", new Error("").stack);
  1577. }
  1578. return callback.apply(callback, arguments);
  1579. };
  1580. }
  1581.  
  1582. // end of shims
  1583. // beginning of real work
  1584.  
  1585. /**
  1586. * Constructs a promise for an immediate reference, passes promises through, or
  1587. * coerces promises from different systems.
  1588. * @param value immediate reference or promise
  1589. */
  1590. function Q(value) {
  1591. // If the object is already a Promise, return it directly. This enables
  1592. // the resolve function to both be used to created references from objects,
  1593. // but to tolerably coerce non-promises to promises.
  1594. if (value instanceof Promise) {
  1595. return value;
  1596. }
  1597.  
  1598. // assimilate thenables
  1599. if (isPromiseAlike(value)) {
  1600. return coerce(value);
  1601. } else {
  1602. return fulfill(value);
  1603. }
  1604. }
  1605. Q.resolve = Q;
  1606.  
  1607. /**
  1608. * Performs a task in a future turn of the event loop.
  1609. * @param {Function} task
  1610. */
  1611. Q.nextTick = nextTick;
  1612.  
  1613. /**
  1614. * Controls whether or not long stack traces will be on
  1615. */
  1616. Q.longStackSupport = false;
  1617.  
  1618. // enable long stacks if Q_DEBUG is set
  1619. if (typeof process === "object" && process && process.env && process.env.Q_DEBUG) {
  1620. Q.longStackSupport = true;
  1621. }
  1622.  
  1623. /**
  1624. * Constructs a {promise, resolve, reject} object.
  1625. *
  1626. * `resolve` is a callback to invoke with a more resolved value for the
  1627. * promise. To fulfill the promise, invoke `resolve` with any value that is
  1628. * not a thenable. To reject the promise, invoke `resolve` with a rejected
  1629. * thenable, or invoke `reject` with the reason directly. To resolve the
  1630. * promise to another thenable, thus putting it in the same state, invoke
  1631. * `resolve` with that other thenable.
  1632. */
  1633. Q.defer = defer;
  1634. function defer() {
  1635. // if "messages" is an "Array", that indicates that the promise has not yet
  1636. // been resolved. If it is "undefined", it has been resolved. Each
  1637. // element of the messages array is itself an array of complete arguments to
  1638. // forward to the resolved promise. We coerce the resolution value to a
  1639. // promise using the `resolve` function because it handles both fully
  1640. // non-thenable values and other thenables gracefully.
  1641. var messages = [], progressListeners = [], resolvedPromise;
  1642.  
  1643. var deferred = object_create(defer.prototype);
  1644. var promise = object_create(Promise.prototype);
  1645.  
  1646. promise.promiseDispatch = function (resolve, op, operands) {
  1647. var args = array_slice(arguments);
  1648. if (messages) {
  1649. messages.push(args);
  1650. if (op === "when" && operands[1]) { // progress operand
  1651. progressListeners.push(operands[1]);
  1652. }
  1653. } else {
  1654. Q.nextTick(function () {
  1655. resolvedPromise.promiseDispatch.apply(resolvedPromise, args);
  1656. });
  1657. }
  1658. };
  1659.  
  1660. // XXX deprecated
  1661. promise.valueOf = function () {
  1662. if (messages) {
  1663. return promise;
  1664. }
  1665. var nearerValue = nearer(resolvedPromise);
  1666. if (isPromise(nearerValue)) {
  1667. resolvedPromise = nearerValue; // shorten chain
  1668. }
  1669. return nearerValue;
  1670. };
  1671.  
  1672. promise.inspect = function () {
  1673. if (!resolvedPromise) {
  1674. return { state: "pending" };
  1675. }
  1676. return resolvedPromise.inspect();
  1677. };
  1678.  
  1679. if (Q.longStackSupport && hasStacks) {
  1680. try {
  1681. throw new Error();
  1682. } catch (e) {
  1683. // NOTE: don't try to use `Error.captureStackTrace` or transfer the
  1684. // accessor around; that causes memory leaks as per GH-111. Just
  1685. // reify the stack trace as a string ASAP.
  1686. //
  1687. // At the same time, cut off the first line; it's always just
  1688. // "[object Promise]\n", as per the `toString`.
  1689. promise.stack = e.stack.substring(e.stack.indexOf("\n") + 1);
  1690. }
  1691. }
  1692.  
  1693. // NOTE: we do the checks for `resolvedPromise` in each method, instead of
  1694. // consolidating them into `become`, since otherwise we'd create new
  1695. // promises with the lines `become(whatever(value))`. See e.g. GH-252.
  1696.  
  1697. function become(newPromise) {
  1698. resolvedPromise = newPromise;
  1699. promise.source = newPromise;
  1700.  
  1701. array_reduce(messages, function (undefined, message) {
  1702. Q.nextTick(function () {
  1703. newPromise.promiseDispatch.apply(newPromise, message);
  1704. });
  1705. }, void 0);
  1706.  
  1707. messages = void 0;
  1708. progressListeners = void 0;
  1709. }
  1710.  
  1711. deferred.promise = promise;
  1712. deferred.resolve = function (value) {
  1713. if (resolvedPromise) {
  1714. return;
  1715. }
  1716.  
  1717. become(Q(value));
  1718. };
  1719.  
  1720. deferred.fulfill = function (value) {
  1721. if (resolvedPromise) {
  1722. return;
  1723. }
  1724.  
  1725. become(fulfill(value));
  1726. };
  1727. deferred.reject = function (reason) {
  1728. if (resolvedPromise) {
  1729. return;
  1730. }
  1731.  
  1732. become(reject(reason));
  1733. };
  1734. deferred.notify = function (progress) {
  1735. if (resolvedPromise) {
  1736. return;
  1737. }
  1738.  
  1739. array_reduce(progressListeners, function (undefined, progressListener) {
  1740. Q.nextTick(function () {
  1741. progressListener(progress);
  1742. });
  1743. }, void 0);
  1744. };
  1745.  
  1746. return deferred;
  1747. }
  1748.  
  1749. /**
  1750. * Creates a Node-style callback that will resolve or reject the deferred
  1751. * promise.
  1752. * @returns a nodeback
  1753. */
  1754. defer.prototype.makeNodeResolver = function () {
  1755. var self = this;
  1756. return function (error, value) {
  1757. if (error) {
  1758. self.reject(error);
  1759. } else if (arguments.length > 2) {
  1760. self.resolve(array_slice(arguments, 1));
  1761. } else {
  1762. self.resolve(value);
  1763. }
  1764. };
  1765. };
  1766.  
  1767. /**
  1768. * @param resolver {Function} a function that returns nothing and accepts
  1769. * the resolve, reject, and notify functions for a deferred.
  1770. * @returns a promise that may be resolved with the given resolve and reject
  1771. * functions, or rejected by a thrown exception in resolver
  1772. */
  1773. Q.Promise = promise; // ES6
  1774. Q.promise = promise;
  1775. function promise(resolver) {
  1776. if (typeof resolver !== "function") {
  1777. throw new TypeError("resolver must be a function.");
  1778. }
  1779. var deferred = defer();
  1780. try {
  1781. resolver(deferred.resolve, deferred.reject, deferred.notify);
  1782. } catch (reason) {
  1783. deferred.reject(reason);
  1784. }
  1785. return deferred.promise;
  1786. }
  1787.  
  1788. promise.race = race; // ES6
  1789. promise.all = all; // ES6
  1790. promise.reject = reject; // ES6
  1791. promise.resolve = Q; // ES6
  1792.  
  1793. // XXX experimental. This method is a way to denote that a local value is
  1794. // serializable and should be immediately dispatched to a remote upon request,
  1795. // instead of passing a reference.
  1796. Q.passByCopy = function (object) {
  1797. //freeze(object);
  1798. //passByCopies.set(object, true);
  1799. return object;
  1800. };
  1801.  
  1802. Promise.prototype.passByCopy = function () {
  1803. //freeze(object);
  1804. //passByCopies.set(object, true);
  1805. return this;
  1806. };
  1807.  
  1808. /**
  1809. * If two promises eventually fulfill to the same value, promises that value,
  1810. * but otherwise rejects.
  1811. * @param x {Any*}
  1812. * @param y {Any*}
  1813. * @returns {Any*} a promise for x and y if they are the same, but a rejection
  1814. * otherwise.
  1815. *
  1816. */
  1817. Q.join = function (x, y) {
  1818. return Q(x).join(y);
  1819. };
  1820.  
  1821. Promise.prototype.join = function (that) {
  1822. return Q([this, that]).spread(function (x, y) {
  1823. if (x === y) {
  1824. // TODO: "===" should be Object.is or equiv
  1825. return x;
  1826. } else {
  1827. throw new Error("Can't join: not the same: " + x + " " + y);
  1828. }
  1829. });
  1830. };
  1831.  
  1832. /**
  1833. * Returns a promise for the first of an array of promises to become settled.
  1834. * @param answers {Array[Any*]} promises to race
  1835. * @returns {Any*} the first promise to be settled
  1836. */
  1837. Q.race = race;
  1838. function race(answerPs) {
  1839. return promise(function (resolve, reject) {
  1840. // Switch to this once we can assume at least ES5
  1841. // answerPs.forEach(function (answerP) {
  1842. // Q(answerP).then(resolve, reject);
  1843. // });
  1844. // Use this in the meantime
  1845. for (var i = 0, len = answerPs.length; i < len; i++) {
  1846. Q(answerPs[i]).then(resolve, reject);
  1847. }
  1848. });
  1849. }
  1850.  
  1851. Promise.prototype.race = function () {
  1852. return this.then(Q.race);
  1853. };
  1854.  
  1855. /**
  1856. * Constructs a Promise with a promise descriptor object and optional fallback
  1857. * function. The descriptor contains methods like when(rejected), get(name),
  1858. * set(name, value), post(name, args), and delete(name), which all
  1859. * return either a value, a promise for a value, or a rejection. The fallback
  1860. * accepts the operation name, a resolver, and any further arguments that would
  1861. * have been forwarded to the appropriate method above had a method been
  1862. * provided with the proper name. The API makes no guarantees about the nature
  1863. * of the returned object, apart from that it is usable whereever promises are
  1864. * bought and sold.
  1865. */
  1866. Q.makePromise = Promise;
  1867. function Promise(descriptor, fallback, inspect) {
  1868. if (fallback === void 0) {
  1869. fallback = function (op) {
  1870. return reject(new Error(
  1871. "Promise does not support operation: " + op
  1872. ));
  1873. };
  1874. }
  1875. if (inspect === void 0) {
  1876. inspect = function () {
  1877. return {state: "unknown"};
  1878. };
  1879. }
  1880.  
  1881. var promise = object_create(Promise.prototype);
  1882.  
  1883. promise.promiseDispatch = function (resolve, op, args) {
  1884. var result;
  1885. try {
  1886. if (descriptor[op]) {
  1887. result = descriptor[op].apply(promise, args);
  1888. } else {
  1889. result = fallback.call(promise, op, args);
  1890. }
  1891. } catch (exception) {
  1892. result = reject(exception);
  1893. }
  1894. if (resolve) {
  1895. resolve(result);
  1896. }
  1897. };
  1898.  
  1899. promise.inspect = inspect;
  1900.  
  1901. // XXX deprecated `valueOf` and `exception` support
  1902. if (inspect) {
  1903. var inspected = inspect();
  1904. if (inspected.state === "rejected") {
  1905. promise.exception = inspected.reason;
  1906. }
  1907.  
  1908. promise.valueOf = function () {
  1909. var inspected = inspect();
  1910. if (inspected.state === "pending" ||
  1911. inspected.state === "rejected") {
  1912. return promise;
  1913. }
  1914. return inspected.value;
  1915. };
  1916. }
  1917.  
  1918. return promise;
  1919. }
  1920.  
  1921. Promise.prototype.toString = function () {
  1922. return "[object Promise]";
  1923. };
  1924.  
  1925. Promise.prototype.then = function (fulfilled, rejected, progressed) {
  1926. var self = this;
  1927. var deferred = defer();
  1928. var done = false; // ensure the untrusted promise makes at most a
  1929. // single call to one of the callbacks
  1930.  
  1931. function _fulfilled(value) {
  1932. try {
  1933. return typeof fulfilled === "function" ? fulfilled(value) : value;
  1934. } catch (exception) {
  1935. return reject(exception);
  1936. }
  1937. }
  1938.  
  1939. function _rejected(exception) {
  1940. if (typeof rejected === "function") {
  1941. makeStackTraceLong(exception, self);
  1942. try {
  1943. return rejected(exception);
  1944. } catch (newException) {
  1945. return reject(newException);
  1946. }
  1947. }
  1948. return reject(exception);
  1949. }
  1950.  
  1951. function _progressed(value) {
  1952. return typeof progressed === "function" ? progressed(value) : value;
  1953. }
  1954.  
  1955. Q.nextTick(function () {
  1956. self.promiseDispatch(function (value) {
  1957. if (done) {
  1958. return;
  1959. }
  1960. done = true;
  1961.  
  1962. deferred.resolve(_fulfilled(value));
  1963. }, "when", [function (exception) {
  1964. if (done) {
  1965. return;
  1966. }
  1967. done = true;
  1968.  
  1969. deferred.resolve(_rejected(exception));
  1970. }]);
  1971. });
  1972.  
  1973. // Progress propagator need to be attached in the current tick.
  1974. self.promiseDispatch(void 0, "when", [void 0, function (value) {
  1975. var newValue;
  1976. var threw = false;
  1977. try {
  1978. newValue = _progressed(value);
  1979. } catch (e) {
  1980. threw = true;
  1981. if (Q.onerror) {
  1982. Q.onerror(e);
  1983. } else {
  1984. throw e;
  1985. }
  1986. }
  1987.  
  1988. if (!threw) {
  1989. deferred.notify(newValue);
  1990. }
  1991. }]);
  1992.  
  1993. return deferred.promise;
  1994. };
  1995.  
  1996. Q.tap = function (promise, callback) {
  1997. return Q(promise).tap(callback);
  1998. };
  1999.  
  2000. /**
  2001. * Works almost like "finally", but not called for rejections.
  2002. * Original resolution value is passed through callback unaffected.
  2003. * Callback may return a promise that will be awaited for.
  2004. * @param {Function} callback
  2005. * @returns {Q.Promise}
  2006. * @example
  2007. * doSomething()
  2008. * .then(...)
  2009. * .tap(console.log)
  2010. * .then(...);
  2011. */
  2012. Promise.prototype.tap = function (callback) {
  2013. callback = Q(callback);
  2014.  
  2015. return this.then(function (value) {
  2016. return callback.fcall(value).thenResolve(value);
  2017. });
  2018. };
  2019.  
  2020. /**
  2021. * Registers an observer on a promise.
  2022. *
  2023. * Guarantees:
  2024. *
  2025. * 1. that fulfilled and rejected will be called only once.
  2026. * 2. that either the fulfilled callback or the rejected callback will be
  2027. * called, but not both.
  2028. * 3. that fulfilled and rejected will not be called in this turn.
  2029. *
  2030. * @param value promise or immediate reference to observe
  2031. * @param fulfilled function to be called with the fulfilled value
  2032. * @param rejected function to be called with the rejection exception
  2033. * @param progressed function to be called on any progress notifications
  2034. * @return promise for the return value from the invoked callback
  2035. */
  2036. Q.when = when;
  2037. function when(value, fulfilled, rejected, progressed) {
  2038. return Q(value).then(fulfilled, rejected, progressed);
  2039. }
  2040.  
  2041. Promise.prototype.thenResolve = function (value) {
  2042. return this.then(function () { return value; });
  2043. };
  2044.  
  2045. Q.thenResolve = function (promise, value) {
  2046. return Q(promise).thenResolve(value);
  2047. };
  2048.  
  2049. Promise.prototype.thenReject = function (reason) {
  2050. return this.then(function () { throw reason; });
  2051. };
  2052.  
  2053. Q.thenReject = function (promise, reason) {
  2054. return Q(promise).thenReject(reason);
  2055. };
  2056.  
  2057. /**
  2058. * If an object is not a promise, it is as "near" as possible.
  2059. * If a promise is rejected, it is as "near" as possible too.
  2060. * If it’s a fulfilled promise, the fulfillment value is nearer.
  2061. * If it’s a deferred promise and the deferred has been resolved, the
  2062. * resolution is "nearer".
  2063. * @param object
  2064. * @returns most resolved (nearest) form of the object
  2065. */
  2066.  
  2067. // XXX should we re-do this?
  2068. Q.nearer = nearer;
  2069. function nearer(value) {
  2070. if (isPromise(value)) {
  2071. var inspected = value.inspect();
  2072. if (inspected.state === "fulfilled") {
  2073. return inspected.value;
  2074. }
  2075. }
  2076. return value;
  2077. }
  2078.  
  2079. /**
  2080. * @returns whether the given object is a promise.
  2081. * Otherwise it is a fulfilled value.
  2082. */
  2083. Q.isPromise = isPromise;
  2084. function isPromise(object) {
  2085. return object instanceof Promise;
  2086. }
  2087.  
  2088. Q.isPromiseAlike = isPromiseAlike;
  2089. function isPromiseAlike(object) {
  2090. return isObject(object) && typeof object.then === "function";
  2091. }
  2092.  
  2093. /**
  2094. * @returns whether the given object is a pending promise, meaning not
  2095. * fulfilled or rejected.
  2096. */
  2097. Q.isPending = isPending;
  2098. function isPending(object) {
  2099. return isPromise(object) && object.inspect().state === "pending";
  2100. }
  2101.  
  2102. Promise.prototype.isPending = function () {
  2103. return this.inspect().state === "pending";
  2104. };
  2105.  
  2106. /**
  2107. * @returns whether the given object is a value or fulfilled
  2108. * promise.
  2109. */
  2110. Q.isFulfilled = isFulfilled;
  2111. function isFulfilled(object) {
  2112. return !isPromise(object) || object.inspect().state === "fulfilled";
  2113. }
  2114.  
  2115. Promise.prototype.isFulfilled = function () {
  2116. return this.inspect().state === "fulfilled";
  2117. };
  2118.  
  2119. /**
  2120. * @returns whether the given object is a rejected promise.
  2121. */
  2122. Q.isRejected = isRejected;
  2123. function isRejected(object) {
  2124. return isPromise(object) && object.inspect().state === "rejected";
  2125. }
  2126.  
  2127. Promise.prototype.isRejected = function () {
  2128. return this.inspect().state === "rejected";
  2129. };
  2130.  
  2131. //// BEGIN UNHANDLED REJECTION TRACKING
  2132.  
  2133. // This promise library consumes exceptions thrown in handlers so they can be
  2134. // handled by a subsequent promise. The exceptions get added to this array when
  2135. // they are created, and removed when they are handled. Note that in ES6 or
  2136. // shimmed environments, this would naturally be a `Set`.
  2137. var unhandledReasons = [];
  2138. var unhandledRejections = [];
  2139. var reportedUnhandledRejections = [];
  2140. var trackUnhandledRejections = true;
  2141.  
  2142. function resetUnhandledRejections() {
  2143. unhandledReasons.length = 0;
  2144. unhandledRejections.length = 0;
  2145.  
  2146. if (!trackUnhandledRejections) {
  2147. trackUnhandledRejections = true;
  2148. }
  2149. }
  2150.  
  2151. function trackRejection(promise, reason) {
  2152. if (!trackUnhandledRejections) {
  2153. return;
  2154. }
  2155. if (typeof process === "object" && typeof process.emit === "function") {
  2156. Q.nextTick.runAfter(function () {
  2157. if (array_indexOf(unhandledRejections, promise) !== -1) {
  2158. process.emit("unhandledRejection", reason, promise);
  2159. reportedUnhandledRejections.push(promise);
  2160. }
  2161. });
  2162. }
  2163.  
  2164. unhandledRejections.push(promise);
  2165. if (reason && typeof reason.stack !== "undefined") {
  2166. unhandledReasons.push(reason.stack);
  2167. } else {
  2168. unhandledReasons.push("(no stack) " + reason);
  2169. }
  2170. }
  2171.  
  2172. function untrackRejection(promise) {
  2173. if (!trackUnhandledRejections) {
  2174. return;
  2175. }
  2176.  
  2177. var at = array_indexOf(unhandledRejections, promise);
  2178. if (at !== -1) {
  2179. if (typeof process === "object" && typeof process.emit === "function") {
  2180. Q.nextTick.runAfter(function () {
  2181. var atReport = array_indexOf(reportedUnhandledRejections, promise);
  2182. if (atReport !== -1) {
  2183. process.emit("rejectionHandled", unhandledReasons[at], promise);
  2184. reportedUnhandledRejections.splice(atReport, 1);
  2185. }
  2186. });
  2187. }
  2188. unhandledRejections.splice(at, 1);
  2189. unhandledReasons.splice(at, 1);
  2190. }
  2191. }
  2192.  
  2193. Q.resetUnhandledRejections = resetUnhandledRejections;
  2194.  
  2195. Q.getUnhandledReasons = function () {
  2196. // Make a copy so that consumers can't interfere with our internal state.
  2197. return unhandledReasons.slice();
  2198. };
  2199.  
  2200. Q.stopUnhandledRejectionTracking = function () {
  2201. resetUnhandledRejections();
  2202. trackUnhandledRejections = false;
  2203. };
  2204.  
  2205. resetUnhandledRejections();
  2206.  
  2207. //// END UNHANDLED REJECTION TRACKING
  2208.  
  2209. /**
  2210. * Constructs a rejected promise.
  2211. * @param reason value describing the failure
  2212. */
  2213. Q.reject = reject;
  2214. function reject(reason) {
  2215. var rejection = Promise({
  2216. "when": function (rejected) {
  2217. // note that the error has been handled
  2218. if (rejected) {
  2219. untrackRejection(this);
  2220. }
  2221. return rejected ? rejected(reason) : this;
  2222. }
  2223. }, function fallback() {
  2224. return this;
  2225. }, function inspect() {
  2226. return { state: "rejected", reason: reason };
  2227. });
  2228.  
  2229. // Note that the reason has not been handled.
  2230. trackRejection(rejection, reason);
  2231.  
  2232. return rejection;
  2233. }
  2234.  
  2235. /**
  2236. * Constructs a fulfilled promise for an immediate reference.
  2237. * @param value immediate reference
  2238. */
  2239. Q.fulfill = fulfill;
  2240. function fulfill(value) {
  2241. return Promise({
  2242. "when": function () {
  2243. return value;
  2244. },
  2245. "get": function (name) {
  2246. return value[name];
  2247. },
  2248. "set": function (name, rhs) {
  2249. value[name] = rhs;
  2250. },
  2251. "delete": function (name) {
  2252. delete value[name];
  2253. },
  2254. "post": function (name, args) {
  2255. // Mark Miller proposes that post with no name should apply a
  2256. // promised function.
  2257. if (name === null || name === void 0) {
  2258. return value.apply(void 0, args);
  2259. } else {
  2260. return value[name].apply(value, args);
  2261. }
  2262. },
  2263. "apply": function (thisp, args) {
  2264. return value.apply(thisp, args);
  2265. },
  2266. "keys": function () {
  2267. return object_keys(value);
  2268. }
  2269. }, void 0, function inspect() {
  2270. return { state: "fulfilled", value: value };
  2271. });
  2272. }
  2273.  
  2274. /**
  2275. * Converts thenables to Q promises.
  2276. * @param promise thenable promise
  2277. * @returns a Q promise
  2278. */
  2279. function coerce(promise) {
  2280. var deferred = defer();
  2281. Q.nextTick(function () {
  2282. try {
  2283. promise.then(deferred.resolve, deferred.reject, deferred.notify);
  2284. } catch (exception) {
  2285. deferred.reject(exception);
  2286. }
  2287. });
  2288. return deferred.promise;
  2289. }
  2290.  
  2291. /**
  2292. * Annotates an object such that it will never be
  2293. * transferred away from this process over any promise
  2294. * communication channel.
  2295. * @param object
  2296. * @returns promise a wrapping of that object that
  2297. * additionally responds to the "isDef" message
  2298. * without a rejection.
  2299. */
  2300. Q.master = master;
  2301. function master(object) {
  2302. return Promise({
  2303. "isDef": function () {}
  2304. }, function fallback(op, args) {
  2305. return dispatch(object, op, args);
  2306. }, function () {
  2307. return Q(object).inspect();
  2308. });
  2309. }
  2310.  
  2311. /**
  2312. * Spreads the values of a promised array of arguments into the
  2313. * fulfillment callback.
  2314. * @param fulfilled callback that receives variadic arguments from the
  2315. * promised array
  2316. * @param rejected callback that receives the exception if the promise
  2317. * is rejected.
  2318. * @returns a promise for the return value or thrown exception of
  2319. * either callback.
  2320. */
  2321. Q.spread = spread;
  2322. function spread(value, fulfilled, rejected) {
  2323. return Q(value).spread(fulfilled, rejected);
  2324. }
  2325.  
  2326. Promise.prototype.spread = function (fulfilled, rejected) {
  2327. return this.all().then(function (array) {
  2328. return fulfilled.apply(void 0, array);
  2329. }, rejected);
  2330. };
  2331.  
  2332. /**
  2333. * The async function is a decorator for generator functions, turning
  2334. * them into asynchronous generators. Although generators are only part
  2335. * of the newest ECMAScript 6 drafts, this code does not cause syntax
  2336. * errors in older engines. This code should continue to work and will
  2337. * in fact improve over time as the language improves.
  2338. *
  2339. * ES6 generators are currently part of V8 version 3.19 with the
  2340. * --harmony-generators runtime flag enabled. SpiderMonkey has had them
  2341. * for longer, but under an older Python-inspired form. This function
  2342. * works on both kinds of generators.
  2343. *
  2344. * Decorates a generator function such that:
  2345. * - it may yield promises
  2346. * - execution will continue when that promise is fulfilled
  2347. * - the value of the yield expression will be the fulfilled value
  2348. * - it returns a promise for the return value (when the generator
  2349. * stops iterating)
  2350. * - the decorated function returns a promise for the return value
  2351. * of the generator or the first rejected promise among those
  2352. * yielded.
  2353. * - if an error is thrown in the generator, it propagates through
  2354. * every following yield until it is caught, or until it escapes
  2355. * the generator function altogether, and is translated into a
  2356. * rejection for the promise returned by the decorated generator.
  2357. */
  2358. Q.async = async;
  2359. function async(makeGenerator) {
  2360. return function () {
  2361. // when verb is "send", arg is a value
  2362. // when verb is "throw", arg is an exception
  2363. function continuer(verb, arg) {
  2364. var result;
  2365.  
  2366. // Until V8 3.19 / Chromium 29 is released, SpiderMonkey is the only
  2367. // engine that has a deployed base of browsers that support generators.
  2368. // However, SM's generators use the Python-inspired semantics of
  2369. // outdated ES6 drafts. We would like to support ES6, but we'd also
  2370. // like to make it possible to use generators in deployed browsers, so
  2371. // we also support Python-style generators. At some point we can remove
  2372. // this block.
  2373.  
  2374. if (typeof StopIteration === "undefined") {
  2375. // ES6 Generators
  2376. try {
  2377. result = generator[verb](arg);
  2378. } catch (exception) {
  2379. return reject(exception);
  2380. }
  2381. if (result.done) {
  2382. return Q(result.value);
  2383. } else {
  2384. return when(result.value, callback, errback);
  2385. }
  2386. } else {
  2387. // SpiderMonkey Generators
  2388. // FIXME: Remove this case when SM does ES6 generators.
  2389. try {
  2390. result = generator[verb](arg);
  2391. } catch (exception) {
  2392. if (isStopIteration(exception)) {
  2393. return Q(exception.value);
  2394. } else {
  2395. return reject(exception);
  2396. }
  2397. }
  2398. return when(result, callback, errback);
  2399. }
  2400. }
  2401. var generator = makeGenerator.apply(this, arguments);
  2402. var callback = continuer.bind(continuer, "next");
  2403. var errback = continuer.bind(continuer, "throw");
  2404. return callback();
  2405. };
  2406. }
  2407.  
  2408. /**
  2409. * The spawn function is a small wrapper around async that immediately
  2410. * calls the generator and also ends the promise chain, so that any
  2411. * unhandled errors are thrown instead of forwarded to the error
  2412. * handler. This is useful because it's extremely common to run
  2413. * generators at the top-level to work with libraries.
  2414. */
  2415. Q.spawn = spawn;
  2416. function spawn(makeGenerator) {
  2417. Q.done(Q.async(makeGenerator)());
  2418. }
  2419.  
  2420. // FIXME: Remove this interface once ES6 generators are in SpiderMonkey.
  2421. /**
  2422. * Throws a ReturnValue exception to stop an asynchronous generator.
  2423. *
  2424. * This interface is a stop-gap measure to support generator return
  2425. * values in older Firefox/SpiderMonkey. In browsers that support ES6
  2426. * generators like Chromium 29, just use "return" in your generator
  2427. * functions.
  2428. *
  2429. * @param value the return value for the surrounding generator
  2430. * @throws ReturnValue exception with the value.
  2431. * @example
  2432. * // ES6 style
  2433. * Q.async(function* () {
  2434. * var foo = yield getFooPromise();
  2435. * var bar = yield getBarPromise();
  2436. * return foo + bar;
  2437. * })
  2438. * // Older SpiderMonkey style
  2439. * Q.async(function () {
  2440. * var foo = yield getFooPromise();
  2441. * var bar = yield getBarPromise();
  2442. * Q.return(foo + bar);
  2443. * })
  2444. */
  2445. Q["return"] = _return;
  2446. function _return(value) {
  2447. throw new QReturnValue(value);
  2448. }
  2449.  
  2450. /**
  2451. * The promised function decorator ensures that any promise arguments
  2452. * are settled and passed as values (`this` is also settled and passed
  2453. * as a value). It will also ensure that the result of a function is
  2454. * always a promise.
  2455. *
  2456. * @example
  2457. * var add = Q.promised(function (a, b) {
  2458. * return a + b;
  2459. * });
  2460. * add(Q(a), Q(B));
  2461. *
  2462. * @param {function} callback The function to decorate
  2463. * @returns {function} a function that has been decorated.
  2464. */
  2465. Q.promised = promised;
  2466. function promised(callback) {
  2467. return function () {
  2468. return spread([this, all(arguments)], function (self, args) {
  2469. return callback.apply(self, args);
  2470. });
  2471. };
  2472. }
  2473.  
  2474. /**
  2475. * sends a message to a value in a future turn
  2476. * @param object* the recipient
  2477. * @param op the name of the message operation, e.g., "when",
  2478. * @param args further arguments to be forwarded to the operation
  2479. * @returns result {Promise} a promise for the result of the operation
  2480. */
  2481. Q.dispatch = dispatch;
  2482. function dispatch(object, op, args) {
  2483. return Q(object).dispatch(op, args);
  2484. }
  2485.  
  2486. Promise.prototype.dispatch = function (op, args) {
  2487. var self = this;
  2488. var deferred = defer();
  2489. Q.nextTick(function () {
  2490. self.promiseDispatch(deferred.resolve, op, args);
  2491. });
  2492. return deferred.promise;
  2493. };
  2494.  
  2495. /**
  2496. * Gets the value of a property in a future turn.
  2497. * @param object promise or immediate reference for target object
  2498. * @param name name of property to get
  2499. * @return promise for the property value
  2500. */
  2501. Q.get = function (object, key) {
  2502. return Q(object).dispatch("get", [key]);
  2503. };
  2504.  
  2505. Promise.prototype.get = function (key) {
  2506. return this.dispatch("get", [key]);
  2507. };
  2508.  
  2509. /**
  2510. * Sets the value of a property in a future turn.
  2511. * @param object promise or immediate reference for object object
  2512. * @param name name of property to set
  2513. * @param value new value of property
  2514. * @return promise for the return value
  2515. */
  2516. Q.set = function (object, key, value) {
  2517. return Q(object).dispatch("set", [key, value]);
  2518. };
  2519.  
  2520. Promise.prototype.set = function (key, value) {
  2521. return this.dispatch("set", [key, value]);
  2522. };
  2523.  
  2524. /**
  2525. * Deletes a property in a future turn.
  2526. * @param object promise or immediate reference for target object
  2527. * @param name name of property to delete
  2528. * @return promise for the return value
  2529. */
  2530. Q.del = // XXX legacy
  2531. Q["delete"] = function (object, key) {
  2532. return Q(object).dispatch("delete", [key]);
  2533. };
  2534.  
  2535. Promise.prototype.del = // XXX legacy
  2536. Promise.prototype["delete"] = function (key) {
  2537. return this.dispatch("delete", [key]);
  2538. };
  2539.  
  2540. /**
  2541. * Invokes a method in a future turn.
  2542. * @param object promise or immediate reference for target object
  2543. * @param name name of method to invoke
  2544. * @param value a value to post, typically an array of
  2545. * invocation arguments for promises that
  2546. * are ultimately backed with `resolve` values,
  2547. * as opposed to those backed with URLs
  2548. * wherein the posted value can be any
  2549. * JSON serializable object.
  2550. * @return promise for the return value
  2551. */
  2552. // bound locally because it is used by other methods
  2553. Q.mapply = // XXX As proposed by "Redsandro"
  2554. Q.post = function (object, name, args) {
  2555. return Q(object).dispatch("post", [name, args]);
  2556. };
  2557.  
  2558. Promise.prototype.mapply = // XXX As proposed by "Redsandro"
  2559. Promise.prototype.post = function (name, args) {
  2560. return this.dispatch("post", [name, args]);
  2561. };
  2562.  
  2563. /**
  2564. * Invokes a method in a future turn.
  2565. * @param object promise or immediate reference for target object
  2566. * @param name name of method to invoke
  2567. * @param ...args array of invocation arguments
  2568. * @return promise for the return value
  2569. */
  2570. Q.send = // XXX Mark Miller's proposed parlance
  2571. Q.mcall = // XXX As proposed by "Redsandro"
  2572. Q.invoke = function (object, name /*...args*/) {
  2573. return Q(object).dispatch("post", [name, array_slice(arguments, 2)]);
  2574. };
  2575.  
  2576. Promise.prototype.send = // XXX Mark Miller's proposed parlance
  2577. Promise.prototype.mcall = // XXX As proposed by "Redsandro"
  2578. Promise.prototype.invoke = function (name /*...args*/) {
  2579. return this.dispatch("post", [name, array_slice(arguments, 1)]);
  2580. };
  2581.  
  2582. /**
  2583. * Applies the promised function in a future turn.
  2584. * @param object promise or immediate reference for target function
  2585. * @param args array of application arguments
  2586. */
  2587. Q.fapply = function (object, args) {
  2588. return Q(object).dispatch("apply", [void 0, args]);
  2589. };
  2590.  
  2591. Promise.prototype.fapply = function (args) {
  2592. return this.dispatch("apply", [void 0, args]);
  2593. };
  2594.  
  2595. /**
  2596. * Calls the promised function in a future turn.
  2597. * @param object promise or immediate reference for target function
  2598. * @param ...args array of application arguments
  2599. */
  2600. Q["try"] =
  2601. Q.fcall = function (object /* ...args*/) {
  2602. return Q(object).dispatch("apply", [void 0, array_slice(arguments, 1)]);
  2603. };
  2604.  
  2605. Promise.prototype.fcall = function (/*...args*/) {
  2606. return this.dispatch("apply", [void 0, array_slice(arguments)]);
  2607. };
  2608.  
  2609. /**
  2610. * Binds the promised function, transforming return values into a fulfilled
  2611. * promise and thrown errors into a rejected one.
  2612. * @param object promise or immediate reference for target function
  2613. * @param ...args array of application arguments
  2614. */
  2615. Q.fbind = function (object /*...args*/) {
  2616. var promise = Q(object);
  2617. var args = array_slice(arguments, 1);
  2618. return function fbound() {
  2619. return promise.dispatch("apply", [
  2620. this,
  2621. args.concat(array_slice(arguments))
  2622. ]);
  2623. };
  2624. };
  2625. Promise.prototype.fbind = function (/*...args*/) {
  2626. var promise = this;
  2627. var args = array_slice(arguments);
  2628. return function fbound() {
  2629. return promise.dispatch("apply", [
  2630. this,
  2631. args.concat(array_slice(arguments))
  2632. ]);
  2633. };
  2634. };
  2635.  
  2636. /**
  2637. * Requests the names of the owned properties of a promised
  2638. * object in a future turn.
  2639. * @param object promise or immediate reference for target object
  2640. * @return promise for the keys of the eventually settled object
  2641. */
  2642. Q.keys = function (object) {
  2643. return Q(object).dispatch("keys", []);
  2644. };
  2645.  
  2646. Promise.prototype.keys = function () {
  2647. return this.dispatch("keys", []);
  2648. };
  2649.  
  2650. /**
  2651. * Turns an array of promises into a promise for an array. If any of
  2652. * the promises gets rejected, the whole array is rejected immediately.
  2653. * @param {Array*} an array (or promise for an array) of values (or
  2654. * promises for values)
  2655. * @returns a promise for an array of the corresponding values
  2656. */
  2657. // By Mark Miller
  2658. // http://wiki.ecmascript.org/doku.php?id=strawman:concurrency&rev=1308776521#allfulfilled
  2659. Q.all = all;
  2660. function all(promises) {
  2661. return when(promises, function (promises) {
  2662. var pendingCount = 0;
  2663. var deferred = defer();
  2664. array_reduce(promises, function (undefined, promise, index) {
  2665. var snapshot;
  2666. if (
  2667. isPromise(promise) &&
  2668. (snapshot = promise.inspect()).state === "fulfilled"
  2669. ) {
  2670. promises[index] = snapshot.value;
  2671. } else {
  2672. ++pendingCount;
  2673. when(
  2674. promise,
  2675. function (value) {
  2676. promises[index] = value;
  2677. if (--pendingCount === 0) {
  2678. deferred.resolve(promises);
  2679. }
  2680. },
  2681. deferred.reject,
  2682. function (progress) {
  2683. deferred.notify({ index: index, value: progress });
  2684. }
  2685. );
  2686. }
  2687. }, void 0);
  2688. if (pendingCount === 0) {
  2689. deferred.resolve(promises);
  2690. }
  2691. return deferred.promise;
  2692. });
  2693. }
  2694.  
  2695. Promise.prototype.all = function () {
  2696. return all(this);
  2697. };
  2698.  
  2699. /**
  2700. * Returns the first resolved promise of an array. Prior rejected promises are
  2701. * ignored. Rejects only if all promises are rejected.
  2702. * @param {Array*} an array containing values or promises for values
  2703. * @returns a promise fulfilled with the value of the first resolved promise,
  2704. * or a rejected promise if all promises are rejected.
  2705. */
  2706. Q.any = any;
  2707.  
  2708. function any(promises) {
  2709. if (promises.length === 0) {
  2710. return Q.resolve();
  2711. }
  2712.  
  2713. var deferred = Q.defer();
  2714. var pendingCount = 0;
  2715. array_reduce(promises, function (prev, current, index) {
  2716. var promise = promises[index];
  2717.  
  2718. pendingCount++;
  2719.  
  2720. when(promise, onFulfilled, onRejected, onProgress);
  2721. function onFulfilled(result) {
  2722. deferred.resolve(result);
  2723. }
  2724. function onRejected() {
  2725. pendingCount--;
  2726. if (pendingCount === 0) {
  2727. deferred.reject(new Error(
  2728. "Can't get fulfillment value from any promise, all " +
  2729. "promises were rejected."
  2730. ));
  2731. }
  2732. }
  2733. function onProgress(progress) {
  2734. deferred.notify({
  2735. index: index,
  2736. value: progress
  2737. });
  2738. }
  2739. }, undefined);
  2740.  
  2741. return deferred.promise;
  2742. }
  2743.  
  2744. Promise.prototype.any = function () {
  2745. return any(this);
  2746. };
  2747.  
  2748. /**
  2749. * Waits for all promises to be settled, either fulfilled or
  2750. * rejected. This is distinct from `all` since that would stop
  2751. * waiting at the first rejection. The promise returned by
  2752. * `allResolved` will never be rejected.
  2753. * @param promises a promise for an array (or an array) of promises
  2754. * (or values)
  2755. * @return a promise for an array of promises
  2756. */
  2757. Q.allResolved = deprecate(allResolved, "allResolved", "allSettled");
  2758. function allResolved(promises) {
  2759. return when(promises, function (promises) {
  2760. promises = array_map(promises, Q);
  2761. return when(all(array_map(promises, function (promise) {
  2762. return when(promise, noop, noop);
  2763. })), function () {
  2764. return promises;
  2765. });
  2766. });
  2767. }
  2768.  
  2769. Promise.prototype.allResolved = function () {
  2770. return allResolved(this);
  2771. };
  2772.  
  2773. /**
  2774. * @see Promise#allSettled
  2775. */
  2776. Q.allSettled = allSettled;
  2777. function allSettled(promises) {
  2778. return Q(promises).allSettled();
  2779. }
  2780.  
  2781. /**
  2782. * Turns an array of promises into a promise for an array of their states (as
  2783. * returned by `inspect`) when they have all settled.
  2784. * @param {Array[Any*]} values an array (or promise for an array) of values (or
  2785. * promises for values)
  2786. * @returns {Array[State]} an array of states for the respective values.
  2787. */
  2788. Promise.prototype.allSettled = function () {
  2789. return this.then(function (promises) {
  2790. return all(array_map(promises, function (promise) {
  2791. promise = Q(promise);
  2792. function regardless() {
  2793. return promise.inspect();
  2794. }
  2795. return promise.then(regardless, regardless);
  2796. }));
  2797. });
  2798. };
  2799.  
  2800. /**
  2801. * Captures the failure of a promise, giving an oportunity to recover
  2802. * with a callback. If the given promise is fulfilled, the returned
  2803. * promise is fulfilled.
  2804. * @param {Any*} promise for something
  2805. * @param {Function} callback to fulfill the returned promise if the
  2806. * given promise is rejected
  2807. * @returns a promise for the return value of the callback
  2808. */
  2809. Q.fail = // XXX legacy
  2810. Q["catch"] = function (object, rejected) {
  2811. return Q(object).then(void 0, rejected);
  2812. };
  2813.  
  2814. Promise.prototype.fail = // XXX legacy
  2815. Promise.prototype["catch"] = function (rejected) {
  2816. return this.then(void 0, rejected);
  2817. };
  2818.  
  2819. /**
  2820. * Attaches a listener that can respond to progress notifications from a
  2821. * promise's originating deferred. This listener receives the exact arguments
  2822. * passed to ``deferred.notify``.
  2823. * @param {Any*} promise for something
  2824. * @param {Function} callback to receive any progress notifications
  2825. * @returns the given promise, unchanged
  2826. */
  2827. Q.progress = progress;
  2828. function progress(object, progressed) {
  2829. return Q(object).then(void 0, void 0, progressed);
  2830. }
  2831.  
  2832. Promise.prototype.progress = function (progressed) {
  2833. return this.then(void 0, void 0, progressed);
  2834. };
  2835.  
  2836. /**
  2837. * Provides an opportunity to observe the settling of a promise,
  2838. * regardless of whether the promise is fulfilled or rejected. Forwards
  2839. * the resolution to the returned promise when the callback is done.
  2840. * The callback can return a promise to defer completion.
  2841. * @param {Any*} promise
  2842. * @param {Function} callback to observe the resolution of the given
  2843. * promise, takes no arguments.
  2844. * @returns a promise for the resolution of the given promise when
  2845. * ``fin`` is done.
  2846. */
  2847. Q.fin = // XXX legacy
  2848. Q["finally"] = function (object, callback) {
  2849. return Q(object)["finally"](callback);
  2850. };
  2851.  
  2852. Promise.prototype.fin = // XXX legacy
  2853. Promise.prototype["finally"] = function (callback) {
  2854. callback = Q(callback);
  2855. return this.then(function (value) {
  2856. return callback.fcall().then(function () {
  2857. return value;
  2858. });
  2859. }, function (reason) {
  2860. // TODO attempt to recycle the rejection with "this".
  2861. return callback.fcall().then(function () {
  2862. throw reason;
  2863. });
  2864. });
  2865. };
  2866.  
  2867. /**
  2868. * Terminates a chain of promises, forcing rejections to be
  2869. * thrown as exceptions.
  2870. * @param {Any*} promise at the end of a chain of promises
  2871. * @returns nothing
  2872. */
  2873. Q.done = function (object, fulfilled, rejected, progress) {
  2874. return Q(object).done(fulfilled, rejected, progress);
  2875. };
  2876.  
  2877. Promise.prototype.done = function (fulfilled, rejected, progress) {
  2878. var onUnhandledError = function (error) {
  2879. // forward to a future turn so that ``when``
  2880. // does not catch it and turn it into a rejection.
  2881. Q.nextTick(function () {
  2882. makeStackTraceLong(error, promise);
  2883. if (Q.onerror) {
  2884. Q.onerror(error);
  2885. } else {
  2886. throw error;
  2887. }
  2888. });
  2889. };
  2890.  
  2891. // Avoid unnecessary `nextTick`ing via an unnecessary `when`.
  2892. var promise = fulfilled || rejected || progress ?
  2893. this.then(fulfilled, rejected, progress) :
  2894. this;
  2895.  
  2896. if (typeof process === "object" && process && process.domain) {
  2897. onUnhandledError = process.domain.bind(onUnhandledError);
  2898. }
  2899.  
  2900. promise.then(void 0, onUnhandledError);
  2901. };
  2902.  
  2903. /**
  2904. * Causes a promise to be rejected if it does not get fulfilled before
  2905. * some milliseconds time out.
  2906. * @param {Any*} promise
  2907. * @param {Number} milliseconds timeout
  2908. * @param {Any*} custom error message or Error object (optional)
  2909. * @returns a promise for the resolution of the given promise if it is
  2910. * fulfilled before the timeout, otherwise rejected.
  2911. */
  2912. Q.timeout = function (object, ms, error) {
  2913. return Q(object).timeout(ms, error);
  2914. };
  2915.  
  2916. Promise.prototype.timeout = function (ms, error) {
  2917. var deferred = defer();
  2918. var timeoutId = setTimeout(function () {
  2919. if (!error || "string" === typeof error) {
  2920. error = new Error(error || "Timed out after " + ms + " ms");
  2921. error.code = "ETIMEDOUT";
  2922. }
  2923. deferred.reject(error);
  2924. }, ms);
  2925.  
  2926. this.then(function (value) {
  2927. clearTimeout(timeoutId);
  2928. deferred.resolve(value);
  2929. }, function (exception) {
  2930. clearTimeout(timeoutId);
  2931. deferred.reject(exception);
  2932. }, deferred.notify);
  2933.  
  2934. return deferred.promise;
  2935. };
  2936.  
  2937. /**
  2938. * Returns a promise for the given value (or promised value), some
  2939. * milliseconds after it resolved. Passes rejections immediately.
  2940. * @param {Any*} promise
  2941. * @param {Number} milliseconds
  2942. * @returns a promise for the resolution of the given promise after milliseconds
  2943. * time has elapsed since the resolution of the given promise.
  2944. * If the given promise rejects, that is passed immediately.
  2945. */
  2946. Q.delay = function (object, timeout) {
  2947. if (timeout === void 0) {
  2948. timeout = object;
  2949. object = void 0;
  2950. }
  2951. return Q(object).delay(timeout);
  2952. };
  2953.  
  2954. Promise.prototype.delay = function (timeout) {
  2955. return this.then(function (value) {
  2956. var deferred = defer();
  2957. setTimeout(function () {
  2958. deferred.resolve(value);
  2959. }, timeout);
  2960. return deferred.promise;
  2961. });
  2962. };
  2963.  
  2964. /**
  2965. * Passes a continuation to a Node function, which is called with the given
  2966. * arguments provided as an array, and returns a promise.
  2967. *
  2968. * Q.nfapply(FS.readFile, [__filename])
  2969. * .then(function (content) {
  2970. * })
  2971. *
  2972. */
  2973. Q.nfapply = function (callback, args) {
  2974. return Q(callback).nfapply(args);
  2975. };
  2976.  
  2977. Promise.prototype.nfapply = function (args) {
  2978. var deferred = defer();
  2979. var nodeArgs = array_slice(args);
  2980. nodeArgs.push(deferred.makeNodeResolver());
  2981. this.fapply(nodeArgs).fail(deferred.reject);
  2982. return deferred.promise;
  2983. };
  2984.  
  2985. /**
  2986. * Passes a continuation to a Node function, which is called with the given
  2987. * arguments provided individually, and returns a promise.
  2988. * @example
  2989. * Q.nfcall(FS.readFile, __filename)
  2990. * .then(function (content) {
  2991. * })
  2992. *
  2993. */
  2994. Q.nfcall = function (callback /*...args*/) {
  2995. var args = array_slice(arguments, 1);
  2996. return Q(callback).nfapply(args);
  2997. };
  2998.  
  2999. Promise.prototype.nfcall = function (/*...args*/) {
  3000. var nodeArgs = array_slice(arguments);
  3001. var deferred = defer();
  3002. nodeArgs.push(deferred.makeNodeResolver());
  3003. this.fapply(nodeArgs).fail(deferred.reject);
  3004. return deferred.promise;
  3005. };
  3006.  
  3007. /**
  3008. * Wraps a NodeJS continuation passing function and returns an equivalent
  3009. * version that returns a promise.
  3010. * @example
  3011. * Q.nfbind(FS.readFile, __filename)("utf-8")
  3012. * .then(console.log)
  3013. * .done()
  3014. */
  3015. Q.nfbind =
  3016. Q.denodeify = function (callback /*...args*/) {
  3017. var baseArgs = array_slice(arguments, 1);
  3018. return function () {
  3019. var nodeArgs = baseArgs.concat(array_slice(arguments));
  3020. var deferred = defer();
  3021. nodeArgs.push(deferred.makeNodeResolver());
  3022. Q(callback).fapply(nodeArgs).fail(deferred.reject);
  3023. return deferred.promise;
  3024. };
  3025. };
  3026.  
  3027. Promise.prototype.nfbind =
  3028. Promise.prototype.denodeify = function (/*...args*/) {
  3029. var args = array_slice(arguments);
  3030. args.unshift(this);
  3031. return Q.denodeify.apply(void 0, args);
  3032. };
  3033.  
  3034. Q.nbind = function (callback, thisp /*...args*/) {
  3035. var baseArgs = array_slice(arguments, 2);
  3036. return function () {
  3037. var nodeArgs = baseArgs.concat(array_slice(arguments));
  3038. var deferred = defer();
  3039. nodeArgs.push(deferred.makeNodeResolver());
  3040. function bound() {
  3041. return callback.apply(thisp, arguments);
  3042. }
  3043. Q(bound).fapply(nodeArgs).fail(deferred.reject);
  3044. return deferred.promise;
  3045. };
  3046. };
  3047.  
  3048. Promise.prototype.nbind = function (/*thisp, ...args*/) {
  3049. var args = array_slice(arguments, 0);
  3050. args.unshift(this);
  3051. return Q.nbind.apply(void 0, args);
  3052. };
  3053.  
  3054. /**
  3055. * Calls a method of a Node-style object that accepts a Node-style
  3056. * callback with a given array of arguments, plus a provided callback.
  3057. * @param object an object that has the named method
  3058. * @param {String} name name of the method of object
  3059. * @param {Array} args arguments to pass to the method; the callback
  3060. * will be provided by Q and appended to these arguments.
  3061. * @returns a promise for the value or error
  3062. */
  3063. Q.nmapply = // XXX As proposed by "Redsandro"
  3064. Q.npost = function (object, name, args) {
  3065. return Q(object).npost(name, args);
  3066. };
  3067.  
  3068. Promise.prototype.nmapply = // XXX As proposed by "Redsandro"
  3069. Promise.prototype.npost = function (name, args) {
  3070. var nodeArgs = array_slice(args || []);
  3071. var deferred = defer();
  3072. nodeArgs.push(deferred.makeNodeResolver());
  3073. this.dispatch("post", [name, nodeArgs]).fail(deferred.reject);
  3074. return deferred.promise;
  3075. };
  3076.  
  3077. /**
  3078. * Calls a method of a Node-style object that accepts a Node-style
  3079. * callback, forwarding the given variadic arguments, plus a provided
  3080. * callback argument.
  3081. * @param object an object that has the named method
  3082. * @param {String} name name of the method of object
  3083. * @param ...args arguments to pass to the method; the callback will
  3084. * be provided by Q and appended to these arguments.
  3085. * @returns a promise for the value or error
  3086. */
  3087. Q.nsend = // XXX Based on Mark Miller's proposed "send"
  3088. Q.nmcall = // XXX Based on "Redsandro's" proposal
  3089. Q.ninvoke = function (object, name /*...args*/) {
  3090. var nodeArgs = array_slice(arguments, 2);
  3091. var deferred = defer();
  3092. nodeArgs.push(deferred.makeNodeResolver());
  3093. Q(object).dispatch("post", [name, nodeArgs]).fail(deferred.reject);
  3094. return deferred.promise;
  3095. };
  3096.  
  3097. Promise.prototype.nsend = // XXX Based on Mark Miller's proposed "send"
  3098. Promise.prototype.nmcall = // XXX Based on "Redsandro's" proposal
  3099. Promise.prototype.ninvoke = function (name /*...args*/) {
  3100. var nodeArgs = array_slice(arguments, 1);
  3101. var deferred = defer();
  3102. nodeArgs.push(deferred.makeNodeResolver());
  3103. this.dispatch("post", [name, nodeArgs]).fail(deferred.reject);
  3104. return deferred.promise;
  3105. };
  3106.  
  3107. /**
  3108. * If a function would like to support both Node continuation-passing-style and
  3109. * promise-returning-style, it can end its internal promise chain with
  3110. * `nodeify(nodeback)`, forwarding the optional nodeback argument. If the user
  3111. * elects to use a nodeback, the result will be sent there. If they do not
  3112. * pass a nodeback, they will receive the result promise.
  3113. * @param object a result (or a promise for a result)
  3114. * @param {Function} nodeback a Node.js-style callback
  3115. * @returns either the promise or nothing
  3116. */
  3117. Q.nodeify = nodeify;
  3118. function nodeify(object, nodeback) {
  3119. return Q(object).nodeify(nodeback);
  3120. }
  3121.  
  3122. Promise.prototype.nodeify = function (nodeback) {
  3123. if (nodeback) {
  3124. this.then(function (value) {
  3125. Q.nextTick(function () {
  3126. nodeback(null, value);
  3127. });
  3128. }, function (error) {
  3129. Q.nextTick(function () {
  3130. nodeback(error);
  3131. });
  3132. });
  3133. } else {
  3134. return this;
  3135. }
  3136. };
  3137.  
  3138. Q.noConflict = function() {
  3139. throw new Error("Q.noConflict only works when Q is used as a global");
  3140. };
  3141.  
  3142. // All code before this point will be filtered from stack traces.
  3143. var qEndingLine = captureLine();
  3144.  
  3145. return Q;
  3146.  
  3147. });
  3148.  
  3149. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(44), __webpack_require__(45).setImmediate))
  3150.  
  3151. /***/ },
  3152. /* 44 */
  3153. /***/ function(module, exports) {
  3154.  
  3155. // shim for using process in browser
  3156.  
  3157. var process = module.exports = {};
  3158. var queue = [];
  3159. var draining = false;
  3160. var currentQueue;
  3161. var queueIndex = -1;
  3162.  
  3163. function cleanUpNextTick() {
  3164. if (!draining || !currentQueue) {
  3165. return;
  3166. }
  3167. draining = false;
  3168. if (currentQueue.length) {
  3169. queue = currentQueue.concat(queue);
  3170. } else {
  3171. queueIndex = -1;
  3172. }
  3173. if (queue.length) {
  3174. drainQueue();
  3175. }
  3176. }
  3177.  
  3178. function drainQueue() {
  3179. if (draining) {
  3180. return;
  3181. }
  3182. var timeout = setTimeout(cleanUpNextTick);
  3183. draining = true;
  3184.  
  3185. var len = queue.length;
  3186. while(len) {
  3187. currentQueue = queue;
  3188. queue = [];
  3189. while (++queueIndex < len) {
  3190. if (currentQueue) {
  3191. currentQueue[queueIndex].run();
  3192. }
  3193. }
  3194. queueIndex = -1;
  3195. len = queue.length;
  3196. }
  3197. currentQueue = null;
  3198. draining = false;
  3199. clearTimeout(timeout);
  3200. }
  3201.  
  3202. process.nextTick = function (fun) {
  3203. var args = new Array(arguments.length - 1);
  3204. if (arguments.length > 1) {
  3205. for (var i = 1; i < arguments.length; i++) {
  3206. args[i - 1] = arguments[i];
  3207. }
  3208. }
  3209. queue.push(new Item(fun, args));
  3210. if (queue.length === 1 && !draining) {
  3211. setTimeout(drainQueue, 0);
  3212. }
  3213. };
  3214.  
  3215. // v8 likes predictible objects
  3216. function Item(fun, array) {
  3217. this.fun = fun;
  3218. this.array = array;
  3219. }
  3220. Item.prototype.run = function () {
  3221. this.fun.apply(null, this.array);
  3222. };
  3223. process.title = 'browser';
  3224. process.browser = true;
  3225. process.env = {};
  3226. process.argv = [];
  3227. process.version = ''; // empty string to avoid regexp issues
  3228. process.versions = {};
  3229.  
  3230. function noop() {}
  3231.  
  3232. process.on = noop;
  3233. process.addListener = noop;
  3234. process.once = noop;
  3235. process.off = noop;
  3236. process.removeListener = noop;
  3237. process.removeAllListeners = noop;
  3238. process.emit = noop;
  3239.  
  3240. process.binding = function (name) {
  3241. throw new Error('process.binding is not supported');
  3242. };
  3243.  
  3244. process.cwd = function () { return '/' };
  3245. process.chdir = function (dir) {
  3246. throw new Error('process.chdir is not supported');
  3247. };
  3248. process.umask = function() { return 0; };
  3249.  
  3250.  
  3251. /***/ },
  3252. /* 45 */
  3253. /***/ function(module, exports, __webpack_require__) {
  3254.  
  3255. /* WEBPACK VAR INJECTION */(function(setImmediate, clearImmediate) {var nextTick = __webpack_require__(44).nextTick;
  3256. var apply = Function.prototype.apply;
  3257. var slice = Array.prototype.slice;
  3258. var immediateIds = {};
  3259. var nextImmediateId = 0;
  3260.  
  3261. // DOM APIs, for completeness
  3262.  
  3263. exports.setTimeout = function() {
  3264. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  3265. };
  3266. exports.setInterval = function() {
  3267. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  3268. };
  3269. exports.clearTimeout =
  3270. exports.clearInterval = function(timeout) { timeout.close(); };
  3271.  
  3272. function Timeout(id, clearFn) {
  3273. this._id = id;
  3274. this._clearFn = clearFn;
  3275. }
  3276. Timeout.prototype.unref = Timeout.prototype.ref = function() {};
  3277. Timeout.prototype.close = function() {
  3278. this._clearFn.call(window, this._id);
  3279. };
  3280.  
  3281. // Does not start the time, just sets up the members needed.
  3282. exports.enroll = function(item, msecs) {
  3283. clearTimeout(item._idleTimeoutId);
  3284. item._idleTimeout = msecs;
  3285. };
  3286.  
  3287. exports.unenroll = function(item) {
  3288. clearTimeout(item._idleTimeoutId);
  3289. item._idleTimeout = -1;
  3290. };
  3291.  
  3292. exports._unrefActive = exports.active = function(item) {
  3293. clearTimeout(item._idleTimeoutId);
  3294.  
  3295. var msecs = item._idleTimeout;
  3296. if (msecs >= 0) {
  3297. item._idleTimeoutId = setTimeout(function onTimeout() {
  3298. if (item._onTimeout)
  3299. item._onTimeout();
  3300. }, msecs);
  3301. }
  3302. };
  3303.  
  3304. // That's not how node.js implements it but the exposed api is the same.
  3305. exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
  3306. var id = nextImmediateId++;
  3307. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  3308.  
  3309. immediateIds[id] = true;
  3310.  
  3311. nextTick(function onNextTick() {
  3312. if (immediateIds[id]) {
  3313. // fn.call() is faster so we optimize for the common use-case
  3314. // @see http://jsperf.com/call-apply-segu
  3315. if (args) {
  3316. fn.apply(null, args);
  3317. } else {
  3318. fn.call(null);
  3319. }
  3320. // Prevent ids from leaking
  3321. exports.clearImmediate(id);
  3322. }
  3323. });
  3324.  
  3325. return id;
  3326. };
  3327.  
  3328. exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
  3329. delete immediateIds[id];
  3330. };
  3331. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(45).setImmediate, __webpack_require__(45).clearImmediate))
  3332.  
  3333. /***/ },
  3334. /* 46 */
  3335. /***/ function(module, exports, __webpack_require__) {
  3336.  
  3337. 'use strict';
  3338.  
  3339. Object.defineProperty(exports, "__esModule", {
  3340. value: true
  3341. });
  3342.  
  3343. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3344.  
  3345. var _jqLite = __webpack_require__(1);
  3346.  
  3347. var _jqLite2 = _interopRequireDefault(_jqLite);
  3348.  
  3349. var _q = __webpack_require__(43);
  3350.  
  3351. var _q2 = _interopRequireDefault(_q);
  3352.  
  3353. var _config = __webpack_require__(47);
  3354.  
  3355. var _config2 = _interopRequireDefault(_config);
  3356.  
  3357. var _$http = __webpack_require__(48);
  3358.  
  3359. var _$http2 = _interopRequireDefault(_$http);
  3360.  
  3361. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  3362.  
  3363. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3364.  
  3365. var main = function () {
  3366. function main() {
  3367. var _this = this;
  3368.  
  3369. var agm = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
  3370.  
  3371. _classCallCheck(this, main);
  3372.  
  3373. if (!agm) return this;
  3374.  
  3375. this.inViewPort = [];
  3376.  
  3377. (0, _jqLite2.default)(agm).each(function (ele) {
  3378. return _jqLite2.default.fn.visible(ele) && _this.inViewPort.push(ele);
  3379. });
  3380. }
  3381.  
  3382. /**
  3383. * request a url which has origin links
  3384. * @returns {Promise}
  3385. */
  3386.  
  3387.  
  3388. _createClass(main, [{
  3389. key: 'all',
  3390. value: function all() {
  3391. var deferred = _q2.default.defer();
  3392.  
  3393. var url = window.top.location.href.replace(/(\&)(tn=\w+)(\&)/img, '$1' + 'tn=baidulocal' + '$3');
  3394.  
  3395. _config2.default.isDecodingAll = true;
  3396.  
  3397. _$http2.default.get(url, { timeout: 2000 }).then(function (response) {
  3398. _config2.default.isDecodingAll = false;
  3399.  
  3400. if (!response) return;
  3401. var responseText = response.responseText;
  3402.  
  3403. // remove the image/script/css resource
  3404. responseText = responseText.replace(/(src=[^>]*|link=[^>])/g, '');
  3405.  
  3406. var html = document.createElement('html');
  3407. html.innerHTML = responseText;
  3408.  
  3409. (0, _jqLite2.default)('.t>a:not(.OP_LOG_LINK):not([decoded])').each(function (sourceEle) {
  3410. (0, _jqLite2.default)('.f>a', html).each(function (targetEle) {
  3411. if ((0, _jqLite2.default)(sourceEle).text === (0, _jqLite2.default)(targetEle).text) {
  3412. sourceEle.href = targetEle.href;
  3413. (0, _jqLite2.default)(sourceEle).attr('decoded', true);
  3414. }
  3415. });
  3416. });
  3417.  
  3418. deferred.resolve(response);
  3419. }, function (response) {
  3420. _config2.default.isDecodingAll = false;
  3421. deferred.reject(response);
  3422. });
  3423.  
  3424. return deferred.promise;
  3425. }
  3426. }, {
  3427. key: 'one',
  3428. value: function one(aEle) {
  3429. var deferred = _q2.default.defer();
  3430.  
  3431. (0, _jqLite2.default)(aEle).attr('decoding', true);
  3432.  
  3433. _$http2.default.head(aEle.href, { timeout: 2000, anonymous: true }).then(function (response) {
  3434. (0, _jqLite2.default)(aEle).attr('href', response.finalUrl).attr('decoded', true).removeAttr('decoding');
  3435. deferred.resolve(response);
  3436. }, function (response) {
  3437. (0, _jqLite2.default)(aEle).removeAttr('decoding');
  3438. deferred.reject(response);
  3439. });
  3440.  
  3441. return deferred.promise;
  3442. }
  3443.  
  3444. /**
  3445. * request the A tag's href one by one those in view port
  3446. * @returns {main}
  3447. */
  3448.  
  3449. }, {
  3450. key: 'oneByOne',
  3451. value: function oneByOne() {
  3452. var _this2 = this;
  3453.  
  3454. (0, _jqLite2.default)(this.inViewPort).each(function (aEle) {
  3455. if (!main.match(aEle)) return;
  3456. _this2.one(aEle);
  3457. });
  3458. return this;
  3459. }
  3460.  
  3461. /**
  3462. * match the Element
  3463. */
  3464.  
  3465. }], [{
  3466. key: 'match',
  3467. value: function match(ele) {
  3468. if (ele.tagName !== "A" || !ele.href || !/www\.baidu\.com\/link\?url=/im.test(ele.href) || !!(0, _jqLite2.default)(ele).attr('decoded') || !!(0, _jqLite2.default)(ele).attr('decoding')) {
  3469. return false;
  3470. } else {
  3471. return true;
  3472. }
  3473. }
  3474. }]);
  3475.  
  3476. return main;
  3477. }();
  3478.  
  3479. exports.default = main;
  3480.  
  3481. /***/ },
  3482. /* 47 */
  3483. /***/ function(module, exports) {
  3484.  
  3485. 'use strict';
  3486.  
  3487. Object.defineProperty(exports, "__esModule", {
  3488. value: true
  3489. });
  3490. // config
  3491. var CONFIG = {
  3492. rules: '\n a[href*="www.baidu.com/link?url"]\n :not(.m)\n :not([decoding])\n :not([decoded])\n '.trim().replace(/\n/img, '').replace(/\s{1,}([^a-zA-Z])/g, '$1'),
  3493. debug: false,
  3494. debugStyle: '\n a[decoded]{\n background-color:green !important;\n color:#303030 !important;\n };\n a[decoding]{\n background-color:yellow !important;\n color:#303030 !important;\n }\n ',
  3495. isDecodingAll: false
  3496. };
  3497.  
  3498. exports.default = CONFIG;
  3499.  
  3500. /***/ },
  3501. /* 48 */
  3502. /***/ function(module, exports, __webpack_require__) {
  3503.  
  3504. 'use strict';
  3505.  
  3506. Object.defineProperty(exports, "__esModule", {
  3507. value: true
  3508. });
  3509. /**
  3510. * http service
  3511. * @param ops
  3512. * @returns {Promise}
  3513. */
  3514.  
  3515. var $q = __webpack_require__(43);
  3516. var $ = __webpack_require__(1);
  3517. var $util = __webpack_require__(49);
  3518.  
  3519. var $http = function $http() {
  3520. var ops = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  3521.  
  3522. var deferred = $q.defer();
  3523.  
  3524. var onreadystatechange = function onreadystatechange(response) {
  3525. if (response.readyState !== 4) return;
  3526. response.requestUrl = ops.url;
  3527. if (/^(2|3)/.test(response.status) || response.finalUrl) {
  3528. deferred.resolve(response);
  3529. } else {
  3530. deferred.reject(response);
  3531. }
  3532. };
  3533.  
  3534. var ontimeout = function ontimeout(response) {
  3535. response.requestUrl = ops.url;
  3536. response && response.finalUrl ? deferred.resolve(response) : deferred.reject(response);
  3537. };
  3538.  
  3539. var onerror = function onerror(response) {
  3540. response.requestUrl = ops.url;
  3541. response && response.finalUrl ? deferred.resolve(response) : deferred.reject(response);
  3542. };
  3543.  
  3544. ops = $util.merge({
  3545. onreadystatechange: onreadystatechange,
  3546. ontimeout: ontimeout,
  3547. onerror: onerror
  3548. }, ops);
  3549.  
  3550. // make the protocol agree
  3551. if (!new RegExp('^' + window.location.protocol).test(ops.url)) {
  3552. ops.url = ops.url.replace(/^(http|https):/im, window.location.protocol);
  3553. }
  3554.  
  3555. GM_xmlhttpRequest(ops);
  3556. return deferred.promise;
  3557. };
  3558.  
  3559. ['HEAD', 'GET', 'POST'].forEach(function (method) {
  3560. $http[method.toLocaleLowerCase()] = function (url) {
  3561. var ops = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  3562.  
  3563. var deferred = $q.defer();
  3564. ops = $util.merge(ops, { url: url, method: method });
  3565. $http(ops).then(function (response) {
  3566. deferred.resolve(response);
  3567. }, function (response) {
  3568. deferred.reject(response);
  3569. });
  3570. return deferred.promise;
  3571. };
  3572. });
  3573.  
  3574. $http.jsonp = function (url) {
  3575. var deferred = $q.defer();
  3576.  
  3577. var func = function func(resp) {
  3578. script.remove();
  3579. resp ? deferred.resolve(resp) : deferred.reject(resp);
  3580. };
  3581.  
  3582. var script = document.createElement('script');
  3583. script.setAttribute("type", "text/javascript");
  3584. script.src = url + '?callback=func';
  3585. document.body.appendChild(script);
  3586.  
  3587. return deferred.promise;
  3588. };
  3589.  
  3590. exports.default = $http;
  3591.  
  3592. /***/ },
  3593. /* 49 */
  3594. /***/ function(module, exports, __webpack_require__) {
  3595.  
  3596. 'use strict';
  3597.  
  3598. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /**
  3599. * Created by axetroy on 16-4-17.
  3600. */
  3601.  
  3602. // object.assign for merge and copy
  3603.  
  3604.  
  3605. __webpack_require__(30);
  3606.  
  3607. var TYPED_ARRAY_REGEXP = /^\[object (?:Uint8|Uint8Clamped|Uint16|Uint32|Int8|Int16|Int32|Float32|Float64)Array\]$/;
  3608.  
  3609. var noop = void 0;
  3610. var toString = Object.prototype.toString;
  3611. var createMap = void 0;
  3612. var _equals = void 0;
  3613. var merge = void 0;
  3614. var extend = void 0;
  3615. var copy = void 0;
  3616.  
  3617. var isDefined = void 0;
  3618. var isUndefined = void 0;
  3619. var isArray = void 0;
  3620. var isDate = void 0;
  3621. var isBoolean = void 0;
  3622. var isElement = void 0;
  3623. var isNumber = void 0;
  3624. var isObject = void 0;
  3625. var isString = void 0;
  3626. var isFunction = void 0;
  3627. var isRegExp = void 0;
  3628. var isWindow = void 0;
  3629. var isFile = void 0;
  3630. var isBlob = void 0;
  3631. var isTypedArray = void 0;
  3632. var isArrayBuffer = void 0;
  3633.  
  3634. noop = function noop() {};
  3635.  
  3636. createMap = function createMap() {
  3637. return Object.create(null);
  3638. };
  3639.  
  3640. isDefined = function isDefined($$defined) {
  3641. return !isUndefined($$defined);
  3642. };
  3643. isUndefined = function isUndefined(value, undefined) {
  3644. return typeof value === 'undefined' || value === undefined;
  3645. };
  3646. isArray = Array.isArray;
  3647. isDate = function isDate(date) {
  3648. return toString.call(date) === '[object Date]';
  3649. };
  3650. isBoolean = function isBoolean(value) {
  3651. return typeof value === 'boolean' || value instanceof Boolean;
  3652. };
  3653. isElement = function isElement(node) {
  3654. return !!(node && (node.nodeName || node.prop && node.attr));
  3655. };
  3656. isNumber = function isNumber(value) {
  3657. return isNaN(value) ? false : typeof value === 'number' || value instanceof Number;
  3658. };
  3659. isObject = function isObject(value) {
  3660. return value !== null && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object';
  3661. };
  3662. isString = function isString(value) {
  3663. return typeof value === 'string' || value instanceof String;
  3664. };
  3665. isFunction = function isFunction(value) {
  3666. return typeof value === 'function';
  3667. };
  3668. isRegExp = function isRegExp(value) {
  3669. return toString.call(value) === '[object RegExp]';
  3670. };
  3671. isWindow = function isWindow(obj) {
  3672. return obj && obj.window === obj;
  3673. };
  3674. isFile = function isFile(obj) {
  3675. return toString.call(obj) === '[object File]';
  3676. };
  3677. isBlob = function isBlob(obj) {
  3678. return toString.call(obj) === '[object Blob]';
  3679. };
  3680. isTypedArray = function isTypedArray(value) {
  3681. return value && isNumber(value.length) && TYPED_ARRAY_REGEXP.test(toString.call(value));
  3682. };
  3683. isArrayBuffer = function isArrayBuffer(obj) {
  3684. return toString.call(obj) === '[object ArrayBuffer]';
  3685. };
  3686.  
  3687. _equals = function equals(o1, o2) {
  3688. if (o1 === o2) return true;
  3689. if (o1 === null || o2 === null) return false;
  3690. if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
  3691. var t1 = typeof o1 === 'undefined' ? 'undefined' : _typeof(o1),
  3692. t2 = typeof o2 === 'undefined' ? 'undefined' : _typeof(o2);
  3693. if (t1 === t2 && t1 === 'object') {
  3694. // array
  3695. if (isArray(o1)) {
  3696. if (!isArray(o2)) return false;
  3697. var length = o1.length;
  3698. if (length === o2.length) {
  3699. for (var key = 0; key < length; key++) {
  3700. if (!_equals(o1[key], o2[key])) return false;
  3701. }
  3702. return true;
  3703. }
  3704. }
  3705. //date
  3706. else if (isDate(o1)) {
  3707. if (!isDate(o2)) return false;
  3708. return _equals(o1.getTime(), o2.getTime());
  3709. }
  3710. // RegExp
  3711. else if (isRegExp(o1)) {
  3712. if (!isRegExp(o2)) return false;
  3713. return o1.toString() === o2.toString();
  3714. } else {
  3715. if (isWindow(o1) || isWindow(o2)) return false;
  3716.  
  3717. for (var attr in o2) {
  3718. if (o2.hasOwnProperty(attr)) {
  3719. if (!attr in o1 || o2[attr] !== o1[attr]) return false;
  3720. }
  3721. }
  3722.  
  3723. return true;
  3724. }
  3725. } else if (t1 === 'function') {
  3726. if (t2 !== 'function') return false;
  3727. return o1.toString() === o2.toString();
  3728. } else {
  3729. return o1 === o2;
  3730. }
  3731. return false;
  3732. };
  3733.  
  3734. merge = function merge() {
  3735. for (var _len = arguments.length, sources = Array(_len), _key = 0; _key < _len; _key++) {
  3736. sources[_key] = arguments[_key];
  3737. }
  3738.  
  3739. return Object.assign.apply(Object, [{}].concat(sources));
  3740. };
  3741.  
  3742. extend = function extend(target) {
  3743. for (var _len2 = arguments.length, source = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  3744. source[_key2 - 1] = arguments[_key2];
  3745. }
  3746.  
  3747. return Object.assign.apply(Object, [target].concat(source));
  3748. };
  3749.  
  3750. copy = function copy(obj) {
  3751. return merge(obj);
  3752. };
  3753.  
  3754. module.exports = {
  3755. noop: noop,
  3756. isDefined: isDefined,
  3757. isUndefined: isUndefined,
  3758. isArray: isArray,
  3759. isDate: isDate,
  3760. isBoolean: isBoolean,
  3761. isElement: isElement,
  3762. isNumber: isNumber,
  3763. isObject: isObject,
  3764. isString: isString,
  3765. isFunction: isFunction,
  3766. isRegExp: isRegExp,
  3767. isWindow: isWindow,
  3768. isFile: isFile,
  3769. isBlob: isBlob,
  3770. isTypedArray: isTypedArray,
  3771. isArrayBuffer: isArrayBuffer,
  3772. equals: _equals,
  3773. merge: merge,
  3774. extend: extend,
  3775. copy: copy
  3776. };
  3777.  
  3778. /***/ },
  3779. /* 50 */
  3780. /***/ function(module, exports, __webpack_require__) {
  3781.  
  3782. 'use strict';
  3783.  
  3784. Object.defineProperty(exports, "__esModule", {
  3785. value: true
  3786. });
  3787.  
  3788. var _jqLite = __webpack_require__(1);
  3789.  
  3790. var _jqLite2 = _interopRequireDefault(_jqLite);
  3791.  
  3792. var _$debounce = __webpack_require__(51);
  3793.  
  3794. var _$addStyle = __webpack_require__(52);
  3795.  
  3796. var _$addStyle2 = _interopRequireDefault(_$addStyle);
  3797.  
  3798. var _main = __webpack_require__(46);
  3799.  
  3800. var _main2 = _interopRequireDefault(_main);
  3801.  
  3802. var _init = __webpack_require__(42);
  3803.  
  3804. var _init2 = _interopRequireDefault(_init);
  3805.  
  3806. var _config = __webpack_require__(47);
  3807.  
  3808. var _config2 = _interopRequireDefault(_config);
  3809.  
  3810. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  3811.  
  3812. var observe = function observe() {
  3813.  
  3814. (0, _jqLite2.default)(document).observe((0, _$debounce.$debounce)(function (target) {
  3815. var addList = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
  3816. var removeList = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
  3817.  
  3818. if (!addList.length) return;
  3819. _config2.default.isDecodingAll ? new _main2.default(_config2.default.rules).oneByOne() : (0, _init2.default)();
  3820. _config2.default.debug && (0, _$addStyle2.default)(_config2.default.debugStyle);
  3821. }, 100));
  3822. };
  3823.  
  3824. exports.default = observe;
  3825.  
  3826. /***/ },
  3827. /* 51 */
  3828. /***/ function(module, exports) {
  3829.  
  3830. "use strict";
  3831.  
  3832. Object.defineProperty(exports, "__esModule", {
  3833. value: true
  3834. });
  3835. /*
  3836. * 频率控制 返回函数连续调用时,fn 执行频率限定为每多少时间执行一次
  3837. * @param fn {function} 需要调用的函数
  3838. * @param delay {number} 延迟时间,单位毫秒
  3839. * @param immediate {bool} 给 immediate参数传递false 绑定的函数先执行,而不是delay后后执行。
  3840. * @return {function}实际调用函数
  3841. */
  3842. var $throttle = function $throttle(fn, delay, immediate, debounce) {
  3843. var curr = +new Date(),
  3844. //当前事件
  3845. last_call = 0,
  3846. last_exec = 0,
  3847. timer = null,
  3848. diff,
  3849. //时间差
  3850. context,
  3851. //上下文
  3852. args,
  3853. exec = function exec() {
  3854. last_exec = curr;
  3855. fn.apply(context, args);
  3856. };
  3857. return function () {
  3858. curr = +new Date();
  3859. context = this, args = arguments, diff = curr - (debounce ? last_call : last_exec) - delay;
  3860. clearTimeout(timer);
  3861. if (debounce) {
  3862. if (immediate) {
  3863. timer = setTimeout(exec, delay);
  3864. } else if (diff >= 0) {
  3865. exec();
  3866. }
  3867. } else {
  3868. if (diff >= 0) {
  3869. exec();
  3870. } else if (immediate) {
  3871. timer = setTimeout(exec, -diff);
  3872. }
  3873. }
  3874. last_call = curr;
  3875. };
  3876. };
  3877.  
  3878. /*
  3879. * 空闲控制 返回函数连续调用时,空闲时间必须大于或等于 delay,fn 才会执行
  3880. * @param fn {function} 要调用的函数
  3881. * @param delay {number} 空闲时间
  3882. * @param immediate {bool} 给 immediate参数传递false 绑定的函数先执行,而不是delay后后执行。
  3883. * @return {function}实际调用函数
  3884. */
  3885.  
  3886. var $debounce = function $debounce(fn, delay, immediate) {
  3887. return $throttle(fn, delay, immediate, true);
  3888. };
  3889.  
  3890. exports.$debounce = $debounce;
  3891. exports.$throttle = $throttle;
  3892.  
  3893. /***/ },
  3894. /* 52 */
  3895. /***/ function(module, exports) {
  3896.  
  3897. "use strict";
  3898.  
  3899. Object.defineProperty(exports, "__esModule", {
  3900. value: true
  3901. });
  3902. var addCssByStyle = function addCssByStyle(cssString) {
  3903. var doc = document;
  3904. var style = doc.createElement("style");
  3905. style.setAttribute("type", "text/css");
  3906. style.setAttribute('id', 'remove_redirect_debug');
  3907.  
  3908. if (style.styleSheet) {
  3909. // IE
  3910. style.styleSheet.cssText = cssString;
  3911. } else {
  3912. // w3c
  3913. var cssText = doc.createTextNode(cssString);
  3914. style.appendChild(cssText);
  3915. }
  3916.  
  3917. var heads = doc.getElementsByTagName("head");
  3918. heads.length ? heads[0].appendChild(style) : doc.documentElement.appendChild(style);
  3919. };
  3920.  
  3921. var $addStyle = function $addStyle(styleCSSText) {
  3922. var style = document.getElementById('remove_redirect_debug');
  3923. !style && addCssByStyle(styleCSSText);
  3924. };
  3925.  
  3926. exports.default = $addStyle;
  3927.  
  3928. /***/ },
  3929. /* 53 */
  3930. /***/ function(module, exports, __webpack_require__) {
  3931.  
  3932. 'use strict';
  3933.  
  3934. Object.defineProperty(exports, "__esModule", {
  3935. value: true
  3936. });
  3937.  
  3938. var _jqLite = __webpack_require__(1);
  3939.  
  3940. var _jqLite2 = _interopRequireDefault(_jqLite);
  3941.  
  3942. var _$debounce = __webpack_require__(51);
  3943.  
  3944. var _main = __webpack_require__(46);
  3945.  
  3946. var _main2 = _interopRequireDefault(_main);
  3947.  
  3948. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  3949.  
  3950. var mouseover = function mouseover() {
  3951. (0, _jqLite2.default)(document).bind('mouseover', (0, _$debounce.$debounce)(function (e) {
  3952. var aEle = e.target;
  3953. if (aEle.tagName !== "A" || !aEle.href || !/www\.baidu\.com\/link\?url=/im.test(aEle.href) || !!(0, _jqLite2.default)(aEle).attr('decoded')) {
  3954. return;
  3955. }
  3956. new _main2.default().one(aEle);
  3957. }, 100, true));
  3958. }; // libs
  3959.  
  3960.  
  3961. exports.default = mouseover;
  3962.  
  3963. /***/ },
  3964. /* 54 */
  3965. /***/ function(module, exports, __webpack_require__) {
  3966.  
  3967. 'use strict';
  3968.  
  3969. Object.defineProperty(exports, "__esModule", {
  3970. value: true
  3971. });
  3972.  
  3973. var _jqLite = __webpack_require__(1);
  3974.  
  3975. var _jqLite2 = _interopRequireDefault(_jqLite);
  3976.  
  3977. var _$debounce = __webpack_require__(51);
  3978.  
  3979. var _$addStyle = __webpack_require__(52);
  3980.  
  3981. var _$addStyle2 = _interopRequireDefault(_$addStyle);
  3982.  
  3983. var _main = __webpack_require__(46);
  3984.  
  3985. var _main2 = _interopRequireDefault(_main);
  3986.  
  3987. var _config = __webpack_require__(47);
  3988.  
  3989. var _config2 = _interopRequireDefault(_config);
  3990.  
  3991. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  3992.  
  3993. var scroll = function scroll() {
  3994. (0, _jqLite2.default)(window).bind('scroll', (0, _$debounce.$debounce)(function () {
  3995. new _main2.default(_config2.default.rules).oneByOne();
  3996. _config2.default.debug && (0, _$addStyle2.default)(_config2.default.debugStyle);
  3997. }, 100));
  3998. };
  3999.  
  4000. exports.default = scroll;
  4001.  
  4002. /***/ }
  4003. /******/ ]);