需要帮助调试greasemonkey脚本 [英] Need help debugging greasemonkey script

查看:105
本文介绍了需要帮助调试greasemonkey脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里很新,就像GM脚本一样新。在这里的一些成员Brock和其他人的帮助下,我正在取得进展。



我目前有调试Greasemonkey脚本的问题,但由于某些原因没有得到它的悬念。我的第一个问题,调试使用console.log为firebug。



有时我找到日志,大多数时候我无法找到任何东西,猜测我错了。然后尝试使用alert来查看变量值...同一个故事。



我正在尝试获取脚本来处理网站上的一些拍卖 Trada.net 在Brock Adams的伟大帮助下,我们已经超过了一半,但是我仍然在JS脚本编写我的头脑...安静的一个新的经验,如果你以前我已经习惯了15年以前的涡轮增压。:)



嗯,目前这是我在脚本中的一些:

  // == UserScript == 
// @name bid to test3
// @include http://www.trada .net / *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// == / UserScript ==


// ---创建一个单元,用于将日期从页面范围发送到GM范围。
$('body')。 prepend('< div id =LatestJSON_Data>< / div>');

var J_DataCell = $('#LatestJSON_Data');


// ---在页面的AJAX上调用并粘贴数据到我们的特殊div中。
unsafeWindow $('body')。ajaxSuccess(
function(event,requestData)
{
J_DataCell.text(requestData.responseText);
}
);

// **出价函数和var's
// ** var interval = 50;
// ** var bidClickTimer = setInterval(function(){BidClick();},interval);
// ** var numBidClicks = 0;
// ** var A1reset_go = false;



// **功能BidClick1()
// ** {var //bidBtn1=document.getElementById(\"ctl00_mainContentPlaceholder_AirtimeAuctionItem1_btn_BidButton);


// ** numBidClicks ++;
// ** if(numBidClicks> 10)
// ** {Alert(check10);
// ** clearInterval(bidClickTimer);
// ** bidClickTimer =;
// **}
// ** else
// ** {Alert(check11);
// ** bidBtn1.click(1);

// **}
// **};

// **结束出价功能

// ---监听特殊div的更改并解析数据。
J_DataCell.bind('DOMSubtreeModified',ParseJSON_Data);

函数ParseJSON_Data()
{

// **我的var
// ** var auction_type; A1_upto; A1_start; A1_current; A1_reset;
// ** end我的var

// ---从特殊单元格获取最新的数据并解析它。
var myJson = J_DataCell.text();
var jsonObj = $ .parseJSON(myJson);

// --- JSON应该返回一个名为d的二维数组。
var BidDataArray = jsonObj.d;

// ---循环遍历数组中的每一行。
$ .each(
BidDataArray,
函数(rowIndex,rowValue){

// ---打印第7列
console.log ('Row:'+(parseInt(rowIndex)+ 1)+'Column:7 Value:'+ rowValue [6]);

// **我的部分
// * * alert(check1);
// ** auction_type = parseInt(rowValue [4]);
// ** if(auction_type == 1)
// **
// ** {Alert(check2);
// ** A1_upto = parseInt(rowValue [12]);
// ** Alert(check3);
// ** A1_current = parseInt(rowValue [8]);
// ** Alert(check4);
// ** A1_reset = rowValue [16];
// ** if(A1_reset!=null)
// ** {Alert(check5);
// ** A1reset_go ='true';
// * *};
// ** if(A1_reset ==null)和(A1reset_go =='true')
// ** {Alert(check6);
/ / ** A1reset_go = false;
// ** Alert(check7);
// ** A1_start = rowValue [8];
/ / **};
// ** if((A1_current - A1_start)< =(A1_upto - 10))
// ** {Alert(check8);
// ** BidClick1();
// **};
// **};

// **结束我的部分

};
);
}


