小编use*_*236的帖子

Google Chrome默认控制台上下文

最近在打开Goog​​le Chrome开发者控制台时,上下文出错了.

我加载一个页面,按Ctrl + Shift + J并得到这个:http://i.imgur.com/2eTJgD0.png

它有时会改变扩展名,但它应该是"顶部".

我可以每次手动更改上下文,但这样做有点烦人.

google-chrome google-chrome-devtools

15
推荐指数
1
解决办法
1480
查看次数

覆盖 XMLHttpRequest.responseText

我会尽力解释我的问题,但说实话,我自己也有点困惑,所以我无法想象这对你们来说会容易得多。

是的,我正在为我经常访问的网站的用户脚本创建一个脚本。我想做的是劫持任何ajax请求,我做得很好,然后修改responseText。

我似乎无法写入responseText,我可以很好地阅读它并且它显示了很好的响应,但无论我如何尝试,我都无法更改它的值。

我在控制台中没有收到任何错误,我在代码中留下了注释以显示记录的内容。

我本来打算放弃它,但了解我自己,我错过了一些愚蠢而明显的东西,只是看不到它。

提前致谢。

(function(send) { 
    XMLHttpRequest.prototype.send = function(data) { 
        this.addEventListener('readystatechange', function() { 
            if(typeof data == 'string'){
                if(data.indexOf('room.details_1') > -1){
                    if(this.readyState == 4 && this.status == 200){
                        console.log('Before: ' + JSON.parse(this.responseText).body.user.profile.username); // Shows NameNumber1
                        var temp = JSON.parse(this.responseText);
                        temp.body.user.profile.username = 'NameNumber2';
                        this.responseText = JSON.stringify(temp);
                        console.log('Temp: ' + temp.body.user.profile.username); // Shows NameNumber2
                        console.log('After: ' + JSON.parse(this.responseText).body.user.profile.username); // Shows NameNumber1 <-- This is the problem.
                        console.log(this); // Shows the XMLHttpRequest object, with the original responseText rather than the modified one. …
Run Code Online (Sandbox Code Playgroud)

javascript

0
推荐指数
1
解决办法
3007
查看次数