(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o h || pos.bottom < 0 || pos.left > w || pos.right < 0; return inViewPort ? false : true; } }; var debounce = function debounce(fn, delay) { var timer = undefined; return function () { var _this4 = this; var agm = arguments; window.clearTimeout(timer); timer = window.setTimeout(function () { fn.apply(_this4, agm); }, delay); }; }; var merge = function merge() { for (var _len = arguments.length, sources = Array(_len), _key = 0; _key < _len; _key++) { sources[_key] = arguments[_key]; } return Object.assign.apply(Object, [{}].concat(sources)); }; return { visible: visible, debounce: debounce, merge: merge }; } }]); return jqLite; })(); var $ = function $() { var selectors = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0]; var context = arguments.length <= 1 || arguments[1] === undefined ? document : arguments[1]; return new jqLite(selectors, context); }; $.fn = jqLite.fn; module.exports = $; },{}],5:[function(require,module,exports){ // config 'use strict'; var config = { 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'), debug: false, isDecodingAll: false }; if (config.debug) { GM_addStyle('\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 '); } module.exports = config; },{}],6:[function(require,module,exports){ 'use strict'; var main = require('./main'); var $q = require('../libs/$q'); var config = require('./config'); var init = function init() { new main(config.rules).all().then(function () { return $q.resolve(true); }, function () { return $q.resolve(true); }).then(function () { new main(config.rules).oneByOne(); }); }; module.exports = init; },{"../libs/$q":3,"./config":5,"./main":7}],7:[function(require,module,exports){ /** * the main class to bootstrap this script */ 'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var config = require('./config'); var $ = require('./../libs/jqLite'); var $q = require('./../libs/$q'); var $http = require('./../libs/$http'); var main = (function () { function main() { var _this = this; var agm = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0]; _classCallCheck(this, main); if (!agm) return this; this.inViewPort = []; $(agm).each(function (ele) { return $.fn.visible(ele) && _this.inViewPort.push(ele); }); } /** * request a url which has origin links * @returns {Promise} */ main.prototype.all = function all() { var deferred = $q.defer(); var url = window.top.location.href.replace(/(\&)(tn=\w+)(\&)/img, '$1' + 'tn=baidulocal' + '$3'); config.isDecodingAll = true; $http.get(url, { timeout: 2000 }).then(function (response) { config.isDecodingAll = false; if (!response) return; var responseText = response.responseText; // remove the image/script/css resource responseText = responseText.replace(/(src=[^>]*|link=[^>])/g, ''); var html = document.createElement('html'); html.innerHTML = responseText; $('.t>a:not(.OP_LOG_LINK):not([decoded])').each(function (sourceEle) { $('.f>a', html).each(function (targetEle) { if ($(sourceEle).text === $(targetEle).text) { sourceEle.href = targetEle.href; $(sourceEle).attr('decoded', true); } }); }); deferred.resolve(response); }, function (response) { config.isDecodingAll = false; deferred.reject(response); }); return deferred.promise; }; main.prototype.one = function one(aEle) { var deferred = $q.defer(); $(aEle).attr('decoding', true); $http.get(aEle.href, { timeout: 2000, anonymous: true }).then(function (response) { $(aEle).attr('href', response.finalUrl).attr('decoded', true).removeAttr('decoding'); deferred.resolve(response); }, function (response) { $(aEle).removeAttr('decoding'); deferred.reject(response); }); return deferred.promise; }; /** * request the A tag's href one by one those in view port * @returns {main} */ main.prototype.oneByOne = function oneByOne() { var _this2 = this; $(this.inViewPort).each(function (aEle) { if (!main.match(aEle)) return; _this2.one(aEle); }); return this; }; /** * match the Element */ main.match = function match(ele) { if (ele.tagName !== "A" || !ele.href || !/www\.baidu\.com\/link\?url=/im.test(ele.href) || !!$(ele).attr('decoded') || !!$(ele).attr('decoding')) { return false; } else { return true; } }; return main; })(); module.exports = main; },{"./../libs/$http":2,"./../libs/$q":3,"./../libs/jqLite":4,"./config":5}],8:[function(require,module,exports){ /** * Created by axetroy on 16-4-10. */ 'use strict'; var $ = require('../libs/jqLite'); var main = require('./main'); var mouseoverDebounce = $.fn.debounce(function (e) { var aEle = e.target; if (aEle.tagName !== "A" || !aEle.href || !/www\.baidu\.com\/link\?url=/im.test(aEle.href) || !!$(aEle).attr('decoded')) { return; } new main().one(aEle); }, 100); var mouseover = function mouseover() { return function () { $(document).bind('mouseover', function (e) { mouseoverDebounce(e); }); }; }; module.exports = mouseover(); },{"../libs/jqLite":4,"./main":7}],9:[function(require,module,exports){ /** * Created by axetroy on 16-4-10. */ 'use strict'; var $ = require('../libs/jqLite'); var main = require('./main'); var init = require('./init'); var config = require('./config'); var observe = function observe() { return function () { var observeDebounce = $.fn.debounce(function (target) { var addList = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; var removeList = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; if (!addList.length) return; config.isDecodingAll ? new main(config.rules).oneByOne() : init(); }, 100); $(document).observe(function (target) { var addList = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; var removeList = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; observeDebounce(target, addList, removeList); }); }; }; module.exports = observe(); },{"../libs/jqLite":4,"./config":5,"./init":6,"./main":7}],10:[function(require,module,exports){ /** * Created by axetroy on 16-4-10. */ 'use strict'; var $ = require('../libs/jqLite'); var main = require('./main'); var config = require('./config'); var scroll = function scroll() { return function () { var scrollDebounce = $.fn.debounce(function () { new main(config.rules).oneByOne(); }, 100); $(window).bind('scroll', function () { scrollDebounce(); }); }; }; module.exports = scroll(); },{"../libs/jqLite":4,"./config":5,"./main":7}]},{},[1]);