如何解决需要帮助调试lublessmonkey脚本
| 我在这里很新,与GM脚本一样。在Brock和其他成员的帮助下,我正在取得进步。 我目前遇到了调试Greasemonkey脚本的问题,但是由于某些原因,我无法掌握它。我的第一个问题是使用console.log调试firebug。 有时我会找到日志,大多数时候我找不到任何日志,猜想我在错误地使用它。然后尝试使用警报以查看变量值...相同的故事。 目前,我正试图在Brock Adams的大力帮助下,在Trada.net网站上处理一个脚本,以进行一些拍卖,我们已经完成了一半以上的工作,但是我仍然对JS脚本颇有兴趣。如果您接受我15年前就习惯了涡轮帕斯卡,那么安静的新体验。:) 好吧,目前这是我在脚本上得到的结果: // ==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 () );
基本上,到目前为止,它确实创建了一个单元格,在其中显示放入数组“ 1”的所有拍卖数据。
我想使用每秒更新一次的数组中的数据来获取某些数据,然后决定是否单击“出价”按钮。
对于第一次拍卖,我停了下来。计时器拍卖使我能够每隔几秒钟单击一次。
在第一次拍卖中,我基本上想:
检查它是哪个拍卖,
找出这是否是第一次竞价,
获得最高出价,
进行计算以开始单击拍卖的最后10次点击。
重置起始金额。
听起来很简单,但是没有调试器并且对Js和GM的了解很少,这让我很忙。我曾尝试将Var放在控制台日志中,但是无法跟踪它们。可能是错误地声明了它们,或者错误地使用了它们……但是我看不到错误,并且我没有调试器来测试它们。
Java调试器可以工作吗?但它没有链接到该网站...
另外,当我将零件添加到Brock的代码中时,它不再显示带有信息的单元格...所以在我破坏了他的代码的地方,我找不到问题了...在我添加任何内容之前他的代码,效果很好,然后我添加了我的部件,它不再起作用了,所以我使用\“ // \”将其取出。因此脚本应该跳过它,但是他的部分不再起作用。我尝试添加“警报”,但似乎找不到问题。我所有的零件都标有\“ // ** \”,目前应该处于无效状态。
任何帮助将不胜感激。谢谢
解决方法
好吧,我没有从这里得到很多答复,但是我已经尝试过...:((我设法将它调试了90%,但这是我的回答sofer ...在我找到一种方法后将对其进行更新引起小故障..:
// ==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,7635\",null,\"1.40\",\"6458\",\"0:13:30\",\"12\",\"C\",\"30\",null],[\"y\",\"-00:00\",\"2\",\"49593\",6458,6458\",\"2.92\",\"0:13:37\",\"L\",\"Ve4mYdrvkkQMKxBH1\\/1VMtDTCDQBRspg5jB8jjY08zg=\"],[\"\",\"3\",\"49058\",\"7456,9216,5153,7456\",\"194.40\",\"7456\",\"0:00:31\",\"1100\",\"T\",\"4\",\"49597\",\"2935,6554\",\"1.22\",\"2935\",\"0:01:16\",\"5\",\"49590\",\"4440,0518,5343,2625,4848\",\"0.95\",\"4440\",\"0:15:58\",\"6\",\"49591\",\"4848,4440,2625\",\"1.81\",\"4848\",\"0:16:05\",\"7\",\"49595\",\"5.55\",\"0:04:13\",\"55\",\"8\",\"49596\",\"2.90\",\"NONE\",\"0:04:35\",\"29\",\"9\",\"49496\",2427,7863,5845\",\"2.56\",\"0:06:07\",\"10\",\"B\",\"49524\",\"1.67\",\"0:06:00\",\"11\",\"49539\",0764\",\"2.02\",\"0:04:25\",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 ();
};
};
}
);
我目前在此脚本上遇到的问题:
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\') and (A1reset_go==true)
{alert(\'check6\');
A1reset_go=false;
alert(\'check7\');
A1_start=singleAuctionData[8];
};
未正确执行。对于此数组,“ arrayOfAuctions \”,在第一个段上,我对\“ A1_rest \”进行的所有测试应= = \“ null \”,但不是,因此它执行:\“
if (A1_rest != \'null\')
{alert(\'check5\');
A1reset_go=true;
};\"
而且,它不执行以下语句:
\“
if (A1_rest == \'null\') and (A1reset_go==true)
{alert(\'check6\');
A1reset_go=false;
正确地,它仅应在A1_rest = \“ null \”并且A1_reset_go为true时执行。无论哪一个为真,它都会执行,如果我将其表示为:if ((A1_rest == \'null\') and (A1reset_go==true))
,它根本不会运行该脚本。
如果有任何一个完整的答案,我会这样标出来。
谢谢。
警报(\'check7 \');
A1_start = singleAuctionData [8];
}; \“总是执行
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。