3

I want to know how can I include jQuery library into javascript and use it in iMacros?

It goes like this. Into .js file I declare iMacros code as a variable

var someMacro;
someMacro ="CODE:";
someMacro +="TAB T=1 \n";

The code is actually larger and this is just small example. After I declared the variable I use commands like iimPlay, iimSet etc. to play the macro and set the variables inside the macro.

Now how can I include jQuery library into this so that I can use jQuery inside .js file and enhance my scripts ?

P.S. I found this on their forum but it didn't help me much since I didn't understand how to use it. Here is the link Link to iopus forum about jQuery

Francis Kim
  • 4,235
  • 4
  • 36
  • 51
edinvnode
  • 3,497
  • 7
  • 30
  • 53

2 Answers2

7

I've come with this this solution:

function loadScriptFromURL(url) {
    var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
        async = false;
    request.open('GET', url, async);
    request.send();
    if (request.status !== 200) {
        var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
        iimDisplay(message);
        return false;
    }
    eval(request.response);
    return true;
}

// load JQuery
loadScriptFromURL('http://mysupersecret.blob.core.windows.net/share/jquery-2.0.3.min.js');
$ = window.$,
JQuery = window.JQuery;

Trying to get jQuery from it's official CDN, I faced with the "setTimeout is undefined" error in iMacros. So I downloaded jQuery and modified setTimeout method to be window.setTimeout. This worked for me and so I had to place jQuery in my online shared location to use it from there. Hope this helps.

cyxou
  • 166
  • 2
  • 11
  • This will help a lot. Can you share an example of jQuery code used in iMacros with this? – edinvnode Nov 22 '13 at 16:25
  • 1
    Just search your JQuery file for a "setTimeout" string and prepend it with "window." You can get mine from here: http://spprofessionals.blob.core.windows.net/share/jquery-2.0.3.min.js – cyxou Nov 22 '13 at 19:04
  • IDK what iMacros is, but couldn't you just do something like `var setTimeout = window.setTimeout` in the global scope and then load jQuery from the CDN? – Dagg Nabbit Nov 22 '13 at 19:50
  • @dagg-nabbit, I've tried that as well — did not work for me)) – cyxou Nov 24 '13 at 12:46
  • @cyxou - can you share your js file again? I tried to change it by myself, but still get the same error. Can you please share it again? Thank you. – whitesiroi Apr 16 '15 at 13:42
  • @cyxou Thank you mate :) still getting this stuff - ReferenceError: setTimeout is not defined, line 1 (Error code: -991) :) maybe, cuz of newer version of iMacros or Firefox. – whitesiroi Apr 16 '15 at 14:49
  • @whitesiroi try this one https://cloud.mail.ru/public/4pXZXZ9UBTxx/jquery.js I've changed all occurrences of setTimeout to window.setTimeout – cyxou Apr 16 '15 at 15:01
  • @cyxou thank you mate :) getting the same stuff :) I tried it before, changed every setTimeout, delete some of them, delete all of them, ... -> ReferenceError: setTimeout is not defined, line 1 (Error code: -991) :) – whitesiroi Apr 16 '15 at 15:31
  • @whitesiroi hm pretty strange.... actually I now use the [qwery](https://github.com/ded/qwery) library for basic dom operations. It's a light alternative to jQuery. Could you please try it by downloading from here https://cloud.mail.ru/public/244mXJRs7tbQ/qwery.js This one is my production minified version – cyxou Apr 16 '15 at 15:52
  • @cyxou thank you, thank you :) it does work :) If you find out how to use jquery :) - plz, lemme know :) – whitesiroi Apr 16 '15 at 23:59
  • @ cyxou I tried to use this with firefox version 54.0.1 and iMacros Version 8.9.7, but getting an error `Error: unsafe CPOW usage forbidden, line 2 (Error code: -991)` – Hardeep Singh Jul 17 '17 at 13:52
  • @HardeepSingh, a lot has changed in latest versions of Firefox in terms of extensions. Use Pale Moon browser instead of Firefox, or use older version of Firefox, i.e. v42. – cyxou Jul 21 '17 at 10:31
1

Thanks for putting this solution together. I loaded jQuery successfully, then created a bootstrap modal and appended it to the body. Next I attempted to load bootstrap.js and call the modal('show') method on the modal but to no avail. iMacros tells me that the function .modal doesn't exist.

loadScriptFromURL('http://localhost.com:7001/ybswcsstub/resources/plugins/jquery-1.10.2.min.js');

$ = window.$, JQuery = window.JQuery;

$.getScript('http://localhost.com:7001/ybswcsstub/resources/plugins/bootstrap/js/bootstrap.js');

$('body').append('<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
'  <div class="modal-dialog">'+
'    <div class="modal-content">'+
'      <div class="modal-header">'+
'        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>'+
'        <h4 class="modal-title" id="myModalLabel">Modal title</h4>'+
'      </div>'+
'      <div class="modal-body">'+
'        Some Modal'+
'      </div>'+
'      <div class="modal-footer">'+
'        <button type="button" class="btn btn-default"     data-dismiss="modal">Close</button>'+
'        <button type="button" class="btn btn-primary">Save changes</button>'+
'      </div>'+
'    </div>'+
'  </div>'+
'</div>');

$('#myModal').modal('show');

When I run I get the following error in iMacros TypeError: $(...).modal is not a function, line 211 (Error code: -991)

Any help would be greatly appreciated as I'm kind of stuck at this point :s

Edit:I had to use $.getScript to load the bootstrap.js (the .com in the domain is because of stackoverflowrestriction) as when I tried to use the loadScriptFromURL, I was getting the error

Error: Bootstrap's JavaScript requires jQuery, line 7 (Error code: -991)

Thanks, Mark.

Mark Gargan
  • 831
  • 1
  • 9
  • 21
  • Faced with the same problem! I've managed to trigger a bootstrap modal by clicking on the corresponding button. Just create a button like this one: `var btn = ""; $(btn).appendTo("body");` Of course you'll want to make this button invisible by applying display hidden to it. Once it appended to the body click on it with `$("#myButton").trigger("click");`. Hope this helps – cyxou Dec 10 '14 at 10:53