// ---使用CSS格式化我们的特殊单元格。添加visibility:hidden;或display:none;,如果需要。
GM_addStyle((<<![CDATA [
#LatestJSON_Data
{
background:gold;
border:3px ridge#0000DD;
font-size:10px;
margin:0 2em;
padding:1ex 1em;
width:94%;
opacity:0.8;
overflow:
z-index:666;
position:absolute;
color:black;
}
]]>< />)toString() ;

到目前为止,它确实创建了 其中显示所有投放数据的单元格转入数组 BidDataArray



我想使用阵列中的数据,每秒更新一次,以获取某些数据,然后决定是否点击出价按钮。



对于第一次拍卖,我得到了一个静止。定时拍卖我得到它每工作几秒钟点击。



在第一次拍卖会上,我基本上想要:


  1. 检查哪个拍卖是,

  2. 确定是否是拍卖的首次出价,

  3. 将出价提高到金额,

  4. 进行计算,开始点击拍卖的最后10次点击。

  5. 重置起始金额。

听起来很简单,但没有调试器,很少关于Js和GM的知识,它让我很忙。我试过把我的Var的控制台日志,但不能跟踪他们。可能已经声明错误,或者错误地使用它们...但是我看不到错误,我没有调试器来测试它们。



一个java调试器会工作吗?但它没有链接到网站...



此外,当我将部件添加到Brock的代码中,它没有显示信息的单元格...所以在某个地方我打破了他的代码我无法找到问题...在我添加任何东西到他的代码之前,它运行良好,然后我添加了我的零件,它没有工作,所以我把它拿出来使用/ /。所以脚本应该跳过它,但他的部分不再工作了。我尝试添加警报,但似乎找不到问题。我的所有零件都标有// **,此时应该处于非活动状态。



任何帮助将不胜感激。谢谢

解决方案

嗯,我没有从这里得到很多回应,但我试过... :(我设法得到它调试了90%,但这里是我的答案sofar ...将更新它后,我找到了一个方法在小故障..:

  // == UserScript == 
// @name让我们试试3.42
// @include http://www.trada.net/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// == / UserScript ==
var auctiontyp = 0; var aupto = 0 ; var A1_start = 0; var A1_current = 0; var A1_rest ='x';
// **出价函数和var's
var interval = 50;
var bidClickTimer = setInterval(function ){BidClick1();},interval);
var numBidClicks = 0;
var A1reset_go = false;

函数BidClick1()

{ var bidBtn1 = document.getElementById(ctl00_mainContentPlaceholder_AirtimeAuctionItem1_btn_BidButton);


numB idClicks ++;
if(numBidClicks> 3)
{alert(check10);
clearInterval(bidClickTimer);
bidClickTimer =;
}
else
{alert('check11');
//bidBtn1.click(1);

}
};



//结束出价功能

var myJson ='{d:[[,,y ZAR,1,49517,6458,8270,8270,8270,7635,null,1.40,6458,0:13:30,,12 ,C,30,null],[y, - 00:00,y,ZAR,2,49593,6458,6458,6458,6488,548 6458,null2.92,6458,0:13:37,,12,,L,12,Ve4mYdrvkkQMKxBH1\ / 1VMtDTCDQBRspg5jB8jjY08zg =] ,,y,ZAR,3,49058,7456,9216,6485,5153,7466,null,194.40,7456,0:00:31 ,1100,,T,null,null],[,,y,ZAR,4,49597,2935,6545 null,1.22,2935,0:01:16,,12,,T,null,null],[,,y ,5,49590,4440,0518,5343,2625,4848,null,0.95,4440,0:15:58,,5 L,null,null],[,,y,ZAR,6,49591,4848,4440,4440,0518,2625,null,1.81 4848,0:16:05,,12,,L,null,null],[,,y,ZAR 49595,6458,null,5.55,6458,0:04:13,,55,,T,null,null],[ ,Y,ZAR,8,49596,,null,2.90,NONE,0:04:35,,29 T,null,null],[ ,,y,ZAR,9,49496,6458,2427,2427,7863,5845,null,2.56,6458,0:06:07 ,10,,B,null,null],[,,y,ZAR,10,49524,6458,2427,7863,7863 ,5845,null,1.67,6458,0:06:00,,5,,B,null,null],[,, ,ZAR,11,49539,6458,2427,7863,7863,0764,null,2.02,6458,0:04:25, ,,B,null,null]]}'
var jsonObj = $ .parseJSON(myJson);

// --- JSON应该返回一个名为d的二维数组。
var arrayOfAuctions = jsonObj.d;

// ---循环遍历数组中的每一行。
$ .each(
arrayOfAuctions,
函数(rowIndex,singleAuctionData){

// ---打印第7列
console.log ('Row:'+(parseInt(rowIndex)+ 1)+'Column:7 Value:'+ singleAuctionData [6]);
alert('test3.41');
auctiontyp = parseInt singleAuctionData [4]);
if(auctiontyp == 1)

{
aupto = parseInt(singleAuctionData [15]); alert('check2.6');
alert('check3'+(singleAuctionData [8]));
A1_current = parseFloat(singleAuctionData [8]);
alert('check4'+(singleAuctionData [16]));
A1_rest = singleAuctionData [16];
alert(A1_rest);
if(A1_rest!='null')
{alert('check5');
A1reset_go = true;
};
alert('check5.1');
alert(A1reset_go);
if(A1_rest =='null')和(A1reset_go == true)
{alert('check6');
A1rese t_go = false;
alert('check7');
A1_start = singleAuctionData [8];
};
alert('check7.3');
alert((A1_current));
alert((A1_start));
alert((aupto));
if(((A1_current - A1_start)* 100)<(aupto - 10))
{alert('check8');
// BidClick1();
};

};
}
);

