【发布时间】:2011-05-30 20:30:57
【问题描述】:
我是新手,对 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 () );
到目前为止,基本上,它确实创建了 一个单元格,其中显示了放入数组BidDataArray 中的所有拍卖数据。
我想用每秒更新的数组中的数据来获取某些数据,然后决定是否点击出价按钮。
对于第一次拍卖,我停滞不前。计时器拍卖我让它每隔几秒点击一次。
在第一次拍卖中,我基本上想:
- 检查它是哪个拍卖,
- 看看是不是第一个出价的拍卖,
- 让出价达到金额,
- 进行计算以开始点击拍卖的最后 10 次点击。
- 重置起始金额。
听起来很简单,但是没有调试器并且对 Js 和 GM 知之甚少,这让我很忙。我尝试将我的 Var 放在控制台日志中,但无法跟踪它们。可能错误地声明了它们,或者错误地使用了它们……但我看不到错误,而且我没有调试器来测试它们。
java 调试器可以工作吗?但它没有链接到网站...
另外,当我将我的部分添加到 Brock 的代码中时,它不再显示包含信息的单元格......所以我在某个地方破坏了他的代码,我找不到问题......在我向他添加任何内容之前代码,它工作得很好,然后我添加了我的部分,它不再工作了,所以我用“//”把它拿出来了。所以脚本应该跳过它,但他的部分不再起作用了。我尝试添加“警报”,但似乎找不到问题。我所有的部分都标有“//**”,目前应该处于非活动状态。
任何帮助将不胜感激。谢谢
【问题讨论】:
-
好的,我已经对这个脚本进行了最新的更改,但还是很幸运。有没有办法解决这个 Gm 脚本上的编译错误?看看我哪里出错了?...主要目的是让它运行所有标记为 //** 的部分,这是导致脚本无响应的实际部分。
-
这个问题解决了吗……也许是后来的问题?
-
好的,谢谢。目前只有stackoverflow.com/questions/6297356
标签: javascript jquery debugging greasemonkey