views:

42

answers:

1

I've started writing a greasemonkey script, and am facing problems performing localstorage in the Greasemonkey script. The only way I could figure out localstorage in GM is by creating another instance of Javascript in the newElement.innerHTML DOM property, but there the rest of my variables are inaccessible.

Any ideas ? Here's the Greasemonkey code fragment I'm working on.

        var testHref = anchorTag[i].href;
    var testHTML = anchorTag[i].innerHTML;
    var patHref = /item\?id=[0-9]*/g;
    var patCaptureId = /item\?id=([0-9]*)/g;
    var testId = patCaptureId.exec(testHref);
    var patHTML = /[0-9]* comment(|s)/g;
    var patHTML2 = /discuss/g;
    if(patHref.test(testHref) && !patHTML.test(testHTML) && !patHTML2.test(testHTML))
    {
        newElement = document.createElement('span');
        newElement.style.color = "#FF0000";
        newElement.innerHTML = "<a href=\"javascript:localStorage.setItem( 'one', 'rishabhVerma' ); var test = localStorage.getItem( 'one' ); console.log( test );\"> B</a>";
        anchorTag[i].parentNode.insertBefore(newElement, anchorTag[i].nextSibling); 
    }
    i++;
+1  A: 

hmm, unsafeWindow.localStorage doesn't work I guess? I know it's not a problem for chrome to get the localStorage, never tried it on firefox to be honest.

Johan