Saving or writing data with greasemonkey, which can be processed later

I am busy on a site for which I want to write a greasemonkey script that logs all the data or at least certain posts and saves in a file that will be interperatable fo ms excell. Is it possible? for example, I take this piece of data:

{"d":[["","","y","ZAR","1","49517","6458, 8270, 8270, 8270, 7635",null,"1.40","6458","0:13:30","","12","","C","30",null],["y","-00:00","y","ZAR","2","49593","6458, 6458, 6458, 6458, 6458",null,"2.92","6458","0:13:37","","12","","L","12","Ve4mYdrvkkQMKxBH1\/1VMtDTCDQBRspg5jB8jjY08zg="],["","","y","ZAR","3","49058","7456, 9216, 6458, 5153, 7456",null,"194.40","7456","0:00:31","","1100","","T",null,null],["","","y","ZAR","4","49597","2935, 6554",null,"1.22","2935","0:01:16","","12","","T",null,null],["","","y","ZAR","5","49590","4440, 0518, 5343, 2625, 4848",null,"0.95","4440","0:15:58","","5","","L",null,null],["","","y","ZAR","6","49591","4848, 4440, 4440, 0518, 2625",null,"1.81","4848","0:16:05","","12","","L",null,null],["","","y","ZAR","7","49595","6458",null,"5.55","6458","0:04:13","","55","","T",null,null],["","","y","ZAR","8","49596","",null,"2.90","NONE","0:04:35","","29","","T",null,null],["","","y","ZAR","9","49496","6458, 2427, 2427, 7863, 5845",null,"2.56","6458","0:06:07","","10","","B",null,null],["","","y","ZAR","10","49524","6458, 2427, 7863, 7863, 5845",null,"1.67","6458","0:06:00","","5","","B",null,null],["","","y","ZAR","11","49539","6458, 2427, 7863, 7863, 0764",null,"2.02","6458","0:04:25","","10","","B",null,null]]} 

read it into the 2nd array that Brock Adams helped me with.

 var myJson = '{"d":[["","","y","ZAR","1","49517","6458, 8270, 8270, 8270, 7635",null,"1.40","6458","0:13:30","","12","","C","30",null],["y","-00:00","y","ZAR","2","49593","6458, 6458, 6458, 6458, 6458",null,"2.92","6458","0:13:37","","12","","L","12","Ve4mYdrvkkQMKxBH1\/1VMtDTCDQBRspg5jB8jjY08zg="],["","","y","ZAR","3","49058","7456, 9216, 6458, 5153, 7456",null,"194.40","7456","0:00:31","","1100","","T",null,null],["","","y","ZAR","4","49597","2935, 6554",null,"1.22","2935","0:01:16","","12","","T",null,null],["","","y","ZAR","5","49590","4440, 0518, 5343, 2625, 4848",null,"0.95","4440","0:15:58","","5","","L",null,null],["","","y","ZAR","6","49591","4848, 4440, 4440, 0518, 2625",null,"1.81","4848","0:16:05","","12","","L",null,null],["","","y","ZAR","7","49595","6458",null,"5.55","6458","0:04:13","","55","","T",null,null],["","","y","ZAR","8","49596","",null,"2.90","NONE","0:04:35","","29","","T",null,null],["","","y","ZAR","9","49496","6458, 2427, 2427, 7863, 5845",null,"2.56","6458","0:06:07","","10","","B",null,null],["","","y","ZAR","10","49524","6458, 2427, 7863, 7863, 5845",null,"1.67","6458","0:06:00","","5","","B",null,null],["","","y","ZAR","11","49539","6458, 2427, 7863, 7863, 0764",null,"2.02","6458","0:04:25","","10","","B",null,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]); } ); 

Now I want to write this array data to a file, which I can later open and open in excell and iterate over it. Using GM_setValue, can this be done? What would be the easiest way to continue with it?

Thanks.

+2
source share
1 answer

Greasemonkey cannot write a file, and using GM_setValue or local storage is a pain to get into the file. In any case, you do not want to store a lot of values ​​using GM_setValue , since they are stored in the browser settings.

You mentioned a remote server.
Yes, GM can send data to a remote server (or even your local computer if it works as XAMPP). With a bit of extra work, you can also send data to Google documents or similar.

It is unclear what data you want to send (provided that you are not just sending the entire arrayOfAuctions ).

So, let's say you have analyzed the data and determined that you need these columns:

  Column 
 Index meaning / purpose
 ------ --------------------------------
    4 Auction display number
    5 Auction ID
    8 Current Price
    9 High bidder ID
   10 Time Remaining
   12 Up to ???


Then you can isolate the data of interest as follows:

 //--- Start custom, 2-D array. var myAuctionData = [ [ 'DisplayNumber', 'AuctionID', 'CurrentPrice', 'HighbidderID', 'TimeRemaining', 'Upto' ] ]; //--- Loop over each row in the array, storing desired data. $.each ( arrayOfAuctions, function (rowIndex, singleAuctionData) { myAuctionData.push ( [ singleAuctionData[4], singleAuctionData[5], singleAuctionData[8], singleAuctionData[9], singleAuctionData[10], singleAuctionData[12] ] ); } ); 


And send it to your server as follows:

 SerializedAuctionData = JSON.stringify (myAuctionData); GM_xmlhttpRequest ( { method: "POST", url: "http://localhost/YourDir/LogAuctionData.php", data: SerializedAuctionData, headers: {"Content-Type": "application/json"} } ); 


The server can use any technique that is convenient for you.
If it was a PHP page, it could retrieve JSON data as follows:

 $AuctionData = json_decode($HTTP_RAW_POST_DATA); print_r ($AuctionData); 


A server page can write a csv or xls file, but since a lot of data will be posted once per second, it would probably be wiser to use the mySQL database.

+1
source

All Articles