Calling a Javascript Bookmarklet from an IIM Script

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
AgileHumor
Posts: 5
Joined: Wed Jul 01, 2020 3:35 am

Calling a Javascript Bookmarklet from an IIM Script

Post by AgileHumor » Wed Jul 01, 2020 4:03 am

Goal:
While running IIM script, need to call a JavaScript bookmarklet to edit the current page. I read the samples and it keeps failing at "URL GOTO=javascript://run/?m=bookmarklet.js" on IIM script.

I normally run it manually on the page using bookmark/favorite with the JS code below and it works fine. Cannot figure out how to call the Bookmarklet in the IIM file.

Config:
iMacros Personal Edition 10.0.2.1450 w/File Access Module, Firefox 78.0, Windows 10

IIM Code saved in 'Macros' directory:

Code: Select all

URL GOTO=https://www.vons.com/
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=CLASS:"button__item menu-nav__red-caret-down hidden-xs hidden-sm"
TAG POS=1 TYPE=A ATTR=TXT:"Sign In"
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=my@email.com
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:inputPassword CONTENT=password
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=ID:btnSignIn
WAIT SECONDS=5
URL GOTO=javascript://run/?m=bookmarklet.js
WAIT SECONDS=20
REFRESH
TAG POS=1 TYPE=SPAN ATTR=TXT:Account
TAG POS=1 TYPE=A ATTR=TXT:Sign<SP>Out
JS Bookmarkelet Code saved as bookmarklet.js in 'Macros' directory/b]

Code: Select all

javascript:(function(){"use strict";var promises=[];var allcoupons=Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]);var coupons=allcoupons.filter(function(x){return x.status==="U"}).filter(function(y){return y.deleted!==0});if(coupons.length>0){coupons.forEach(function(item){var data={"items":[]},clip={},list={};clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm;data.items.push(clip);data.items.push(list);var request=new Request(window.AB.couponClipPath+"?storeId\x3d"+window.AB.userInfo.j4u.storeId,{method:'POST',mode:'cors',redirect:'error',headers:new Headers(window.AB.j4uHttpOptions),body:JSON.stringify(data)});var promise=fetch(request).then(function(response){return response.json()}).then(function(itemjson){if(itemjson.items[0]["status"]===1){var wtf=JSON.parse(localStorage.getItem("abJ4uCoupons"));if(wtf.objCoupons[item.offerId]&&wtf.objCoupons[item.offerId]["offerId"]===item.offerId){wtf.objCoupons[item.offerId].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}else{var index=wtf.objCoupons.findIndex(function(obj){return obj.offerId===item.offerId});if(index!==-1){wtf.objCoupons[index].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}}}});promises.push(promise)});Promise.all(promises).then(function(){if(Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return x.status==="U"}).filter(function(y){return y.deleted!==0}).length>0){window.alert("there are still some unclipped coupons - something probably broke this script")}else{}localStorage.removeItem("abCoupons");localStorage.removeItem("abJ4uCoupons");location.reload()})}else{if(allcoupons.length>0){window.alert("no clippable coupons")}else{window.alert("no coupons detected")}}})();
Last edited by AgileHumor on Wed Jul 01, 2020 6:15 pm, edited 2 times in total.
chivracq
Posts: 9374
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Calling a Javascript Bookmarklet from an IIM Script

Post by chivracq » Wed Jul 01, 2020 2:01 pm

AgileHumor wrote:
Wed Jul 01, 2020 4:03 am
Goal:
While running IIM script, need to call a JavaScript bookmarklet to edit the current page. I read the samples and it keeps failing at "URL GOTO=javascript://run/?m=bookmarklet.js" on IIM script.

I normally run it manually on the page using bookmark/favorite with the JS code below and it works fine. Cannot figure out how to call the Bookmarklet in the IIM file.

Config:

Code: Select all

iMacros Personal Edition 10.0.2.1450 w/File Access Module, Firefox 78.0, Windows 10
IIM Code saved in 'Macros' directory:

Code: Select all

