From 056f9359f0bd46b8ec7f946c64b7858bb57cd6eb Mon Sep 17 00:00:00 2001 From: surunzi Date: Sat, 12 Mar 2016 23:50:55 +0800 Subject: [PATCH] Dev: Console url detect --- dist/eruda.js | 35 +++++++++++++++++++++++++++++++++++ eustia/loadJs.js | 6 ++++++ package.json | 4 +++- src/Console/Log.es6 | 10 ++++++++++ src/Console/cmdList.json | 1 + src/Console/libraries.json | 3 +++ src/util.js | 16 ++++++++++++++++ 7 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 eustia/loadJs.js create mode 100644 src/Console/libraries.json diff --git a/dist/eruda.js b/dist/eruda.js index 05bb41e..29b94df 100644 --- a/dist/eruda.js +++ b/dist/eruda.js @@ -817,6 +817,22 @@ var eruda = return isRegExp; })(); + /* ------------------------------ loadJs ------------------------------ */ + + var loadJs; + + _.loadJs = (function () + { + loadJs = function (url) + { + var script = document.createElement('script'); + script.src = url; + document.body.appendChild(script); + }; + + return loadJs; + })(); + /* ------------------------------ ltrim ------------------------------ */ var ltrim; @@ -5445,6 +5461,10 @@ var eruda = commands: cmdList }); + var libraries = __webpack_require__(71); + + var regJsUrl = /https?:\/\/([0-9.\-A-Za-z]+)(?::(\d+))?\/[A-Za-z0-9/]*\.js/g; + function evalJs(jsInput) { return eval(jsInput); } @@ -5455,6 +5475,10 @@ var eruda = if (_util2.default.isUndef(msg)) msg = lines[0] + '
'; var stack = '
' + lines.slice(1).join('
') + '
'; + stack = stack.replace(regJsUrl, function (match) { + return '' + match + ''; + }); + return msg + stack; } @@ -5637,6 +5661,8 @@ var eruda = return this.filter('log'); case 'h': return this.help(); + case '$': + return _util2.default.loadJs(libraries['jQuery']); default: this.warn('Unknown command').help(); } @@ -5732,6 +5758,7 @@ var eruda = ":w": "Show warn logs only", ":l": "Show normal logs only", ":h": "Show help", + ":$": "Load jQuery", "/regexp": "Show logs that match given regexp" }; @@ -9531,5 +9558,13 @@ var eruda = // exports +/***/ }, +/* 71 */ +/***/ function(module, exports) { + + module.exports = { + "jQuery": "//code.jquery.com/jquery-1.12.0.min.js" + }; + /***/ } /******/ ]); \ No newline at end of file diff --git a/eustia/loadJs.js b/eustia/loadJs.js new file mode 100644 index 0000000..2b767ea --- /dev/null +++ b/eustia/loadJs.js @@ -0,0 +1,6 @@ +loadJs = function (url) +{ + var script = document.createElement('script'); + script.src = url; + document.body.appendChild(script); +}; \ No newline at end of file diff --git a/package.json b/package.json index b257e27..e0bb870 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,9 @@ "node-sass": "^3.4.2", "postcss-loader": "^0.8.1", "precss": "^1.4.0", - "sass-loader": "^3.1.2" + "sass-loader": "^3.1.2", + "style-loader": "^0.13.0", + "webpack": "^1.12.14" }, "dependencies": { "draggabilly": "^2.1.0" diff --git a/src/Console/Log.es6 b/src/Console/Log.es6 index bb987fb..f39dd1b 100644 --- a/src/Console/Log.es6 +++ b/src/Console/Log.es6 @@ -7,6 +7,10 @@ var cmdList = require('./cmdList.json'), commands: cmdList }); +var libraries = require('./libraries.json'); + +var regJsUrl = /https?:\/\/([0-9.\-A-Za-z]+)(?::(\d+))?\/[A-Za-z0-9/]*\.js/g; + function evalJs(jsInput) { return eval(jsInput); @@ -19,6 +23,11 @@ function errToStr(err, msg) if (util.isUndef(msg)) msg = lines[0] + '
'; var stack = '
' + lines.slice(1).join('
') + '
'; + stack = stack.replace(regJsUrl, function (match) + { + return '' + match + ''; + }); + return msg + stack; } @@ -198,6 +207,7 @@ export default class Log case 'w': return this.filter('warn'); case 'l': return this.filter('log'); case 'h': return this.help(); + case '$': return util.loadJs(libraries['jQuery']); default: this.warn('Unknown command').help(); } diff --git a/src/Console/cmdList.json b/src/Console/cmdList.json index 8f1eb36..ff7b989 100644 --- a/src/Console/cmdList.json +++ b/src/Console/cmdList.json @@ -5,5 +5,6 @@ ":w": "Show warn logs only", ":l": "Show normal logs only", ":h": "Show help", + ":$": "Load jQuery", "/regexp": "Show logs that match given regexp" } \ No newline at end of file diff --git a/src/Console/libraries.json b/src/Console/libraries.json new file mode 100644 index 0000000..ffa423b --- /dev/null +++ b/src/Console/libraries.json @@ -0,0 +1,3 @@ +{ + "jQuery": "//code.jquery.com/jquery-1.12.0.min.js" +} \ No newline at end of file diff --git a/src/util.js b/src/util.js index aeb06a9..039938a 100644 --- a/src/util.js +++ b/src/util.js @@ -593,6 +593,22 @@ module.exports = (function () return isRegExp; })(); + /* ------------------------------ loadJs ------------------------------ */ + + var loadJs; + + _.loadJs = (function () + { + loadJs = function (url) + { + var script = document.createElement('script'); + script.src = url; + document.body.appendChild(script); + }; + + return loadJs; + })(); + /* ------------------------------ ltrim ------------------------------ */ var ltrim;