views:

517

answers:

5

I have my greasemonkey script scanning every page i visit for a specific string. I would like to recordkeep the variations of the string in a sqlite db. I'll have another app process this db everyonce in a while. What i dont know is HOW do i store the data into the sqlite db? i was thinking i can launch an executable automatically if the string was found but i dont know how to do that through javascript. Another alternative i thought was have a socket listen on a certain port and have some js magic but i couldnt think of a silent way to send data like that.

A: 

You can have the greasemonkey script call a url with some variables (like the data you want stored). Use ajax requests. You can have a web server setup locally to handle them.

If you on windows, you can use WAMP to quickly throw up a web server. Just make sure you enable php_sqlite extension.

This may help you with some implementation specifics: http://www.pathf.com/blogs/2006/07/bjax_with_greas/

HyperCas
+2  A: 

You may also want to consider using Google Gears extension, which uses an SQLite database under the hood.

Joel Carranza
+2  A: 

I recommend using a webserver to gather the data. You can set up a domain or IP to send the data to. Just for starting out you could even run on localhost if you need to.

The advantage is that, once created, the same architecture can be used from different PCs, so that any computer you run the script from can share the results.

Update: To communicate with your server you will need to use GM_xmlhttpRequest. I know of one library that adds an abstraction layer to make using GM_xmlhttpRequest easier: Speakeasy.js. It is a relatively unknown lightweight ActiveResource like interface for sending and retrieving data from a RESTful webserver. Here's an example of a Greasemonkey script that communicates with a webserver on every page load. It loads annotations and displays them on the page.

Here's an adapted version close to your needs:

// ==UserScript==
// @name           Demo Script
// @namespace      http://example.com
// @description    Sample
// @include        *
//
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js
// @require     http://strd6.googlecode.com/svn/trunk/gm_util/d_money.js
// @require     http://strd6.googlecode.com/svn/trunk/gm_util/speakeasy.js
//
// ==/UserScript==


error = D$.error;
log = D$.log;
D$.debug(false);


Speakeasy
  .generateResource('result')
  .configure({
    baseUrl: 'http://localhost:3000/'
  })
;


// Attach all annotations for this page from remote server
var href = window.location.href;
currentUrl = href.substring(href.indexOf('://') + 3);
log(currentUrl);

var result1 = 'something'; // Insert your function to get your result data
var result2 = 'something else'; // Insert your function to get your result data

Speakeasy.result.create({
  data: {
    url: currentUrl, 
    result1: result1, 
    result2: result2
  }
});

You can quickly create a Rails site or use whatever backend you are familiar with.

Daniel X Moore
how would i send data to my site or localhost while i browse? it should scan every page automatically and send silently
acidzombie24
The "result1" and "result2" variables, in this example, would hold the data you want. If you just want the entire site's HTML, then use document.body.innerHTML. Otherwise, filter the page accordingly. The data will be sent on every page-load, because this script executes on all sites.
Paul Marshall
+1  A: 

I'm not sure how you can use it with Greasemonkey but Firefox has an API called Storage for using an sqlite database. Check it out here: https://developer.mozilla.org/en/Storage

tayfun
+1  A: 

Or you simply use LubeMonkey, its an improved Greasemonkey fork with sqlite support. Every installed script gets his own sqlite db created and you can execute queries updates etc within that db, you can even cache images on the db or any data. Get it here http://www.gamecore.org

GBoz