当前位置:博客展示

JavaScript资源调试器[图][下载]

作者: 创建时间:2016-12-02 10:15:37

要求环境

jquery-1.10.1.min.js 环境

工具截图

dump({news:'欢迎进入好工作网!',href:document.location},'小菜一碟');的打印测试截图
dump({news:'欢迎进入好工作网!',href:document.location},'小菜一碟');的打印测试截图

使用方法

p({news:'欢迎进入好工作网!',href:document.location},'小菜一碟');

测试

代码

//希望有用
//打印函数(刷新)
//JavaScript资源调试器 源代码
$(function() {
	if (window.json) {
		pc('json', json);
	}
});
function p() {
	dump_fn(arguments, true, false)
}
function ps() {
	dump_fn(arguments, true)
}
function po(a) {
	dump_fn(a, true)
}
function pr(a) {
	dump_fn(a)
}
function pc(b,d) {
	if (!window.DEBUG) return 'DEBUG未开启!';
	if (d.err && d.data) {
		d.text = d.data.replace(/<script[^>]*?>[\s\S]*?<\/script[^>]*>|<style[^>]*?>[\s\S]*?<\/style[^>]*>|<(.|\n)+?>/g, ' ');
		d.text = d.text.replace(/\s+/g, ' ');
		d.text = d.text.replace(/(\/|\\)+/g, '/');
		d.text = d.text.replace(/(^\s*)|(\s*$)/g, '');
	}
	if (d.title) {
		b = d.title + '_' + b;
	} else if (d.REQUEST && d.REQUEST.URL) {
		b = 'URL:' + d.REQUEST.URL + '';
	}
	var butt = '<button style="position:fixed;right:5px;z-index:50000;bottom:' + ((window.parObjIndex = window.parObjIndex ? ++window.parObjIndex: 1) * 25 + 10) + 'px;" onclick=\'p(unescape(\"' + escape(JSON.stringify(d)) + '\"));\' >' + b + '[' + parObjIndex + ']</button>';
	$('body').append(butt);
}
function dump_fn(arg,unarg,add) {
	if (!window.DEBUG) return 'DEBUG未开启!';
	window.dump_ = {
		i: 0,o: {},k: {},s: 0,step: 6,br: 0,p: function(i) {
			dump_.step = 3;
			var R = new dump_.fn();
			R.html = '查询结果:';
			R.data[dump_.k[i]] = dump_.o[i];
			R.add = true;
			R.shot = true;
			R.app()
		},fn: function() {
			this.html = '';
			this.data = {};
			this.add = true;
			this.run = function run(o,n,lk) {
				var err = '',k = '',t = '',h = '',v = '',l = 0,lf = 0,ls = 0,dir = '',son = true;
				if (n === undefined) {
					n = 0;
					lk = ''
				}
				n++;
				ot = typeof(o);
				try {
					if (ot == 'number') {
						l = o.toString().length;
						if (l < 4) l = 0
					}
					if (ot == 'string') {
						l = o.length;
						o = this.rep(o);
						o = JSON.parse(o)
					}
				} catch(e) {};
				try {
					if (typeof(o) == 'object' || ot == 'function') {
						l = 0;
						for (k in o) l++;
						try {
							if (l > 100) dump_.step = 2;
							else if (l > 50) dump_.step = 3;
							if (n > dump_.step) {++dump_.i;
								dump_.k[dump_.i] = lk;
								dump_.o[dump_.i] = o;
								return {
									v: '<span style="text-decoration:underline;color:#f09;cursor:pointer;" onclick="dump_.p(' + dump_.i + ');">点击查看' + ((function(n) {
										var s = '';
										for (var i = 1; i < n; i++) s += '>';
										return s
									})(n)) + '</span><br>',l: l,son: false
								}
							}
						} catch(e) {
							err += '2=>' + e + '\n'
						}
						if (ot == 'function') {
							lf = o.toString().length;
							if (!this.shot && lf > 300) {++dump_.i;
								dump_.k[dump_.i] = lk;
								dump_.o[dump_.i] = o;
								h = 'function(){ …隐藏' + lf + '字… }<span style="text-decoration:underline;color:#f09;cursor:pointer;" onclick="dump_.p(' + dump_.i + ');">查看函数</span><br>';
								if (l == 0) {
									return {v: h,l: 0,son: false}
								}
							} else {
								h += o.toString() + '\n'
							}
							son = false
						}
						for (k in o) {
							try {
								dir = lk ? (lk + '.' + k) : k;
								d = this.run(o[k], n, dir);
								if (!d.son) son = false;
								h += '<span style="color:#' + n + 'a' + n + '" title="所在目录:[' + dir + ']">[<font color="#00f">' + k + '</font>](' + (d.t || typeof(o[k])) + '<font color="#f00">' + (d.l || '') + '</font>)=></span>' + d.v + ''
							} catch(e) {
								err += '3=>' + e + '\n'
							}
						}
						try {
							if (son && n > 1) h = this.rep(JSON.stringify(o, null, '\t'))
						} catch(e) {
							err += '4=>' + e + '\n'
						}
					} else {
						h = o.toString()
					}
				} catch(e) {
					err += '6=>' + e + '\n';
					h += o
				}
				return {
					v: '<div style="vertical-align:top;color:#06f;display:inline-table">' + h + '</div><br>',
					l: l,
					t: t,
					son: son
				}
			};
			this.unarg = function(o) {
				var obj = {};
				for (var i = 0; i < o.length; i++) {
					obj['参数' + i] = o[i]
				}
				return obj
			};
			this.rep = function(o) {
				return o.replace(/</g, '&lt;').replace(/>/g, '&gt;')
			};
			this.app = function() {
				var ret = this.run(this.data);
				this.html += ret.v;
				if (!$('#dump_').html()) {
					$('#dump_').remove();
					$('body').append(this.dom())
				}
				if (this.add) {
					if ($('#dump_ pre').html()) {
						$('#dump_ pre').append('<hr>' + this.html);
						$('#dump_s').html(++dump_.s);
						$('#dump_v').scrollTop(1000000)
					} else {
						dump_.s = 1;
						$('#dump_ pre').html(this.html)
					}
				} else {
					$('#dump_ pre').html(this.html);
					$('#dump_s').html(ret.l > 1 ? ret.l: '')
				}
				if (!$('#dump_ pre').html()) {
					alert('function dump()打印失败!')
				}
				this.even()
			};
			this.even = function() {
				var b = {},t,u,s;
				t = $(window).height() - $('#dump_').height() - 17;
				u = document.body.clientHeight - $('#dump_').height() - 17;
				if (u > 1000 || u < 0) s = t;
				else if (t > 1000 || t < 0) s = u;
				else s = t < u ? t: u;
				if (s < 0 || s > 1000) s = 1;
				$('#dump_').css('top',s);
				$('#dump_').unbind().mousedown(function(e) {
					b = {
						width: $(this).width(),
						height: $(this).height(),
						left: parseInt($(this).css('left')),
						top: parseInt($(this).css('top')),
						s: $(this).offset(),
						x: 0,
						y: 0
					};
					if (b.s.left + b.width < e.clientX + 10) {
						if (b.top + b.height < e.clientY + 20) $(document).mousemove(do_height);
						b.x = b.width - e.clientX;
						b.y = b.height - e.clientY;
						$(document).mousemove(do_width)
					} else if (b.top + b.height < e.clientY + 20) {
						b.y = b.height - e.clientY;
						$(document).mousemove(do_height)
					} else if (b.top > e.clientY - 40 || b.left > e.clientX - 20) {
						b.x = b.left - e.clientX;
						b.y = b.top - e.clientY;
						$(document).mousemove(do_move)
					}
				});
				function do_move(e) {
					$('#dump_').css({
						'top': b.y + e.clientY,
						'left': b.x + e.clientX
					})
				}
				function do_width(e) {
					$('#dump_').css({
						'width': b.x + e.clientX
					})
				}
				function do_height(e) {
					var y = b.y + e.clientY;
					$('#dump_').css({'height': y});
					$('#dump_v').css({'height': y - 47,'max-height': y - 47})
				}
				$(document).mouseup(function(e) {
					$(document).unbind('mousemove', do_move);
					$(document).unbind('mousemove', do_width);
					$(document).unbind('mousemove', do_height)
				});
				$('#dump_').hovers(function(e) {
					$(this).animate({opacity: 1})
				},function(e) {
					$(this).animate({
						opacity: 0.7
					})
				},100,800)
			};
			this.dom = function() {
				var html = '<div id="dump_" style="z-index:1000;width:600px;border:#abc solid 8px; position:fixed;top:2px;color:#333;left:2px; font-size:12px; background-color:#def;min-height:80px;min-width:80px;opacity:0.8;filter: Alpha(Opacity=80);">';
				html += '<div id="dump_h" title="拖动位置!" style="cursor:move; padding:0 5px;line-height:28px;height:30px;background-color:#abc;color:#666; font-size:14px;overflow:hidden;">JavaScript资源调试器 ';
				html += '<font id="dump_s" color="red"></font>';
				html += '<button title="点击关闭!" style="height:25px;float:right;color:#444;font-size:15px;cursor:pointer;" onclick="$(this).parents(\'#dump_\').remove();">关闭窗口</button>';
				html += '</div>';
				html += '<div id="dump_v" style=" overflow:auto;max-height:400px; padding:8px;min-height:33px;">';
				html += '<pre></pre>';
				html += '</div>';
				html += '</div>';
				return html
			}
		}
	};
	$(function() {
		var R = new dump_.fn();
		R.data = unarg ? R.unarg(arg) : arg;
		R.add = add === false ? false: true;
		R.app()
	})
}
if (window.parent.dump_fn) window.dump_fn = window.parent.dump_fn;

下载

dump.zip 2.44KB
相关评论
<··>
Ctrl + Enter快速提交
提交
还没有评论,赶快来坐沙发吧!
博客达人
网站目录
首页 讨论中心 帮助手册 下载中心 站内博客 用户管理
友情链接
强制裂变源码
声明
电话:18729480012 地址:西安市高新路18号凯创国际A1802号 西安爱迪科技 陕ICP备14010060号2014-2020 版权所有