Is this possible? Store data...

Subscribe to Is this possible? Store data... 4 posts, 2 voices

 
RufusD User

So I go to a webpage where I input some data, submit it, and then it gives me a new page with a code in the middle. I can copy and paste the code to save it, but it gets kind of tedious after 50 times or so... I'm looking for a faster way.

From what I've read, you can't access local files on the computer for security reasons, so I can't have it grab the data (which I can get easily from an ID tag,) and store in a text file or anything.

BUT - would it be possible to have a script copy the data, change tabs, append it to a google docs file, for example, and tab back?

Fundamentally, is there any way to have a script automatically grab a code from a webpage and store it in a format I can use in the future?

Thanks! Hopefully someone more knowledgeable than me can answer this!

(and if greasemonkey couldn't do it, anyone know of a program that could?)

 
Michael Devore Scriptwright

You can use the Greasemonkey API functions GM_setValue and GM_getValue to set and get data across pages, or even browser sessions. The data is placed in the browser's local storage, which is almost as good as an external text file as long as you don't go nuts with the size of the data you're saving, and you clear it out or reuse it.

Add to and check against validation data (e.g. timestamp or other unique code) along with, and you can make the data retrieval reasonably bulletproof against unplanned browsers terminations, simultaneous multiple sessions, etc.

 
RufusD User

How do I retrieve it from the browser's local storage once I get it there with GM_setValue ?

If, for example, I want to store 20 codes (each about 25 characters long,) for later use, how would I use these functions?

Thanks!

 
Michael Devore Scriptwright

Following test script demonstrates dynamic reading, updating and saving three values via GM_setValue and GM_getValue, with storage spanning browser sessions. The basic idea can be expanded to any number of values: integer, string, or boolean. To try it out, install and load a userscripts site page. Uninstall after it gets sufficiently obnoxious (about two page loads should do it).

// test.user.js
// ==UserScript==
// @include http://userscripts.org/*
// ==/UserScript==
var pigNames = [ "George", "Pinko", "Flopsy" ];
var sleepPigSleep = 5;
function nonsense()
{
var pigCounter = new Array();
for (var i = 0; i < pigNames.length; i++)
{
pigCounter[i] = GM_getValue("PigCounter" + pigNames[i], "-1");
pigCounter[i] += 0;
if (pigCounter[i] <= 0 || pigCounter[i] >= sleepPigSleep)
{
pigCounter[i] = 0;
GM_setValue("PigCounter" + pigNames[i], 0);
alert("Little piggy " + pigNames[i] + " is asleep. It will wake up next time you load a page here.");
}
if (pigCounter[i])
{
alert("Little piggy " + pigNames[i] + " oinks! (and has " + pigCounter[i] + " time" + (pigCounter[i] > 1 ? "s)" : ")"));
}
GM_setValue("PigCounter" + pigNames[i], ++pigCounter[i]);
}
}
window.addEventListener( "load", nonsense, false );