我目前在此脚本中的问题:



1.BidClick1函数运行在脚本的开头,而不被调用,我只将其称为接近尾声,但是它不运行。
2.这部分:

  A1_rest = singleAuctionData [16]; 
alert(A1_rest);
if(A1_rest!='null')
{alert('check5');
A1reset_go = true;
};
alert('check5.1');
alert(A1reset_go);
if(A1_rest =='null')和(A1reset_go == true)
{alert('check6');
A1reset_go = false;
alert('check7');
A1_start = singleAuctionData [8];
};

不正确执行,对于这个数组,arrayOfAuctions在第一个segmant上,做所有的测试,A1_rest应该是=null,但它不是,因此它执行:

  if(A1_rest!='null')
{alert('check5');
A1reset_go = true;
};

,并且它不执行此语句:

  if(A1_rest =='null')和(A1reset_go == true)
{alert('check6');
A1reset_go = false;

正确,只有在A1_rest =null且A1_reset_go为真时才执行执行,无论哪一个是真的,如果我把它作为: if((A1_rest =='null')和(A1reset_go == true)),它不运行这个脚本在所有的。



如果any1得到一个完整的答案,我会把它标记为这样
谢谢
alert('check7') ;
A1_start = singleAuctionData [8];
};始终执行


I'm quite new here, and just as new with GM scripting. With the help of some of the members here, Brock and others, I'm making progress.

I currently have the problem of debugging Greasemonkey scripts, but for some reason I'm not getting the hang of it. My first problem, to debug using console.log for firebug.

Sometimes I find the logs, most of the times I cant find anything there, guess I'm using it wrongly. Then trying to use alert in order to see variable values... same story.

I'm currently trying to get a script going to handle some auctions on the site Trada.net with the great help of Brock Adams, we got more than halfway there, but I'm still hitting my head on JS scripting... quiet a new experience, if u take I was used to turbo pascal 15 + years ago.:)

Well, currently this is what I got together on the script:

 // ==UserScript==
// @name           bid up to test3
// @include         http://www.trada.net/*
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// ==/UserScript==


//--- Create a cell for transmitting the date from page scope to GM scope.
$('body'). prepend ('<div id="LatestJSON_Data"></div>');

var J_DataCell          = $('#LatestJSON_Data');


//--- Eavesdrop on the page's AJAX calls and paste the data into our special div.
unsafeWindow.$('body').ajaxSuccess (
    function (event, requestData)
    {
        J_DataCell.text (requestData.responseText);
    }
);

// **bid function and var's
// **var interval            = 50;
// **var bidClickTimer       = setInterval (function() {BidClick (); }, interval);
// **var numBidClicks        = 0;
// **var A1reset_go          = false;



// **function BidClick1 ()
// **{var //bidBtn1=document.getElementById("ctl00_mainContentPlaceholder_AirtimeAuctionItem1_btn_BidButton");


//**    numBidClicks++;
//**    if (numBidClicks > 10)
//**    {   Alert("check10");
//**        clearInterval (bidClickTimer);
//**        bidClickTimer   = "";
//**    }
//**    else
//**    {   Alert("check11");
//**        bidBtn1.click (1);

//**    }
//**};

//**end bid function

//--- Listen for changes to the special div and parse the data.
J_DataCell.bind ('DOMSubtreeModified', ParseJSON_Data);