URL GOTO=https://www.vons.com/
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=CLASS:"button__item menu-nav__red-caret-down hidden-xs hidden-sm"
TAG POS=1 TYPE=A ATTR=TXT:"Sign In"
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:inputPassword CONTENT=password
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=ID:btnSignIn
WAIT SECONDS=5
URL GOTO=javascript://run/?m=bookmarklet.js
WAIT SECONDS=20
REFRESH
TAG POS=1 TYPE=SPAN ATTR=TXT:Account
TAG POS=1 TYPE=A ATTR=TXT:Sign<SP>Out
JS Bookmarkelet Code saved as bookmarklet.js in 'Macros' directory/b]

Code: Select all

javascript:(function () {"use strict"; var promises = []; var allcoupons = Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]); var coupons = allcoupons.filter(function(x){return x.status==="U";}).filter(function(y){return y.deleted!==0;}); if (coupons.length > 0) { window.alert("clipping " + coupons.length + " of " + allcoupons.length + " coupons"); coupons.forEach(function(item){ var data = {"items":[]}, clip = {}, list = {}; clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm; list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm; data.items.push(clip);data.items.push(list); var request = new Request(window.AB.couponClipPath + "?storeId\x3d" + window.AB.userInfo.j4u.storeId, { method: 'POST', mode: 'cors', redirect: 'error', headers: new Headers(window.AB.j4uHttpOptions), body: JSON.stringify(data) }); var promise = fetch(request).then(function(response) { return response.json(); }) .then(function(itemjson) { if (itemjson.items[0]["status"] === 1) { var wtf = JSON.parse(localStorage.getItem("abJ4uCoupons")); if (wtf.objCoupons[item.offerId] && wtf.objCoupons[item.offerId]["offerId"] === item.offerId) { wtf.objCoupons[item.offerId].status = "C"; localStorage.setItem("abJ4uCoupons", JSON.stringify(wtf)); } else { var index = wtf.objCoupons.findIndex(function(obj){return obj.offerId === item.offerId}); if (index !== -1) { wtf.objCoupons[index].status = "C"; localStorage.setItem("abJ4uCoupons", JSON.stringify(wtf)); } } } }); promises.push(promise); }); Promise.all(promises).then(function(){ if (Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return x.status==="U";}).filter(function(y){return y.deleted!==0;}).length > 0) { window.alert("there are still some unclipped coupons - something probably broke this script"); } else { window.alert("all coupons clipped - reloading page"); } localStorage.removeItem("abCoupons"); localStorage.removeItem("abJ4uCoupons"); location.reload(); }); } else { if (allcoupons.length > 0) { window.alert("no clippable coupons"); } else { window.alert("no coupons detected"); } } })();

Hum, mini-Compliment for the Quality of your OP... :D

I don't know the Syntax that you are using:

Code: Select all

URL GOTO=javascript://run/?m=bookmarklet.js
But the "run/?m=" Syntax is iMacros specific, I would think, and would only work using the "imacros://" Protocol and not the "javascript://" Protocol like you are trying to do, => this one should work then, I would think...:

Code: Select all

URL GOTO=imacros://run/?m=bookmarklet.js
And this Syntax works, I use it myself... Even if I use it only with '.iim' Scripts, I don't use '.js' Scripts.

BUT...!, I think the "URL GOTO=imacros://run/?m=" Syntax is actually not supported (anymore) in v10.0.2 for FF that you are using, mentioned in the Release Notes, and it you still try to run it, I think I remember you then get some Error saying that the "imacros:\\" Protocol is not supported/defined and/or that FF needs some "extra" Software or Plugin or whatever... :shock:
=> You would need to use iMacros for FF v8.9.7 for this Syntax to work, and this Legacy Version works until FF56, recommended FF v55.0.3 (that I use myself), or Pale Moon (v28) or Basilisk (v2019/v2020).

Stg else to realize is that when calling another Macro using this Syntax, that iMacros then switches "completely" to that New Script ('.iim' or '.js'), and "completely" forgets about the calling Macro, and that therefore all Commands after the 'URL GOTO' will be ignored, iMacros will not "come back" to the first Script...

What would/could also work I think, (well, in v8.9.7 for sure, but I think v10.0.2 also supports it), is if you "hard-code" the Content of your whole "bookmarklet.js" in the 'URL GOTO=javascript:' Command, starting with/like...:

Code: Select all

