由于目标页面使用jQuery,因此您可以使用轻松监听JSON数据
ajaxSuccess()。
然后问题就变成了将数据从页面的作用域中移到GM沙箱中……这可以通过将数据放入特殊的页面节点中来完成。
综上所述,以下内容将帮助您入门:
将近4年后更新:
由于Firefox和Greasemonkey的许多更改,下面的代码现在已过时。由于缺乏兴趣,而且由于它不是大多数RL任务的最佳方法,因此我不打算对其进行重新设计。在大多数情况下;最强大,最便携式和最可靠的方法仍然是智能轮询。
// ==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's 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 () );请注意,问题的建议可能会违反网站的 _服务条款_和/或网站可能会采取对策。(他们已经混淆了他们的JS。)



