Console.log而不参考脚本

时间:2014-08-30 22:14:37

标签: javascript facebook console.log

我猜这是一个相当无用的问题,但是如果没有参考脚本就知道facebook如何打印到浏览器控制台真的很有趣。在facebook.com打开控制台,你会看到文字,但不会看到对javascript的引用...

enter image description here

2 个答案:

答案 0 :(得分:5)

好吧,我朋友的朋友找到了答案。

对于没有引用的console.log,我们应该使用setTimout和bind

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

这是整个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]));
});
}

答案 1 :(得分:0)

更多通用功能。
如果使用()而不是(“此处的标题”,“此处的文本”)运行
它将显示默认消息。

((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")

或直接:

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]));
  });
}

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