Search code examples
javascriptfirefoxvarimacros

Imacros Javascript Macro Random Variable Question


I created a script to run on imacros to update the resolution of responsive design mode on firefox but after the script choice random value do not extract the correct value of array.

Can you help me to solve, i need to add the result of random array.

This is the code

myheight = new Array();
myheight.push("1000");
myheight.push("1100");
myheight.push("1200");

randomint = Math.floor(Math.random()*myheight.length);
iimSet("height",myheight[randomint]);

mywidth = new Array();
mywidth.push("800");
mywidth.push("900");
mywidth.push("1000");

randomint = Math.floor(Math.random()*mywidth.length);
iimSet("width",mywidth[randomint]);


var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref("devtools.responsiveUI.customHeight", "height");
prefs.setCharPref("devtools.responsiveUI.customWidth", "width");

Image

This script must update the values extracted but do not extract correctly the values.


Solution

  • I hope the following script should work:

    myheight = new Array();
    myheight.push("1000");
    myheight.push("1100");
    myheight.push("1200");
    
    randomint = Math.floor(Math.random()*myheight.length);
    height = myheight[randomint];
    
    mywidth = new Array();
    mywidth.push("800");
    mywidth.push("900");
    mywidth.push("1000");
    
    randomint = Math.floor(Math.random()*mywidth.length);
    width = mywidth[randomint];
    
    var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
    prefs.setCharPref("devtools.responsiveUI.customHeight", height);
    prefs.setCharPref("devtools.responsiveUI.customWidth", width);
    

    The iimSet() function is useless without the iimPlayCode() (or iimPlay()) functions called later in the code.