【學習筆記】瀏覽器Console個性化輸出

一、效果圖展示

 

 

 二、代碼分享,吧如下代碼封裝到js文件裏即可

/*
 * 張金奎
 * 2019-12-6 00:16:40
 * 一小羣有思想並且有着獻身精神的公民可以改變世界。不要懷疑這種說法,事實上,世界正是這樣被改變的。
 */

hitokoto();
function hitokoto() {
    $.ajax({
        type: "GET",
        url: "https://hitokoto.jijidown.com/v1/api/hitokoto?maxlength=80",
        data: {},
        dataType: "json",
        success: function (data) {
            //alert(data.hitokoto);
            console.log(data.hitokoto + "《" + data.source+"》");
        }
    });
}
if (console) {

    var outs = [], fi = function () { return { msg: "", style: "" } };

    var oi = fi();
    oi.msg = "  才雨又晴晴又雨";
    oi.style = "padding:10px 40px 10px;line-height:30px;background:url('https://images.cnblogs.com/cnblogs_com/kudsu/1298007/o_200824155830see_no_evil_monkey_310px_1214323_easyicon.net.png') no-repeat;background-size:15% 100%;font-size:1.8rem;color:rgba(184, 149, 88)";
    outs.push(oi);

    oi = fi();
    oi.msg = "https://www.netnr.com";
    oi.style = "background-image:-webkit-gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #25e),color-stop(0.75, #4f2), color-stop(0.9, #f2f), color-stop(1, #f22) );color:transparent;-webkit-background-clip: text;font-size:1.5em;"
    outs.push(oi);

    oi = fi();
    oi.msg = "\r\n微博:\nhttps://weibo.com/kudsu\r\n\r\nGitHub:\nhttps://github.com/kudsu\r\n\r\n博客園:\nhttps://www.cnblogs.com/kudsu/\r\n";
    outs.push(oi);

    if (!("ActiveXObject" in window)) {
        outs.map(function (x) {
            console.log("%c" + x.msg, x.style);
        });
    }
}

三、結束

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章