javascriptgreasemonkey

Storing into file using JavaScript/GreaseMonkey


I have captured list of data from the page using Greasemonkey.

GM Script

var hit = GM_getValue("hit") || 0;
var _url = "http://localhost:8080/test?p=$$pageNo$$";
_url = _url.replace("$$pageNo$$", hit);
GM_setValue("hit", ++hit); 
if(hit <= 100) {
window.location.href = _url;
}

This script will runs for nth time and capture <10K data, now i facing the issue in storing the captured data in some file. Anyone has any idea about how we can store the captured data into file/repo?

Thanks - Viswanathan G


Solution

  • Nope, can't write it to a file, but if you're really bored, you can post it to http://pastebin.com (or any other URL that accepts a POST request with a bunch of data).

    GM_xmlhttpRequest({
      method: "POST",
      url: "http://pastebin.com/post.php",
      data: <your data here>,
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      onload: function(response) {
        alert("posted");
      }
    });
    

    Note you need to have a pastebin account to use the API.


    If you really need to write a file to your local filesystem, run a web server on your desktop, and then save the results of an http PUT request to disk.