フィドラーを開く -> メニュー ルール -> ルールのカスタマイズ (またはCtrl+を押すR)
CustomRule.jsファイルが開きます。行が見つかるまで下にスクロールします
static function OnBeforeResponse(oSession: Session)
これがコードの場所です。ここでは、ブラウザが認識する前にサーバーの応答を変更できます。
次のコード サンプルは、水平メニューのUnansweredリンクをUnanswered jQuery Questionsへのショートカットとして機能するリンクに置き換える jQuery コードのカスタム部分を含める方法を示しています。
最初に、組み込みたい jQuery コードを示します
<script type='text/javascript'>
$(function() {
var newLink = '<a href="/unanswered/tagged/jquery">Unanswered jQuery</a>';
$('div#hmenus div.nav:first ul li:last a').replaceWith(newLink);
});
</script>
次に、フィドラー コード ( CustomRules.js にあるコードとFiddlerScript CookBookのコード サンプルに基づく)
//is it a html-response and is it from stackoverflow.com
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html") &&
oSession.HostnameIs("stackoverflow.com")) {
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// Match the jQuery script tag
var oRegEx = /(<script[^>]*jquery.min.js"><\/script>)/gi;
// replace the script tag withitself (no change) + append custom script tag
oBody = oBody.replace(oRegEx, "$1<script type='text/javascript'>$(function() {$('div#hmenus div.nav:first ul li:last a').replaceWith('<a href=\"/unanswered/tagged/jquery\">Unanswered jQuery</a>');})</script>");
// Set the response body to the changed body string
oSession.utilSetResponseBody(oBody);
}
問題に合ったコードをハックできるはずです。
例
// Match the head end
var oRegEx = /(<\/head>)/gi;
// replace with new script
oBody = oBody.replace(oRegEx, "<script type='text/javascript' src='http://url/myscript.js'></script>$1");