General :  K-Meleon Forum
General discussion about K-Meleon. 
SOLVED - Using $_Value=injectJS() to return system date.
Posted by: JamesD
Date: January 19, 2012 04:35AM

I am trying to get the system datetime stamp returned into a macro language variable. I have tried many variations of code, but none has worked so far. Something like the following should work, but I am not an expert in Javascript and it is probably missing some key part.
$_Snippet_Value = injectJS( var d = new Date(dateString););
alert( $_Snippet_Value, "datestring", INFO);

I know the MacroLanguage is correct because Siria was able to get a sorting program to work.

Siria's code
$_puzzle=injectJS("var puzzle=navigator.MacroVarPuzzle.substr(127,9999); navigator.MacroVarPuzzle=puzzle; function returnVar(v){return v;} returnVar(puzzle);");

I am sure that that all or part of the returnVar(), etc code is needed, but I have tried many times and I have not gotten it right yet.

Any help will be appreciated.



Edited 1 time(s). Last edit at 01/24/2012 10:04AM by JamesD.

Options: ReplyQuote
Re: Using $_Value=injectJS() to return system date.
Posted by: snuz2
Date: January 23, 2012 04:16PM

In case someone didn't answer this, the injectJS takes a string argument, you need to put it into quotes in other words.

Options: ReplyQuote
Re: Using $_Value=injectJS() to return system date.
Posted by: JamesD
Date: January 24, 2012 01:49AM

Thanks snuz2

I have made a little progress. I have finally gotten something returned in the macro variable. Unfortunately is the the word 'undefined'. I guess that is progress compared to all the empty strings I have had before.

Below are my attempts and results ( most recent on top ).

# "undefined"  $_Snippet_Value = injectJS( "var date = new Date();"); 
# "undefined"  $_Snippet_Value = injectJS( "var date = new Date()"); 
# $_Snippet_Value = injectJS( "function rds {var date = new Date()  return date} ");
# $_Snippet_Value = injectJS( "var date = new Date();  return date; "); 
# $_Snippet_Value = injectJS( "var date = new Date();  return; "); 
# $_Snippet_Value = injectJS( "var date = new Date();  returnVar(date); "); 
# $_Snippet_Value = injectJS( "var date = new Date();  {return date;} ;"); 
# $_Snippet_Value = injectJS( "var date = new Date()  function returnVar(date){return date;} returnVar(date);");
# Siria's code 
# $_puzzle=injectJS("var puzzle=navigator.MacroVarPuzzle.substr(127,9999); navigator.MacroVarPuzzle=puzzle; function returnVar(v){return v;} returnVar(puzzle);");


_Snippet_RunCode {
$_Snippet_Value = injectJS( "var date = new Date()"); 
alert( $_Snippet_Value, "datestring", INFO);
}

I tried putting a {return date} but just got an empty string. Any ideas on what I am doing wrong?

Options: ReplyQuote
Re: SOLVED - Using $_Value=injectJS() to return system date.
Posted by: JamesD
Date: January 24, 2012 10:00AM

It is TOO SIMPLE. The code that works is:
$_Snippet_Value = injectJS( "Date()"); 
alert( $_Snippet_Value, "datestring", INFO);

I finally found that there was no 'var' statement in my JavaScript book.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.