Is it possible to stop iMacros through Greasemonkey?

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
kingofaces
Posts: 2
Joined: Sun May 29, 2011 10:16 pm

Is it possible to stop iMacros through Greasemonkey?

Post by kingofaces » Sun Feb 02, 2014 6:36 pm

This seems like it should be simple, but I haven't had much luck with searching here or on Google. Basically, I have a macro running that is searching different webpages, while my Greasemonkey script is searching each page for different content. However, when my Greasemonkey script finds a certain piece of content, I would like to add a line in that script that tells iMacros to either stop the specific macro, or close entirely. I'm aware of the EVAL statement and using MacroError to halt the macro, but given that I'm dealing with some dynamic search variables that took a bit of work to iron out in Javascript, I'd rather leave the url looping to iMacros and let Greasemonkey do the rest of the work. Is this feasible at all? Thanks.
Windows 7
Firefox 26.0
iMarcros 8.6.0
chivracq
Posts: 8201
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Is it possible to stop iMacros through Greasemonkey?

Post by chivracq » Mon Feb 03, 2014 9:01 pm

Why don't you simply just use TAG ... CONTENT=EVENT:FAIL_IF_FOUND?
http://wiki.imacros.net/TAG#Triggering_events

I had some ideas to integrate GreaseMonkey with iMacros (or the other way round...!, didn't really decide...!) but I didn't come far enough to actually implement a Proof of Concept, mainly because I didn't spend enough time to become fluent with GM, you seem to have come further than me... Good!

EVAL and MacroError should do the job otherwise indeed.... maybe based on some HTML Element you could dynamically add to the Page with GM before iMacros has a chance to do any Processing on that Page...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
thecoder2012
Posts: 248
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Is it possible to stop iMacros through Greasemonkey?

Post by thecoder2012 » Tue Apr 10, 2018 7:36 pm

It's my topic since few minutes. :wink:
chivracq wrote:Why don't you simply just use TAG ... CONTENT=EVENT:FAIL_IF_FOUND?
http://wiki.imacros.net/TAG#Triggering_events
Stop-Button is better in a few cases. But the (low-level) way is hard in FF but I hope it's possible in Greasemonkey/Tampoermoney in the future.
But it's impossible in the newest FF version.
Incompleted workaround: Close the Tab :lol:
chivracq wrote:I had some ideas to integrate GreaseMonkey with iMacros (or the other way round...!, didn't really decide...!) but I didn't come far enough to actually implement a Proof of Concept, mainly because I didn't spend enough time to become fluent with GM, you seem to have come further than me... Good!
Which ideas?

Autostart thing with GreaseMonkey is no problem. See use imacros code in tampermonkey, Autostart on page load by URI, autrun and call a iMacros-Script from greasemonkey
chivracq wrote:EVAL and MacroError should do the job otherwise indeed.... maybe based on some HTML Element you could dynamically add to the Page with GM before iMacros has a chance to do any Processing on that Page...
Sure but Stop(-Button) is required in few cases and better for Greasemonkey, Tampermonkey and in iMacros with JS as solution.
Possible as workaround in iMacros with JS "throw exit;" (as big instant error without syntax error) but same to MacroError.

EDIT: Proof of concept in iMacros v8.9.7 with Javascript (*.js):

Code: Select all

var wm = imns.Cc["@mozilla.org/appshell/window-mediator;1"].getService(imns.Ci.nsIWindowMediator);
//line for greasemonkey/tampermoney
//var wm = imns.Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(imns.Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");//window/tab management required with more than 1 tab!

iimPlayCode("URL GOTO=https://www.google.de/");
win.iMacros.jsplayer2.stop();//imacros stop button
iimPlayCode("URL GOTO=https://www.yahoo.de/");
It works in my test with Waterfox 55.2.2 but not in Greasemonkey/Tampermonkey (context/tab wrong, maybe)
Last edited by thecoder2012 on Wed Apr 11, 2018 10:29 pm, edited 1 time in total.
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me!
chivracq
Posts: 8201
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Is it possible to stop iMacros through Greasemonkey?

Post by chivracq » Wed Apr 11, 2018 10:19 pm

thecoder2012 wrote:It's my topic since few minutes. :wink:
Yeah, sure...!, since @OP didn't bother to follow up...! :roll:
You seem to be "in a mood" for "exhuming" old Threads from 4 years ago, ah-ah...! But interesting Thread indeed.. 8)
thecoder2012 wrote:
chivracq wrote:Why don't you simply just use TAG ... CONTENT=EVENT:FAIL_IF_FOUND?
http://wiki.imacros.net/TAG#Triggering_events
Stop-Button is better in a few cases. But the (low-level) way is hard in FF but I hope it's possible in Greasemonkey/Tampoermoney in the future.
But it's impossible in the newest FF version.
Incompleted workaround: Close the Tab :lol:
Hum..., "newest"/"latest" is always vague and won't mean anything again to anybody reading the Thread in 4 years from now, you can better mention the exact Version in/from/until which stg (still) works or not anymore... => I guess you probably mean FF57...

Oh...!, and about 'TAB Close', have a look at the following Thread (hum, from 2014 as well, ah-ah...!) where I had posted a very simple Sol that can even be used for a Conditional Close if needed..., and where I maintain a List of relevant Threads as well, with other Sols...:
- How to close the iMacros Browser?
thecoder2012 wrote:
chivracq wrote:I had some ideas to integrate GreaseMonkey with iMacros (or the other way round...!, didn't really decide...!) but I didn't come far enough to actually implement a Proof of Concept, mainly because I didn't spend enough time to become fluent with GM, you seem to have come further than me... Good!
Which ideas?

Autostart thing with GreaseMonkey is no problem. See use imacros code in tampermonkey, Autostart on page load by URI, autrun and call a iMacros-Script from greasemonkey
Fouff..., I don't really remember what "Ideas" I had then, 4 years ago... I "see" one Game that I play where I could (have) use(d) a Mix of GM and iMacros, but I think I wasn't playing it yet in Feb 2014 and for other Games that I was already playing, I had other perfect Sols in (pure) ('.iim') iMacros, so I guess it was maybe for other Threads on the Forum, where like @OP in this one the User(s) didn't follow up, so I didn't do any further "Digging"...

But hum..., wondering if it's possible to Conditionally launch a Macro from GM, or even Macro_1 or Macro_2..., that could be interesting... :twisted:
Even if, hum-hum..., maybe not best for me though, and not "better" than the Sol I already have, I need pure Speed, and a GM Script running on the Page will probably already slow the Page Loading by a few Milliseconds, and even worse, loading and parsing an (.iim') Macro can sometimes take 1-2 sec before the Macro is actually running, while in "my Sol", my Macro is already running, so I'm already beyond the Parsing Phase... (and several Vars and Computations have already been loaded in Memory)...
thecoder2012 wrote:
chivracq wrote:EVAL and MacroError should do the job otherwise indeed.... maybe based on some HTML Element you could dynamically add to the Page with GM before iMacros has a chance to do any Processing on that Page...
Sure but Stop(-Button) is required in few cases and better for Greasemonkey, Tampermonkey and in iMacros with JS as solution.
Possible as workaround in iMacros with JS "throw exit;" (as big instant error without syntax error) but same to MacroError.

EDIT: Proof of concept in iMacros v8.9.7 with Javascript (*.js):

Code: Select all

var wm = imns.Cc["@mozilla.org/appshell/window-mediator;1"].getService(imns.Ci.nsIWindowMediator);
//line for greasemonkey/tampermoney
//var wm = imns.Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(imns.Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");//window/tab management required with more than 1 tab!

iimPlayCode("URL GOTO=https://www.google.de/");
win.iMacros.jsplayer2.stop();//imacros stop button
iimPlayCode("URL GOTO=https://www.yahoo.de/");
It works in my test but not in Greasemonkey/Tampermonkey (context/tab wrong, maybe)
Same about "newest" a bit earlier, you should mention as well in which FF Version you've tested your Script..., and/or in which Browser(s) actually as you regularly use WaterFox like I use Pale Moon myself...

But hum..., interesting to see that you can access the 'Stop' Button of the iMacros Side-Panel from a Script..., I guess that's what the 'PAUSE' Command is doing with probably some:

Code: Select all

win.iMacros.jsplayer2.pause();
Hum, wondering what a 'play()' will do, ah-ah...!, maybe with some Macro as Argument...

But hum-hum..., @thecoder2012, any way to create some Keyboard Shortcut on the fly to this 'pause()' (+ 'continue()')...? That could be interesting, several Threads about such a Functionality on the Forum actually..., just an Idea...

OK, trying to post now, I started this Reply several hours ago, got some Visit several times in the meantime...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
thecoder2012
Posts: 248
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Is it possible to stop iMacros through Greasemonkey?

Post by thecoder2012 » Thu Apr 12, 2018 3:25 am

thecoder2012 wrote:You seem to be "in a mood" for "exhuming" old Threads from 4 years ago, ah-ah...!
A little yes.
chivracq wrote:Hum..., "newest"/"latest" is always vague and won't mean anything again to anybody reading the Thread in 4 years from now, you can better mention the exact Version in/from/until which stg (still) works or not anymore... => I guess you probably mean FF57...
Yes but I mean more the new addon system "WebExtensions" because no low level api possible. See Comparison with the Add-on SDK ("Add-on SDK => WebExtensions" + "Low-level APIs").
chivracq wrote:Oh...!, and about 'TAB Close', have a look at the following Thread (hum, from 2014 as well, ah-ah...!) ...
Thanks! It's helpful.
chivracq wrote:Same about "newest" a bit earlier, you should mention as well in which FF Version you've tested your Script..., and/or in which Browser(s) actually as you regularly use WaterFox like I use Pale Moon myself...
Cyberfox 52.x ESR and Waterfox 55.x
chivracq wrote:But hum..., interesting to see that you can access the 'Stop' Button of the iMacros Side-Panel from a Script..., [/code]
Yes. I was unsure but it is possible.
chivracq wrote:I guess that's what the 'PAUSE' Command is doing with probably some:

Code: Select all

win.iMacros.jsplayer2.pause();
Hum, wondering what a 'play()' will do, ah-ah...!, maybe with some Macro as Argument...
Yes but I have checked the source code (jdgui => imacros.jar => content => iMacros.js). But few commands are untested.

General (with checks!):

Code: Select all

win.iMacros.pause();
win.iMacros.play("file.js");
win.iMacros.playLoop("file.iim",10);
win.iMacros.playURLMacro("yoururldata?code=base64script");
win.iMacros.stop();
(First "pause()" = pause, second "pause()" = continue/unpause.)

IIM:

Code: Select all

win.iMacros.player.pause();
win.iMacros.player.unpause();
win.iMacros.player.play(imns.FIO.openMacroFile("file.iim"));
win.iMacros.player.play(imns.FIO.openMacroFile("file.iim"),10);
win.iMacros.player.stop();
JS:

Code: Select all

win.iMacros.jsplayer2.pause();
win.iMacros.jsplayer2.unpause();
win.iMacros.jsplayer2.playJSFile("yourjsdata","file.js");
win.iMacros.jsplayer2.stop();
Recorder:

Code: Select all

win.iMacros.recorder.start();
win.iMacros.recorder.pause();
win.iMacros.recorder.unpause();
win.iMacros.recorder.stop();
chivracq wrote:But hum-hum..., @thecoder2012, any way to create some Keyboard Shortcut on the fly to this 'pause()' (+ 'continue()')...? That could be interesting, several Threads about such a Functionality on the Forum actually..., just an Idea...
It's not really possible without a lot of code.
See this addon shortkeys (Run custom JS + imacros script in base64 as url) as solution, maybe.
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me!
Post Reply