URL GOTO=javascript:(function () {"use strict"; var promises = []; var allcoupons = [etc...]
... But you need to remove as many Spaces as possible and replace them all otherwise with "<SP>"...

And I will "soft-alert" @TechSup if they want to have a Look at your Thread, to maybe confirm if what I'm saying is "correct", and maybe come up some some other/better Solution/Explanation... 8)

EDIT:
Oh yep indeed, "... and replace them all otherwise with "<BR>"..." => I meant "replace with "<SP>"...", of course... [Edited]
Last edited by chivracq on Wed Jul 01, 2020 9:28 pm, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
AgileHumor
Posts: 5
Joined: Wed Jul 01, 2020 3:35 am

Re: Calling a Javascript Bookmarklet from an IIM Script

Post by AgileHumor » Wed Jul 01, 2020 5:52 pm

Thank you for the response and compliment :)

1. I'll try getting a supported config that was "known working" with FF 56 and iMacros for FF v8.9.7 and retest.

2. Regarding the Javascript with current config:
I tried minifying it @ http://dean.edwards.name/packer/ and tested successfully running it manually as a favorite/bookmarklet:

Code: Select all

javascript:(function(){"use strict";var promises=[];var allcoupons=Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]);var coupons=allcoupons.filter(function(x){return x.status==="U"}).filter(function(y){return y.deleted!==0});if(coupons.length>0){coupons.forEach(function(item){var data={"items":[]},clip={},list={};clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm;data.items.push(clip);data.items.push(list);var request=new Request(window.AB.couponClipPath+"?storeId\x3d"+window.AB.userInfo.j4u.storeId,{method:'POST',mode:'cors',redirect:'error',headers:new Headers(window.AB.j4uHttpOptions),body:JSON.stringify(data)});var promise=fetch(request).then(function(response){return response.json()}).then(function(itemjson){if(itemjson.items[0]["status"]===1){var wtf=JSON.parse(localStorage.getItem("abJ4uCoupons"));if(wtf.objCoupons[item.offerId]&&wtf.objCoupons[item.offerId]["offerId"]===item.offerId){wtf.objCoupons[item.offerId].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}else{var index=wtf.objCoupons.findIndex(function(obj){return obj.offerId===item.offerId});if(index!==-1){wtf.objCoupons[index].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}}}});promises.push(promise)});Promise.all(promises).then(function(){if(Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return x.status==="U"}).filter(function(y){return y.deleted!==0}).length>0){window.alert("there are still some unclipped coupons - something probably broke this script")}else{}localStorage.removeItem("abCoupons");localStorage.removeItem("abJ4uCoupons");location.reload()})}else{if(allcoupons.length>0){window.alert("no clippable coupons")}else{window.alert("no coupons detected")}}})();
Then I searched and replaced all spaces with <SP> in notepad:

Code: Select all

javascript:(function(){"use<SP>strict";var<SP>promises=[];var<SP>allcoupons=Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]);var<SP>coupons=allcoupons.filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0});if(coupons.length>0){coupons.forEach(function(item){var<SP>data={"items":[]},clip={},list={};clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm;data.items.push(clip);data.items.push(list);var<SP>request=new<SP>Request(window.AB.couponClipPath+"?storeId\x3d"+window.AB.userInfo.j4u.storeId,{method:'POST',mode:'cors',redirect:'error',headers:new<SP>Headers(window.AB.j4uHttpOptions),body:JSON.stringify(data)});var<SP>promise=fetch(request).then(function(response){return<SP>response.json()}).then(function(itemjson){if(itemjson.items[0]["status"]===1){var<SP>wtf=JSON.parse(localStorage.getItem("abJ4uCoupons"));if(wtf.objCoupons[item.offerId]&&wtf.objCoupons[item.offerId]["offerId"]===item.offerId){wtf.objCoupons[item.offerId].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}else{var<SP>index=wtf.objCoupons.findIndex(function(obj){return<SP>obj.offerId===item.offerId});if(index!==-1){wtf.objCoupons[index].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}}}});promises.push(promise)});Promise.all(promises).then(function(){if(Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0}).length>0){window.alert("there<SP>are<SP>still<SP>some<SP>unclipped<SP>coupons<SP>-<SP>something<SP>probably<SP>broke<SP>this<SP>script")}else{}localStorage.removeItem("abCoupons");localStorage.removeItem("abJ4uCoupons");location.reload()})}else{if(allcoupons.length>0){window.alert("no<SP>clippable<SP>coupons")}else{window.alert("no<SP>coupons<SP>detected")}}})();

However, the current IIM code is not working with config:
iMacros Personal Edition 10.0.2.1450 w/File Access Module, Firefox 78.0, Windows 10

Code: Select all

URL GOTO=https://www.vons.com/
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=CLASS:"button__item menu-nav__red-caret-down hidden-xs hidden-sm"
TAG POS=1 TYPE=A ATTR=TXT:"Sign In"
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=my@email.com
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:inputPassword CONTENT=password
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=ID:btnSignIn
WAIT SECONDS=5

URL GOTO=javascript:(function(){"use<SP>strict";var<SP>promises=[];var<SP>allcoupons=Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]);var<SP>coupons=allcoupons.filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0});if(coupons.length>0){window.alert("clipping<SP>"+coupons.length+"<SP>of<SP>"+allcoupons.length+"<SP>coupons");coupons.forEach(function(item){var<SP>data={"items":[]},clip={},list={};clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm;data.items.push(clip);data.items.push(list);var<SP>request=new<SP>Request(window.AB.couponClipPath+"?storeId\x3d"+window.AB.userInfo.j4u.storeId,{method:'POST',mode:'cors',redirect:'error',headers:new<SP>Headers(window.AB.j4uHttpOptions),body:JSON.stringify(data)});var<SP>promise=fetch(request).then(function(response){return<SP>response.json()}).then(function(itemjson){if(itemjson.items[0]["status"]===1){var<SP>wtf=JSON.parse(localStorage.getItem("abJ4uCoupons"));if(wtf.objCoupons[item.offerId]&&wtf.objCoupons[item.offerId]["offerId"]===item.offerId){wtf.objCoupons[item.offerId].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}else{var<SP>index=wtf.objCoupons.findIndex(function(obj){return<SP>obj.offerId===item.offerId});if(index!==-1){wtf.objCoupons[index].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}}}});promises.push(promise)});Promise.all(promises).then(function(){if(Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0}).length>0){window.alert("there<SP>are<SP>still<SP>some<SP>unclipped<SP>coupons<SP>-<SP>something<SP>probably<SP>broke<SP>this<SP>script")}else{window.alert("all<SP>coupons<SP>clipped<SP>-<SP>reloading<SP>page")}localStorage.removeItem("abCoupons");localStorage.removeItem("abJ4uCoupons");location.reload()})}else{if(allcoupons.length>0){window.alert("no<SP>clippable<SP>coupons")}else{window.alert("no<SP>coupons<SP>detected")}}})();

WAIT SECONDS=10
REFRESH
TAG POS=1 TYPE=SPAN ATTR=TXT:Account
TAG POS=1 TYPE=A ATTR=TXT:Sign<SP>Out
It just never goes beyond this step in iMacros (no error), sits indefinitely (blue highlighted on this step).

Note - I also tried prefixing with "var<sp>document=window.document;..." as indicated here: https://stackoverflow.com/questions/312 ... in-imacros
Note 2 - I used the "URL GOTO=javascript:YOURFUNCTIONNAMEHERE()" based on not understanding viewtopic.php?t=3645
chivracq
Posts: 9374
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Calling a Javascript Bookmarklet from an IIM Script

Post by chivracq » Thu Jul 02, 2020 5:21 am

AgileHumor wrote:
Wed Jul 01, 2020 5:52 pm
Thank you for the response and compliment :)

1. I'll try getting a supported config that was "known working" with FF 56 and iMacros for FF v8.9.7 and retest.

2. Regarding the Javascript with current config:
I tried minifying it @ http://dean.edwards.name/packer/ and tested successfully running it manually as a favorite/bookmarklet:

Code: Select all

javascript:(function(){"use strict";var promises=[];var allcoupons=Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]);var coupons=allcoupons.filter(function(x){return x.status==="U"}).filter(function(y){return y.deleted!==0});if(coupons.length>0){coupons.forEach(function(item){var data={"items":[]},clip={},list={};clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm;data.items.push(clip);data.items.push(list);var request=new Request(window.AB.couponClipPath+"?storeId\x3d"+window.AB.userInfo.j4u.storeId,{method:'POST',mode:'cors',redirect:'error',headers:new Headers(window.AB.j4uHttpOptions),body:JSON.stringify(data)});var promise=fetch(request).then(function(response){return response.json()}).then(function(itemjson){if(itemjson.items[0]["status"]===1){var wtf=JSON.parse(localStorage.getItem("abJ4uCoupons"));if(wtf.objCoupons[item.offerId]&&wtf.objCoupons[item.offerId]["offerId"]===item.offerId){wtf.objCoupons[item.offerId].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}else{var index=wtf.objCoupons.findIndex(function(obj){return obj.offerId===item.offerId});if(index!==-1){wtf.objCoupons[index].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}}}});promises.push(promise)});Promise.all(promises).then(function(){if(Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return x.status==="U"}).filter(function(y){return y.deleted!==0}).length>0){window.alert("there are still some unclipped coupons - something probably broke this script")}else{}localStorage.removeItem("abCoupons");localStorage.removeItem("abJ4uCoupons");location.reload()})}else{if(allcoupons.length>0){window.alert("no clippable coupons")}else{window.alert("no coupons detected")}}})();
Then I searched and replaced all spaces with <SP> in notepad:

Code: Select all

javascript:(function(){"use<SP>strict";var<SP>promises=[];var<SP>allcoupons=Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]);var<SP>coupons=allcoupons.filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0});if(coupons.length>0){coupons.forEach(function(item){var<SP>data={"items":[]},clip={},list={};clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm;data.items.push(clip);data.items.push(list);var<SP>request=new<SP>Request(window.AB.couponClipPath+"?storeId\x3d"+window.AB.userInfo.j4u.storeId,{method:'POST',mode:'cors',redirect:'error',headers:new<SP>Headers(window.AB.j4uHttpOptions),body:JSON.stringify(data)});var<SP>promise=fetch(request).then(function(response){return<SP>response.json()}).then(function(itemjson){if(itemjson.items[0]["status"]===1){var<SP>wtf=JSON.parse(localStorage.getItem("abJ4uCoupons"));if(wtf.objCoupons[item.offerId]&&wtf.objCoupons[item.offerId]["offerId"]===item.offerId){wtf.objCoupons[item.offerId].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}else{var<SP>index=wtf.objCoupons.findIndex(function(obj){return<SP>obj.offerId===item.offerId});if(index!==-1){wtf.objCoupons[index].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}}}});promises.push(promise)});Promise.all(promises).then(function(){if(Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0}).length>0){window.alert("there<SP>are<SP>still<SP>some<SP>unclipped<SP>coupons<SP>-<SP>something<SP>probably<SP>broke<SP>this<SP>script")}else{}localStorage.removeItem("abCoupons");localStorage.removeItem("abJ4uCoupons");location.reload()})}else{if(allcoupons.length>0){window.alert("no<SP>clippable<SP>coupons")}else{window.alert("no<SP>coupons<SP>detected")}}})();

However, the current IIM code is not working with config:
iMacros Personal Edition 10.0.2.1450 w/File Access Module, Firefox 78.0, Windows 10

Code: Select all

URL GOTO=https://www.vons.com/
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=CLASS:"button__item menu-nav__red-caret-down hidden-xs hidden-sm"
TAG POS=1 TYPE=A ATTR=TXT:"Sign In"
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=my@email.com
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:inputPassword CONTENT=password
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=ID:btnSignIn
WAIT SECONDS=5

