📄 debug.js
字号:
window.onload=init;
var moveable=false;
var debugWin;
var leftOff=0,topOff=0;
var debugEnable=true;
function init(){
initDrag();
initCtrWin();
initEnableBtn();
initCheckBoxes();
info("hello");
warn("hello");
error("hello");
}
function initDrag(){
var header=document.getElementById("head");
header.onmousedown=startDrag;
header.onmousemove=drag;
header.onmouseup=endDrag;
debugWin=header.parentNode;
debugWin.style.left='0px';
debugWin.style.top='0px';
}
function initCtrWin(){
var header=document.getElementById("head");
var minBtn=header.children[1];
var closeBtn=header.children[2];
minBtn.onclick=min;
closeBtn.onclick=close;
}
function initEnableBtn(){
var enableBtn=document.getElementById("debug").children[1].children[3].children[1];
enableBtn.onclick=pause;
}
function initCheckBoxes(){
var checkBoxes=document.getElementById("debug").getElementsByTagName("INPUT");
checkBoxes[0].onclick=shInfo;
checkBoxes[1].onclick=shWarn;
checkBoxes[2].onclick=shError;
}
function startDrag(){
if(window.event.button==1){
this.setCapture();
leftOff=window.event.clientX-parseInt(debugWin.style.left);
topOff=window.event.clientY-parseInt(debugWin.style.top);
moveable=true;
}
}
function drag(){
if(moveable){
debugWin.style.left=window.event.clientX-leftOff;
debugWin.style.top=window.event.clientY-topOff;
}
}
function endDrag(){
if(window.event.button==1){
moveable=false;
this.releaseCapture();
}
}
function min(){
var body=this.parentNode.parentNode.children[1];
if(this.innerHTML==0){
this.innerHTML=2;
body.style.display='none';
}
else{
this.innerHTML=0;
body.style.display='block';
}
}
function close(){
var debug=this.parentNode.parentNode;
document.getElementsByTagName("body")[0].removeChild(debug);
}
function info(info){
if(debugEnable){
var content=debugWin.children[1].children[0];
var infoSpan=document.createElement("span");
var date=new Date();
var hour=date.getHours();
var minute=date.getMinutes();
var sec=date.getSeconds();
infoSpan.type="info";
infoSpan.style.color="green";
infoSpan.style.width="200px";
infoSpan.style.overflow="auto";
infoSpan.style.fontFamily="Arial";
infoSpan.innerHTML='<B>INFO: </B>'+info+' ^--^ '+hour+':'+minute+':'+sec;
content.appendChild(infoSpan);
}
}
function warn(warn){
if(debugEnable){
var content=debugWin.children[1].children[0];
var infoSpan=document.createElement("span");
var date=new Date();
var hour=date.getHours();
var minute=date.getMinutes();
var sec=date.getSeconds();
infoSpan.type="warn";
infoSpan.style.color="orange";
infoSpan.style.width="200px";
infoSpan.style.overflow="auto";
infoSpan.style.fontFamily="Arial";
infoSpan.innerHTML='<B>WARN: </B>'+warn+' ~,~ '+hour+':'+minute+':'+sec;
content.appendChild(infoSpan);
}
}
function error(error){
if(debugEnable){
var content=debugWin.children[1].children[0];
var infoSpan=document.createElement("span");
var date=new Date();
var hour=date.getHours();
var minute=date.getMinutes();
var sec=date.getSeconds();
infoSpan.type="error";
infoSpan.style.color="red";
infoSpan.style.width="200px";
infoSpan.style.overflow="auto";
infoSpan.style.fontFamily="Arial";
infoSpan.innerHTML='<B>ERROR: </B>'+error+' *--* '+hour+':'+minute+':'+sec;
content.appendChild(infoSpan);
}
}
function pause(){
if(debugEnable){
this.children[0].src='./pause.png';
debugEnable=false;
}
else{
this.children[0].src='./resume.png';
debugEnable=true;
}
}
function shInfo(){
var content=debugWin.children[1].children[0];
var allSpan=content.children;
if(this.checked){
for(var i=0;i<allSpan.length;i++){
if(allSpan[i].type=="info")
allSpan[i].style.display='block';
}
}
else{
for(var i=0;i<allSpan.length;i++){
if(allSpan[i].type=="info")
allSpan[i].style.display='none';
}
}
}
function shWarn(){
var content=debugWin.children[1].children[0];
var allSpan=content.children;
if(this.checked){
for(var i=0;i<allSpan.length;i++){
if(allSpan[i].type=="warn")
allSpan[i].style.display='block';
}
}
else{
for(var i=0;i<allSpan.length;i++){
if(allSpan[i].type=="warn")
allSpan[i].style.display='none';
}
}
}
function shError(){
var content=debugWin.children[1].children[0];
var allSpan=content.children;
if(this.checked){
for(var i=0;i<allSpan.length;i++){
if(allSpan[i].type=="error")
allSpan[i].style.display='block';
}
}
else{
for(var i=0;i<allSpan.length;i++){
if(allSpan[i].type=="error")
allSpan[i].style.display='none';
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -