web 練手 JavaScript 輸出

freepbx發表於2020-12-03
<template>
 <div id="debug" class="debug"></div>
</template>
<script type="text/javascript">
  Date.prototype.format = function (t) {
  if (!this.valueOf()) return " ";
  var e = ["\u661f\u671f\u4e00", "\u661f\u671f\u4e8c", "\u661f\u671f\u4e09", "\u661f\u671f\u56db", "\u661f\u671f\u4e94",
  "\u661f\u671f\u516d", "\u661f\u671f\u65e5"],
  r = this;
  return t.replace(/(yyyy|yy|MM|dd|E|hh|HH|hi|mm|mt|mi|ss|sm|a\/p)/gi, function (t) {
  switch (t) {
  case "yyyy":
  return r.getFullYear();
  case "yy":
  return (r.getFullYear() % 1e3).zf(2);
  case "mt":
  case "MM":
  return (r.getMonth() + 1).zf(2);
  case "dd":
  return r.getDate().zf(2);
  case "E":
  return e[r.getDay()];
  case "hi":
  case "HH":
  return r.getHours().zf(2);
  case "hh":
  return ((h = r.getHours() % 12) ? h : 12).zf(2);
  case "mm":
  case "mi":
  return r.getMinutes().zf(2);
  case "ss":
  return r.getSeconds().zf(2);
  case "sm":
  return r.getMilliseconds().zf(3);
  case "a/p":
  return r.getHours() < 12 ? "\u4e0a\u5348" : "\u4e0b\u5348" ; default: return t } }) },
    String.prototype.string=function (t) { for (var e="" , r=0; r++ < t;) e +=this; return e },
    String.prototype.zf=function (t) { return "0" .string(t - this.length) + this }, Number.prototype.zf=function (t) {
    return this.toString().zf(t) }; console.log=function (...obj) { console.info(...obj); var outStr=new
    Date().format('<time>mi:ss.sm ></time></time></time></time></time></time></time> </time></time></time>\t\t\t');
    obj.forEach((o) => {
    t = o.constructor.toString().replace(/^function (.*)\(.*/,"$1").replace("Object","Obj");
    typeList = ["Map", "Set"];
    if (typeList.includes(t)) {
    o = Array.from(o);
    }
    outStr += `<${t}>${ (t == "Function") ?o.toString(): JSON.stringify(o)}</${t}>\t`;
    });
    var debugout = document.querySelectorAll('#debug,.debug,#console,.console');
    if (debugout.length > 0) {
    debugout = debugout[0];
    debugout.innerHTML += '<br>' + outStr;
    debugout.scrollTop = debugout.scrollHeight - debugout.clientHeight;
    } else {
    document.write(outStr + '<br>');
    }
    }
</script>
<style media="screen">
  #debug {
  box-sizing: border-box;
  border-top: 1px solid gray;
  margin: 0;
  padding: 10px;
  position: absolute;
  left: 0;
  bottom: 0;
  background: #ede8f2;
  width: 100vw;
  height: auto;
  min-height: 80px;
  max-height: 60vh;
  overflow: scroll;
  }

  #debug Set::before {
  content: 'Set ';
  }

  #debug Map::before {
  content: 'Map ';
  }

  #debug Array::before {
  content: 'Array ';
  }

  #debug Obj::before {
  content: 'Object ';
  }

  #debug * {
  color: #0000ff;
  font: 1.5em;
  }
  #debug time {
  color: darkblue;
  }

  #debug String {

  }
  #debug Number {

  }
  #debug Array {

  }
  #debug Set {

  }
  #debug Set {

  }

</style>

 

相關文章