简体   繁体   English

Console.log而不参考脚本

[英]Console.log without reference to the script

Pretty useless question, I guess, but it's really interesting to find out how facebook prints to browser console without reference to the script. 我想这是一个相当无用的问题,但是如果没有参考脚本就知道facebook如何打印到浏览器控制台真的很有趣。 Open the console at facebook.com and you will see text, but won't see the reference to th javascript... 在facebook.com打开控制台,你会看到文字,但不会看到对javascript的引用...

在此输入图像描述

Well, friend of my friend found the answer. 好吧,我朋友的朋友找到了答案。

To console.log without reference we should use setTimout and bind 对于没有引用的console.log,我们应该使用setTimout和bind

setTimeout(console.log.bind(console, 'test'));

And here is the whole facebook snippet: 这是整个facebook片段:

    var i = "Stop!",
        j = "This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.";

if ((window.chrome || window.safari)) {
var l = 'font-family:helvetica; font-size:20px; ';
[
   [i, l + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'],
   [j, l],
   ['', '']
].map(function(r) {
    setTimeout(console.log.bind(console, '\n%c' + r[0], r[1]));
});
}

More generic function. 更通用的功能。
If run with () instead of ("Your title here","Your text here") 如果用()而不是(“你的标题在这里”,“你的文字在这里”)运行
it will display the default message. 它将显示默认消息。

((title,message)=>{
    var i = title || "Stop!"
      , j = message || "This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.";

    var l = 'font-family:helvetica; font-size:20px; ';
    [[i, l + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'], [j, l], ['', '']].map(function(r) {
        setTimeout(console.log.bind(console, '\n%c' + r[0], r[1]));
    });
})("Your title here","Your text here")

or directly: 或直接:

console.alert = function(title, message) {
  var i = title || "Stop!",
    j = message || "This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.";

  var l = 'font-family:helvetica; font-size:20px; ';
  [
    [i, l + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'],
    [j, l],
    ['', '']
  ].map(function(r) {
    setTimeout(console.log.bind(console, '\n%c' + r[0], r[1]));
  });
}

and

console.alert("Hello", "You can write what you like here!")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM