How to post content with random number

Discussions and Tech Support related to the iMacros Firefox Add-on.

Moderator: iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

How to post content with random number

by worldcom on Sun Feb 01, 2009 12:43 am

something like content=He like it, it was $randomnumber or something like that, anyone anyone anyone??????????????????? how to do?
worldcom
 
Posts: 7
Joined: Sat Jan 31, 2009 9:31 am

Re: How to post content with random number

by matty on Sun Feb 01, 2009 4:17 am

worldcom wrote:something like content=He like it, it was $randomnumber or something like that, anyone anyone anyone??????????????????? how to do?


I'd use Javascript and this function:

Code: Select all
var randomnumber;
randomnumber = Math.floor(Math.random()*3);


Then pass the random number to the macro using:

Code: Select all
       iimSet ("randomnumber", randomnumber)


And in the macro put:

Code: Select all
blah content=He like it, it was {{randomnumber}} or something like that


Matty
matty
 
Posts: 29
Joined: Thu Dec 25, 2008 4:24 pm

Re: How to post content with random number

by worldcom on Sun Feb 01, 2009 2:28 pm

Thanks matty, can this be done with firefox?
worldcom
 
Posts: 7
Joined: Sat Jan 31, 2009 9:31 am

Re: How to post content with random number

by Tech Support on Mon Feb 02, 2009 10:32 am

Thanks matty, can this be done with firefox?

Yes

You can convert this VBS script to Javascript and use it within Firefox: http://wiki.imacros.net/Random-Numbers.vbs

PS: If you do that, I would be great if you post the result here in the forum for others to use :D
User avatar
Tech Support
 
Posts: 4993
Joined: Tue Sep 20, 2005 12:25 pm

Re: How to post content with random number

by matty on Mon Feb 02, 2009 3:27 pm

Tech Support wrote:
Thanks matty, can this be done with firefox?

Yes

You can convert this VBS script to Javascript and use it within Firefox: http://wiki.imacros.net/Random-Numbers.vbs

PS: If you do that, I would be great if you post the result here in the forum for others to use :D


Similar to this, I am sure that someone else would write it in a different way as my coding expertise is somewhat limited, but it works.

A few notes:
* I was inclined to build the macro inside the JavaScript as it runs faster, if it was a much bigger macro, then I'd work out which chunks are being repeated and sub them out to other functions or imacros.iim files using iimSet("Name for the macro", variable); and iim1.iimPlay("wsh-random.iim");

* It runs really slow if you have show JavaScript enabled, turn this off in your iMarco's side bar >> Edit >> Options >> UnCheck ' Show JavaScript during reply', then watch it fly!

* I see no point in closing the other tabs like the vbs example, as you've gone to that tab specifically to run this macro, again if it was a much larger set of code, then I would be closing the other tabs once at the very beginning

* I added a DeBug variable, as I add this to everything I do, mainly because stuff breaks and I need to know visually whats its doing and when.

Code: Select all
var i=1;                          // For cycling
var JSNewLine="\n";           // new Line
var MyMacroCode;         // For running the code
var NumberOfTimes=5;             // Number of times
var DeBug=1;                      // Added for debugging, set to 0 to turn off
var Keyword;                      // To store the Keyword in
var RandomNumber;              // To put a randome number in

for (i = 0; i < NumberOfTimes; i ++ )
{
    if (DeBug != 0)
    {
        alert ("This example script submits random information to a website");
    }
   
    // Make randome number +1
    RandomNumber = 1 + Math.floor(Math.random()*5);   
   
    // Spill the random number
    if (DeBug != 0)
    {
        alert ("The random number is: " + RandomNumber);
    }
   
    // If tree to find the random number
    if (RandomNumber == 1)
    {
        Keyword = "Sunshine";
    }
    if (RandomNumber == 2)
    {
        Keyword = "Snow";
    }
    if (RandomNumber == 3)
    {
        Keyword = "Rain";
    }
    if (RandomNumber == 4)
    {
        Keyword = "Wind";
    }
    if (RandomNumber == 5)
    {
        Keyword = "clouds"
    }
    // Capture a screw up as it must be 1 to 5
    if (RandomNumber < 1 || RandomNumber > 5)
    {
        Keyword = "Oppps - This should not happen"
    }
   
    if (DeBug != 0)
    {
        alert ("The Keyword is: " + Keyword);
    }   

    // Build the macro
    MyMacroCode = "CODE:"
    MyMacroCode = MyMacroCode + "TAB T=1" + JSNewLine
    //MyMacroCode = MyMacroCode + "TAB CLOSEALLOTHERS" + JSNewLine // Disabled as there is no need to do this, but previous example has this
    MyMacroCode = MyMacroCode + "URL GOTO=http://www.iopus.com/imacros/demo/v5/f2/automatic-data-entry.asp" + JSNewLine
    MyMacroCode = MyMacroCode + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:FNAME CONTENT=" + RandomNumber + JSNewLine
    MyMacroCode = MyMacroCode + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:WebDataEntry ATTR=NAME:LNAME CONTENT=" + Keyword + JSNewLine
    MyMacroCode = MyMacroCode + "TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:WebDataEntry ATTR=NAME:SendButton&&VALUE:Click<SP>to<SP>submit<SP>data" + JSNewLine
   
    // Play the Macro
    iimPlay(MyMacroCode)
}


Enjoy,

Matty
matty
 
Posts: 29
Joined: Thu Dec 25, 2008 4:24 pm

Re: How to post content with random number

by matty on Mon Feb 02, 2009 3:36 pm

Tech Support wrote:
Thanks matty, can this be done with firefox?

Yes

You can convert this VBS script to Javascript and use it within Firefox: http://wiki.imacros.net/Random-Numbers.vbs

PS: If you do that, I would be great if you post the result here in the forum for others to use :D


And yes we need more JavaScript examples, it was a nightmare trying to figure it out to begin with due to the severe lack of working examples to work from.

One which has gotta be added, due to the lack of Dialogue extraction support for Firefox, is an example where you export data on the page to work out if the dialogue is going to appear or not (and thus its contents) to deal with it in a different manner

Matty
matty
 
Posts: 29
Joined: Thu Dec 25, 2008 4:24 pm


Return to iMacros for Firefox

Who is online

Users browsing this forum: Alexa [Bot], Bing [Bot] and 6 guests

Website Monitoring