Using Greasemonkey and jQuery to intercept JSON / AJAX data from a page and process

That's right, I partially received the answer in the previous question. But, I'm still having the problem of telling GM where to go and retrieve the data to put it in an array ...

On the web page http://www.trada.net/p_home.aspx , if I run the firebug console, I get data from the above question, but it is constantly changing, updating every second.

This data, I have an idea how to put it in an array, and from there I will tell GM what to do with it. I canโ€™t start the firebug console all the time, and I donโ€™t know how to get GM to receive data requests sent by the site that look like this: http://www.trada.net/REST_Service/REST_Auction.svc/GetAuctionData?_=1306009003654 - where the last part changes with each update.

Basically, Gm will retrieve data every second, see if there is a need to bid on any of the auctions, and then, if there is any win 1, click the pop-up window that appears to continue.

+1
source share
1 answer

Since the landing page uses jQuery, you can easily eavesdrop on JSON data with ajaxSuccess() .

Then there is the problem of getting data from the page area into the GM sandbox. This can be done by placing the data in a special node page.

From there, it's just a matter of using my other (brilliant: D) โ€‹โ€‹answer .

Combining all this, you need to start the following:

Update after almost 4 years: The code below is deprecated due to many changes in Firefox and Greasemonkey. I do not plan to redo it because of a lack of interest, and also because this is not the best approach for most RL tasks. In most cases; The most reliable, portable and reliable method remains the intelligent survey. See an example of a handy utility for this .

 // ==UserScript== // @name _Fun with JSON // @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'); //--- Evesdrop on the page AJAX calls and paste the data into our special div. unsafeWindow.$('body').ajaxSuccess ( function (event, requestData) { J_DataCell.text (requestData.responseText); } ); //--- Listen for changes to the special div and parse the data. J_DataCell.bind ('DOMSubtreeModified', ParseJSON_Data); function ParseJSON_Data () { //--- 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 AuctionDataArray = jsonObj.d; //--- Loop over each row in the array. $.each ( AuctionDataArray, function (rowIndex, singleAuctionData) { //--- Print the 7th column. console.log ('Row: ' + (parseInt (rowIndex) + 1) + ' Column: 7 Value: ' + singleAuctionData[6]); } ); } //--- 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 () ); 


Please note that proposing a question may violate the Terms of Use of the site and / or the site may take countermeasures. (They are already confusing their JS.)

+1
source

All Articles