我在這裏挺新的,就像新的GM腳本一樣。在Brock等人的幫助下,我正在取得進展。需要幫助調試greasemonkey腳本
我目前有調試Greasemonkey腳本的問題,但由於某種原因,我沒有得到它的竅門。我的第一個問題,使用console.log調試螢火蟲。
有時我會發現日誌,大多數時候我找不到任何東西,我猜錯了。然後嘗試使用警報以查看變量值...相同的故事。
我目前正試圖在布魯克亞當斯的大力幫助下,在網站Trada.net上處理一些拍賣的劇本,我們在這裏獲得了超過一半的資金,但我仍然對JS腳本感到頭痛。 。安靜了全新的體驗,如果u需要我來15 +年前的Turbo Pascal :)
那麼,目前這是我坐在一起的腳本:
// ==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腳本的錯誤?錯誤?......主要目標是讓所有零件都以標記爲// **的方式運行,即啓動腳本無響應的實際零件。 – Ludwig 2011-06-02 18:31:08
這是否得到解決......通過後面的問題,或許? – 2011-06-10 04:15:59
是的謝謝。目前只有http://stackoverflow.com/questions/6297356 – Ludwig 2011-06-10 08:59:40