function ParseJSON_Data ()
{

//**my var
//**var auction_type ;A1_upto;A1_start;A1_current;A1_reset;
//**end my var

    //--- Get the latest data from the special cell and parse it.
    var myJson              = J_DataCell.text ();
    var jsonObj             = $.parseJSON (myJson);

    //--- The JSON should return a 2-D array, named "d".
    var BidDataArray        = jsonObj.d;

    //--- Loop over each row in the array.
    $.each (
        BidDataArray,
        function (rowIndex, rowValue) {

            //--- Print the 7th column.
            console.log ('Row: ' + (parseInt (rowIndex) + 1) + ' Column: 7  Value: ' + rowValue[6]);

//** my part
//**   Alert("check1");
//**  auction_type=parseInt (rowValue[4]);
//**   if (auction_type== 1)
//**
//**     {Alert("check2");
//**      A1_upto=parseInt (rowValue[12]);
//**       Alert("check3");
//**      A1_current=parseInt (rowValue[8]);
//**       Alert("check4");
//**      A1_reset=rowValue[16];
//**       if (A1_reset != "null")
//**         {Alert("check5");
//**          A1reset_go='true';
//**          };
//**       if (A1_reset == "null") and (A1reset_go=='true')
//**         {Alert("check6");
//**          A1reset_go=false;
//**          Alert("check7"); 
//**          A1_start=rowValue[8];
//**          };
//**        if  ((A1_current - A1_start) <= (A1_upto - 10))
//**          {Alert("check8");
//**           BidClick1 ();
//**           };
//**      };

//** end my part

      };
    );
}


//--- Format our special cell with CSS.  Add "visibility: hidden;" or "display: none;", if desired.
GM_addStyle ( (<><![CDATA[
    #LatestJSON_Data
    {
        background:         gold;
        border:             3px ridge #0000DD;
        font-size:          10px;
        margin:             0 2em;
        padding:            1ex 1em;
        width:              94%;
        opacity:            0.8;
        overflow:           hidden;
        z-index:            666;
        position:           absolute;
        color:              black;
    }
]]></>).toString () );

Basically, so far, it did create a cell in which it displays all the auction data which was put into an array BidDataArray.

I want to use the data in the array, which is updated every second, to get certain pieces of data,and then decide whether or not to click on the bid button.

For the first auction I got to a stand still. The timer auctions I got it to work to click every few seconds.

On the first auction I basically want to:

  1. Check which auction it is,
  2. Find out if it is the first bid for auction,
  3. Get the bid up to amount,
  4. Do calculations to start clicking the last 10 clicks of the auction.
  5. Reset the starting amount.

Sounds quite simple, but without a debugger and very little knowledge about Js and GM, it is keeping me quite busy. I've tried putting my Var's in console log, but cant track them. might have declared them wrongly, or used them wrongly... but I cant see the mistake, and I don't have an debugger to test them.

Will a java debugger work? but it is not linked to the site...

Also, the moment I added my parts into Brock's code, it didn't display the cell with the info any more... so somewhere I broke his code I cant find the problem... Before i added anything to his code, it worked well, then i added my parts, it didnt work any more, so i took it out by using "//". so the script should skip it, but his parts dont work anymore. I tried adding "alerts", but cant seem to find the problem. all my parts is marked with "//**" and should be inactive at the moment.

Any help will be appreciated. Thanks

解决方案

Well, I didnt get much response from here, but I've tried...:( I managed to get it debugged 90%, but here is my answer sofar...will update it after i've found a way aroud the minor glitches..:

// ==UserScript==
// @name            let's try 3.42
// @include         http://www.trada.net/*
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// ==/UserScript==
var auctiontyp = 0;var aupto = 0;var A1_start  = 0;var A1_current = 0;var A1_rest= 'x';
// **bid function and var's
var interval            = 50;
var bidClickTimer       = setInterval (function() {BidClick1 (); }, interval);
var numBidClicks        = 0;
var A1reset_go          = false;

function BidClick1 ()

{var bidBtn1=document.getElementById("ctl00_mainContentPlaceholder_AirtimeAuctionItem1_btn_BidButton");


    numBidClicks++;
    if (numBidClicks > 3)
    {   alert("check10");
       clearInterval (bidClickTimer);
        bidClickTimer   = "";
    }
    else
    {   alert('check11');
        //bidBtn1.click (1);

    }
};



// end bid function