URL GOTO=javascript:(function(){"use<SP>strict";var<SP>promises=[];var<SP>allcoupons=Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]);var<SP>coupons=allcoupons.filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0});if(coupons.length>0){window.alert("clipping<SP>"+coupons.length+"<SP>of<SP>"+allcoupons.length+"<SP>coupons");coupons.forEach(function(item){var<SP>data={"items":[]},clip={},list={};clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm;data.items.push(clip);data.items.push(list);var<SP>request=new<SP>Request(window.AB.couponClipPath+"?storeId\x3d"+window.AB.userInfo.j4u.storeId,{method:'POST',mode:'cors',redirect:'error',headers:new<SP>Headers(window.AB.j4uHttpOptions),body:JSON.stringify(data)});var<SP>promise=fetch(request).then(function(response){return<SP>response.json()}).then(function(itemjson){if(itemjson.items[0]["status"]===1){var<SP>wtf=JSON.parse(localStorage.getItem("abJ4uCoupons"));if(wtf.objCoupons[item.offerId]&&wtf.objCoupons[item.offerId]["offerId"]===item.offerId){wtf.objCoupons[item.offerId].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}else{var<SP>index=wtf.objCoupons.findIndex(function(obj){return<SP>obj.offerId===item.offerId});if(index!==-1){wtf.objCoupons[index].status="C";localStorage.setItem("abJ4uCoupons",JSON.stringify(wtf))}}}});promises.push(promise)});Promise.all(promises).then(function(){if(Object.values(JSON.parse(localStorage.getItem("abJ4uCoupons"))["objCoupons"]).filter(function(x){return<SP>x.status==="U"}).filter(function(y){return<SP>y.deleted!==0}).length>0){window.alert("there<SP>are<SP>still<SP>some<SP>unclipped<SP>coupons<SP>-<SP>something<SP>probably<SP>broke<SP>this<SP>script")}else{window.alert("all<SP>coupons<SP>clipped<SP>-<SP>reloading<SP>page")}localStorage.removeItem("abCoupons");localStorage.removeItem("abJ4uCoupons");location.reload()})}else{if(allcoupons.length>0){window.alert("no<SP>clippable<SP>coupons")}else{window.alert("no<SP>coupons<SP>detected")}}})();

WAIT SECONDS=10
REFRESH
TAG POS=1 TYPE=SPAN ATTR=TXT:Account
TAG POS=1 TYPE=A ATTR=TXT:Sign<SP>Out
It just never goes beyond this step in iMacros (no error), sits indefinitely (blue highlighted on this step).

Note - I also tried prefixing with "var<sp>document=window.document;..." as indicated here: https://stackoverflow.com/questions/312 ... in-imacros
Note 2 - I used the "URL GOTO=javascript:YOURFUNCTIONNAMEHERE()" based on not understanding viewtopic.php?t=3645

