【问题标题】:Imacros Javascript Macro Random Variable QuestionImacros Javascript 宏随机变量问题
【发布时间】:2018-11-10 22:47:10
【问题描述】:

我创建了一个在 imacros 上运行的脚本来更新 Firefox 上响应式设计模式的分辨率,但是在脚本选择随机值之后,没有提取正确的数组值。

你能帮我解决吗,我需要添加随机数组的结果。

这是代码

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");

此脚本必须更新提取的值,但不能正确提取值。

【问题讨论】:

    标签: javascript firefox var imacros


    【解决方案1】:

    我希望下面的脚本应该可以工作:

    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);
    

    如果没有稍后在代码中调用的iimPlayCode()(或iimPlay())函数,iimSet() 函数将毫无用处。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多