var myJson              = '{"d":[["","","y","ZAR","1","49517","6458, 8270, 8270, 8270, 7635",null,"1.40","6458","0:13:30","","12","","C","30",null],["y","-00:00","y","ZAR","2","49593","6458, 6458, 6458, 6458, 6458",null,"2.92","6458","0:13:37","","12","","L","12","Ve4mYdrvkkQMKxBH1\/1VMtDTCDQBRspg5jB8jjY08zg="],["","","y","ZAR","3","49058","7456, 9216, 6458, 5153, 7456",null,"194.40","7456","0:00:31","","1100","","T",null,null],["","","y","ZAR","4","49597","2935, 6554",null,"1.22","2935","0:01:16","","12","","T",null,null],["","","y","ZAR","5","49590","4440, 0518, 5343, 2625, 4848",null,"0.95","4440","0:15:58","","5","","L",null,null],["","","y","ZAR","6","49591","4848, 4440, 4440, 0518, 2625",null,"1.81","4848","0:16:05","","12","","L",null,null],["","","y","ZAR","7","49595","6458",null,"5.55","6458","0:04:13","","55","","T",null,null],["","","y","ZAR","8","49596","",null,"2.90","NONE","0:04:35","","29","","T",null,null],["","","y","ZAR","9","49496","6458, 2427, 2427, 7863, 5845",null,"2.56","6458","0:06:07","","10","","B",null,null],["","","y","ZAR","10","49524","6458, 2427, 7863, 7863, 5845",null,"1.67","6458","0:06:00","","5","","B",null,null],["","","y","ZAR","11","49539","6458, 2427, 7863, 7863, 0764",null,"2.02","6458","0:04:25","","10","","B",null,null]]}'
var jsonObj             = $.parseJSON (myJson);

//--- The JSON should return a 2-D array, named "d".
var arrayOfAuctions     = jsonObj.d;

//--- Loop over each row in the array.
$.each (
    arrayOfAuctions,
    function (rowIndex, singleAuctionData) {

        //--- Print the 7th column.
        console.log ('Row: ' + (parseInt (rowIndex) + 1) + ' Column: 7  Value: ' + singleAuctionData[6]);
alert('test3.41');
auctiontyp=parseInt (singleAuctionData[4]);
   if (auctiontyp== 1)

     {
   aupto=parseInt (singleAuctionData[15]);alert('check2.6');
       alert('check3 '+(singleAuctionData[8]));
      A1_current=parseFloat (singleAuctionData[8]);
      alert('check4 '+(singleAuctionData[16]));
      A1_rest=singleAuctionData[16];
       alert(A1_rest);
       if (A1_rest != 'null')
         {alert('check5');
          A1reset_go=true;
          };
       alert('check5.1');
       alert(A1reset_go);
       if (A1_rest == 'null') and (A1reset_go==true)
         {alert('check6');
          A1reset_go=false;
          alert('check7'); 
          A1_start=singleAuctionData[8];
         };
          alert('check7.3');
         alert((A1_current) );
         alert(( A1_start));
         alert((aupto) );
        if  (((A1_current - A1_start)*100) < (aupto - 10))
          {alert('check8');
           //BidClick1 ();
           };

     };
    }
);

My current problems on this script:

1.The "BidClick1" function runs in the beginning of the script without being called, i only call it close to the end, but then it is not running.. 2.This part:

A1_rest=singleAuctionData[16];
           alert(A1_rest);
           if (A1_rest != 'null')
             {alert('check5');
              A1reset_go=true;
              };
           alert('check5.1');
           alert(A1reset_go);
           if (A1_rest == 'null') and (A1reset_go==true)
             {alert('check6');
              A1reset_go=false;
              alert('check7'); 
              A1_start=singleAuctionData[8];
             };

is not executing correctly., for this array,"arrayOfAuctions", on the first segmant, that im doing all the tests on, "A1_rest" should be = to "null", but it's not, thus it executes:"

if (A1_rest != 'null')
                 {alert('check5');
                  A1reset_go=true;
                  };" 

and also, it doesnt execute this statement : "

 if (A1_rest == 'null') and (A1reset_go==true)
                 {alert('check6');
                  A1reset_go=false;

correctly, it should only execute if A1_rest="null" AND A1_reset_go is true. It executes no matter which one is true,and if i put it as:if ((A1_rest == 'null') and (A1reset_go==true)) ,it doesnt run the script at all.

If any1 got an complete answer, i will mark it as such. Thanks. alert('check7'); A1_start=singleAuctionData[8]; };" executes always

这篇关于需要帮助调试greasemonkey脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