久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='EkVaI'></tfoot>
<i id='EkVaI'><tr id='EkVaI'><dt id='EkVaI'><q id='EkVaI'><span id='EkVaI'><b id='EkVaI'><form id='EkVaI'><ins id='EkVaI'></ins><ul id='EkVaI'></ul><sub id='EkVaI'></sub></form><legend id='EkVaI'></legend><bdo id='EkVaI'><pre id='EkVaI'><center id='EkVaI'></center></pre></bdo></b><th id='EkVaI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EkVaI'><tfoot id='EkVaI'></tfoot><dl id='EkVaI'><fieldset id='EkVaI'></fieldset></dl></div>
  • <small id='EkVaI'></small><noframes id='EkVaI'>

    <legend id='EkVaI'><style id='EkVaI'><dir id='EkVaI'><q id='EkVaI'></q></dir></style></legend>
      • <bdo id='EkVaI'></bdo><ul id='EkVaI'></ul>

        使用用戶腳本捕獲頁面 xmlhttp 請求

        capture a pages xmlhttp requests with a userscript(使用用戶腳本捕獲頁面 xmlhttp 請求)

            <bdo id='HWZBM'></bdo><ul id='HWZBM'></ul>

            <legend id='HWZBM'><style id='HWZBM'><dir id='HWZBM'><q id='HWZBM'></q></dir></style></legend>
              <tfoot id='HWZBM'></tfoot>
                <tbody id='HWZBM'></tbody>
              <i id='HWZBM'><tr id='HWZBM'><dt id='HWZBM'><q id='HWZBM'><span id='HWZBM'><b id='HWZBM'><form id='HWZBM'><ins id='HWZBM'></ins><ul id='HWZBM'></ul><sub id='HWZBM'></sub></form><legend id='HWZBM'></legend><bdo id='HWZBM'><pre id='HWZBM'><center id='HWZBM'></center></pre></bdo></b><th id='HWZBM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HWZBM'><tfoot id='HWZBM'></tfoot><dl id='HWZBM'><fieldset id='HWZBM'></fieldset></dl></div>
              • <small id='HWZBM'></small><noframes id='HWZBM'>

                1. 本文介紹了使用用戶腳本捕獲頁面 xmlhttp 請求的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個用戶腳本(用于 chrome 和 FF),它為頁面添加了重要功能,但最近由于開發人員在頁面中添加了一些 AJAX 而被破壞.我想修改腳本以偵聽頁面 xmlhttp 請求,以便我可以根據頁面正在接收的 JSON 格式的 responseText 動態更新我添加的內容.

                  I have a user script (for chrome and FF) that adds significant functionality to a page, but has recently been broken because the developers added some AJAX to the page. I would like to modify the script to listen to the pages xmlhttp requests, so that I can update my added content dynamically, based on the JSON formatted responseText that the page is receiving.

                  搜索發現了許多應該工作的功能,并且在控制臺中運行時可以工作.但是,它們不會從用戶腳本的上下文中執行任何操作.

                  A search has turned up many functions that SHOULD work, and do work when run in the console. However they do nothing from the context of a user script.

                  (function(open) {
                  
                      XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
                  
                          this.addEventListener("readystatechange", function() {
                              console.log(this.readyState);
                          }, false);
                  
                          open.call(this, method, url, async, user, pass);
                      };
                  
                  })(XMLHttpRequest.prototype.open);
                  

                  來自:如何我可以從 Greasemonkey 腳本中截獲 XMLHttpRequests 嗎?

                  這在控制臺中完美運行,我可以將 this.readyState 更改為 this.responseText 并且效果很好(盡管在腳本中我需要它來打開JSON 數據轉換成一個對象,然后讓我在用戶腳本中對其進行操作.不僅僅是寫入控制臺).但是,如果我將其粘貼到用戶腳本中,則不會發生任何事情.用戶腳本中的事件處理程序似乎沒有檢測到頁面上的 xmlhttp 請求.

                  This works perfectly in the console, I can change this.readyState to this.responseText and it works great (though in the script I will need it to turn the JSON data into an object, and then let me manipulate it within the userscript. Not just write to the console). However if I paste it into a userscript nothing happens. The xmlhttp requests on the page do not seem to be detected by the event handler in the userscript.

                  執行請求的頁面正在使用 jquery $.get() 函數,如果這可能與它有關的話.雖然我不這么認為.

                  The page doing the requesting is using the jquery $.get() function, if that could have anything to do with it. Though I don't think it does.

                  我無法想象沒有辦法,似乎任何在 AJAX 頁面上運行的用戶腳本都需要這種能力.

                  I can't imagine that there isn't a way, seems like any userscript running on an AJAX page would want this ability.

                  推薦答案

                  由于頁面使用了$.get(),因此攔截請求更加容易.使用 ajaxSuccess().

                  Since the page uses $.get(), it's even easier to intercept requests. Use ajaxSuccess().

                  這將在 Greasemonkey(Firefox) 腳本中工作:
                  片段 1:

                  This will work in a Greasemonkey(Firefox) script:
                  Snippet 1:

                  unsafeWindow.$('body').ajaxSuccess (
                      function (event, requestData)
                      {
                          console.log (requestData.responseText);
                      }
                  );
                  

                  假設頁面以正常方式使用jQuery($定義等).

                  Assuming the page uses jQuery in the normal way ($ is defined, etc.).


                  這應該適用于 Chrome 用戶腳本(以及 Greasemonkey):
                  片段 2:

                  This should work in a Chrome userscript (as well as Greasemonkey):
                  Snippet 2:

                  function interceptAjax () {
                      $('body').ajaxSuccess (
                          function (event, requestData)
                          {
                              console.log (requestData.responseText);
                          }
                      );
                  }
                  
                  function addJS_Node (text, s_URL, funcToRun) {
                      var D                                   = document;
                      var scriptNode                          = D.createElement ('script');
                      scriptNode.type                         = "text/javascript";
                      if (text)       scriptNode.textContent  = text;
                      if (s_URL)      scriptNode.src          = s_URL;
                      if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
                  
                      var targ    = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
                      targ.appendChild (scriptNode);
                  }
                  
                  addJS_Node (null, null, interceptAjax);
                  

                  <小時><小時><小時>

                  回復:




                  Re:

                  但是我如何將這些數據獲取到腳本中?...(這樣我可以)稍后在腳本中使用這些數據."

                  "But how then do I get that data to the script? ... (So I can) use the data later in the script."

                  這適用于 Greasemonkey(Firefox);它也可能適用于 Chrome 的 Tampermonkey:
                  片段 3:

                  This works in Greasemonkey(Firefox); it might also work in Chrome's Tampermonkey:
                  Snippet 3:

                  function myAjaxHandler (requestData) {
                      console.log ('myAjaxHandler: ', requestData.responseText);
                  }
                  
                  unsafeWindow.$('body').ajaxSuccess (
                      function (event, requestData) {
                          myAjaxHandler (requestData);
                      }
                  );
                  


                  但是,如果不這樣做,那么您將無法(輕松地)在 Chrome 用戶腳本和目標頁面之間共享 JS 信息——這是設計使然.


                  But, if it doesn't then you cannot share JS information (easily) between a Chrome userscript and the target page -- by design.

                  通常您所做的是注入整個用戶腳本,以便所有內容都在頁面范圍內運行.像這樣:
                  片段 4:

                  Typically what you do is inject your entire userscript, so that everything runs in the page scope. Like so:
                  Snippet 4:

                  function scriptWrapper () {
                  
                      //--- Intercept Ajax
                      $('body').ajaxSuccess (
                          function (event, requestData) {
                              doStuffWithAjax (requestData);
                          }
                      );
                  
                      function doStuffWithAjax (requestData) {
                          console.log ('doStuffWithAjax: ', requestData.responseText);
                      }
                  
                      //--- DO YOUR OTHER STUFF HERE.
                      console.log ('Doing stuff outside Ajax.');
                  }
                  
                  function addJS_Node (text, s_URL, funcToRun) {
                      var D                                   = document;
                      var scriptNode                          = D.createElement ('script');
                      scriptNode.type                         = "text/javascript";
                      if (text)       scriptNode.textContent  = text;
                      if (s_URL)      scriptNode.src          = s_URL;
                      if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
                  
                      var targ    = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
                      targ.appendChild (scriptNode);
                  }
                  
                  addJS_Node (null, null, scriptWrapper);
                  

                  這篇關于使用用戶腳本捕獲頁面 xmlhttp 請求的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)
                    <bdo id='hiTlC'></bdo><ul id='hiTlC'></ul>

                      <legend id='hiTlC'><style id='hiTlC'><dir id='hiTlC'><q id='hiTlC'></q></dir></style></legend>
                    1. <i id='hiTlC'><tr id='hiTlC'><dt id='hiTlC'><q id='hiTlC'><span id='hiTlC'><b id='hiTlC'><form id='hiTlC'><ins id='hiTlC'></ins><ul id='hiTlC'></ul><sub id='hiTlC'></sub></form><legend id='hiTlC'></legend><bdo id='hiTlC'><pre id='hiTlC'><center id='hiTlC'></center></pre></bdo></b><th id='hiTlC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hiTlC'><tfoot id='hiTlC'></tfoot><dl id='hiTlC'><fieldset id='hiTlC'></fieldset></dl></div>

                      <small id='hiTlC'></small><noframes id='hiTlC'>

                          <tfoot id='hiTlC'></tfoot>
                            <tbody id='hiTlC'></tbody>

                            主站蜘蛛池模板: 超碰精品在线 | 欧美国产日韩成人 | 午夜国产精品视频 | 草久久久 | 亚洲精品久久久久久宅男 | 日韩欧美在线免费观看 | 一区二区视频免费观看 | 亚洲一区免费视频 | 日韩精品av一区二区三区 | 亚洲精品区 | 中文字幕三区 | 在线 丝袜 欧美 日韩 制服 | 成人国产网站 | 日韩激情网 | 九九热国产精品视频 | 欧美日韩成人影院 | 精精国产xxxx视频在线播放 | 欧美一区二区在线免费观看 | 亚洲第一视频 | 91精品综合久久久久久五月天 | 天天操夜夜操 | 亚洲精品视频免费 | 在线精品亚洲欧美日韩国产 | 国产一区二区三区 | 国产成人精品一区二区三 | 国产精品免费看 | av一区二区三区四区 | 在线观看视频一区 | 亚洲精品一区二区三区在线 | 午夜爱爱网 | 天天狠狠 | 欧美性影院| 亚洲一区二区三区免费在线 | 欧美日韩大陆 | 日韩视频一区在线观看 | 伊人电影院av | 日韩中文字幕在线不卡 | 精品欧美 | 久久久久国产一区二区三区不卡 | 国产精品一区久久久 | 日韩播放|