"1. I'll try getting a supported config that was "known working" with FF 56 and iMacros for FF v8.9.7 and retest."
=> NO...! :shock: , not FF56...! :shock: , I said FF v55.0.3...!! :P , especially for the kind of Functionality that you want, completely broken in FF56... :(

And hum, about your 'URL GOTO=javascript:' Statement, hum..., your "JSON" is completely unknown to that "clean" JS Env. running in iMacros in your '.iim' Script I would think...

But hum, the 'URL GOTO=javascript:' is (usually) meant for "easy" JS Commands, yours is a bit long and complex, you might need to "review" all Single/Double Quotes in it that might need to been escaped, I see also some "\" Char(s), which happens to be the 'Escape' Char, so..., pffff..., you won't get it in 1-2-3 Tries to work, I'm afraid... :(
(But hum, OK, what you want is not really my "Field of Expertise", still waiting for "deeper" Insight/Feedback from @TechSup otherwise... :P )

And you may want to read my Comment in your Next Thread about "choosing" between pure JS Bookmarklet and iMacros... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
AgileHumor
Posts: 5
Joined: Wed Jul 01, 2020 3:35 am

Re: Calling a Javascript Bookmarklet from an IIM Script

Post by AgileHumor » Thu Jul 02, 2020 5:04 pm

I need I Macros to span multiple pages (and bookmarklet doesn't pass state between pages, at least to my knowledge) and login/logout using a few accounts from CSV file (loads coupons to my families Vons/Safeway grocery account). I'm assuming iMacros does that well. I don't maintain the Bookmarklet code, hence why it's external.

I tried FF 55.03 (I read your comment correctly when I was downloading) + iMacros legacy 8..., but Firefox 55 does not support localstorage functions in the Bookmarklet code, so went back to current version. It didn't work on the simple JS code below either.

I can't even get this much more moderate (but not simple) JS to work in FF 53 or current version:

1. Copy code below, and paste into make bookmarklet from here: https://mrcoles.com/bookmarklet/

Code: Select all

var sound=new AudioContext();
var play=sound.createOscillator();
play.connect(sound.destination);
play.start();
play.stop(sound.currentTime+1);
After converting to bookmarklet form, test by clicking "You can run your bookmarklet by clicking: this link" (should beep)

2. Then, I put this code into an IIM, it just sits there on that step (no error):

Code: Select all

URL GOTO=javascript:(function()%7Bvar%20sound%3Dnew%20AudioContext()%3Bvar%20play%3Dsound.createOscillator()%3Bplay.connect(sound.destination)%3Bplay.start()%3Bplay.stop(sound.currentTime%2B1)%7D)()
chivracq
Posts: 9374
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Calling a Javascript Bookmarklet from an IIM Script

Post by chivracq » Thu Jul 02, 2020 5:33 pm

AgileHumor wrote:
Thu Jul 02, 2020 5:04 pm
I need I Macros to span multiple pages (and bookmarklet doesn't pass state between pages, at least to my knowledge) and login/logout using a few accounts from CSV file (loads coupons to my families Vons/Safeway grocery account). I'm assuming iMacros does that well. I don't maintain the Bookmarklet code, hence why it's external.

I tried FF 55.03 (I read your comment correctly when I was downloading) + iMacros legacy 8..., but Firefox 55 does not support localstorage functions in the Bookmarklet code, so went back to current version. It didn't work on the simple JS code below either.

I can't even get this much more moderate (but not simple) JS to work in FF 53 or current version:

1. Copy code below, and paste into make bookmarklet from here: https://mrcoles.com/bookmarklet/

Code: Select all

var sound=new AudioContext();
var play=sound.createOscillator();
play.connect(sound.destination);
play.start();
play.stop(sound.currentTime+1);
After converting to bookmarklet form, test by clicking "You can run your bookmarklet by clicking: this link" (should beep)

2. Then, I put this code into an IIM, it just sits there on that step (no error):

Code: Select all

URL GOTO=javascript:(function()%7Bvar%20sound%3Dnew%20AudioContext()%3Bvar%20play%3Dsound.createOscillator()%3Bplay.connect(sound.destination)%3Bplay.start()%3Bplay.stop(sound.currentTime%2B1)%7D)()

About "... but Firefox 55 does not support localstorage functions in the Bookmarklet code, so went back to current version.", => iMacros for FF v8.9.7 also works on Pale Moon (v28) and Basilisk (v2020)..., which are more "modern" and up-to-date than FF55, maybe an Option for you as they will probably get a better Score on html5test.com... :idea:

And if using iMacros v8.9.7 for FF, you could then also use an (iMacros) '.js' Script (instead of an '.iim' Script), in which the Content of your Bookmarklet will probably work directly as-is from a simple Copy&Paste in the '.js' Script... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Tom, Tech Support
Posts: 3601
Joined: Mon May 31, 2010 4:59 pm

Re: Calling a Javascript Bookmarklet from an IIM Script

Post by Tom, Tech Support » Mon Jul 06, 2020 3:44 pm

AgileHumor wrote:
Thu Jul 02, 2020 5:04 pm
I need I Macros to span multiple pages (and bookmarklet doesn't pass state between pages, at least to my knowledge) and login/logout using a few accounts from CSV file (loads coupons to my families Vons/Safeway grocery account). I'm assuming iMacros does that well. I don't maintain the Bookmarklet code, hence why it's external.

I tried FF 55.03 (I read your comment correctly when I was downloading) + iMacros legacy 8..., but Firefox 55 does not support localstorage functions in the Bookmarklet code, so went back to current version. It didn't work on the simple JS code below either.

I can't even get this much more moderate (but not simple) JS to work in FF 53 or current version:

1. Copy code below, and paste into make bookmarklet from here: https://mrcoles.com/bookmarklet/

Code: Select all

var sound=new AudioContext();
var play=sound.createOscillator();
play.connect(sound.destination);
play.start();
play.stop(sound.currentTime+1);
After converting to bookmarklet form, test by clicking "You can run your bookmarklet by clicking: this link" (should beep)

2. Then, I put this code into an IIM, it just sits there on that step (no error):

Code: Select all

URL GOTO=javascript:(function()%7Bvar%20sound%3Dnew%20AudioContext()%3Bvar%20play%3Dsound.createOscillator()%3Bplay.connect(sound.destination)%3Bplay.start()%3Bplay.stop(sound.currentTime%2B1)%7D)()

Hi AgileHumor,

Here is the syntax you need to use to make this work with iMacros for Firefox (v10 as well as legacy):

Code: Select all

URL GOTO=javascript:var<SP>sound=new<SP>AudioContext();var<SP>play=sound.createOscillator();play.connect(sound.destination);play.start();play.stop(sound.currentTime+1);
Regards,

Tom, iMacros Support
Post Reply