可能是一个没什么用的问题,但是很有趣,想知道facebook如何在不引用脚本的情况下将内容打印到浏览器控制台。在facebook.com上打开控制台,你会看到文本,但不会看到对javascript的引用...
可能是一个没什么用的问题,但是很有趣,想知道facebook如何在不引用脚本的情况下将内容打印到浏览器控制台。在facebook.com上打开控制台,你会看到文本,但不会看到对javascript的引用...
我的朋友的朋友找到了答案。
如果想在没有引用的情况下使用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]));
});
}
if ((window.chrome || window.safari))
是无用的,因为它在 Firefox 上也能工作。 - Zibri((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!")
console.log = function(){ /* 您想要的任何魔法 */ }
- Lix