不知道大家逛 B 站时有没有注意到它控制台输出的字符画(正经人逛 B 站谁会按 F12)字符画如彩蛋般的出现在眼前,还能丰富网站的维度,一个优秀的网站也许在某个不起眼的角落也能带给你惊喜。但貌似最近没有了

教程

  • 新建JS文件,引入主题配置中。

  • 加入以下代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
      if (window.console) {
    Function.prototype.makeMulti = function () {
    let l = new String(this);
    l = l.substring(l.indexOf("/*") + 3, l.lastIndexOf("*/"));
    return l;
    };
    let string = function () {
    /*
    我是字符画
    */
    };
    console.log(string.makeMulti());
    }
    ​ 代码中"我是字符画"处用来放自定义字符画

  • Hexo 三连后,再按下F12或Ctrl + Shift + C即可看到效果,可以先看看我的博客的效果。

  • 字符画下面可以继续添加一些自定义文字(在刚才新建的 JS 文件里继续加)

    1
    2
    3
    4
    5
        */ }
    console.log(string.makeMulti());
    + console.log("<Custom>");
    + console.log("<Custom> %c <Custom>", "<样式代码>");
    + console.log("欢迎访问%Jer's Blog", "color:#1fc7b6;font-weight:bold");

  • 生成字符画

文字

图片

图片2