Extensions :  K-Meleon Web Browser Forum
All about K-Meleon extensions. 
Help with replacing default LMB action on links? With a macro
Posted by: Bziur
Date: April 14, 2015 07:35PM

Hello,

So I have this idea, that I'd like to replace default left click action for my browser when opening certain sites, to open external program, if the URL matches a regex.

I couldn't find anything on hooking an action up for the left click on links though.

Soo anyone knows anything?

Options: ReplyQuote
Re: Help with replacing default LMB action on links? With a macro
Posted by: siria
Date: April 14, 2015 08:04PM

Don't know a way to restrict shortcuts to links... but perhaps try anyway? If your macro has a condition for a $LinkURL, clicks should do nothing outside of links. Take a look at Edit>Configuration>Accels, there are examples for shortcuts. For left click just use "LButton". You can define it also in the macro file itself, but first I'd just test that way if a global leftclick-shortcut is any good at all.

Options: ReplyQuote
Re: Help with replacing default LMB action on links? With a macro
Posted by: Bziur
Date: April 14, 2015 08:08PM

I guess I could hook up to $OnOpenTab, and close the tab immidatiely if the regex is met, then do macro logic, as a workaround, but it's finnicky.

Options: ReplyQuote
Re: Help with replacing default LMB action on links? With a macro
Posted by: siria
Date: April 14, 2015 08:12PM

Am not sure if $OnOpenTab gets the URL already, because I tried that myself recently and didn't work - URL was empty :-/
Was on KM1.6, but not much hope that's different in newer KM.
What works in $OnLoad, but of course that happens only after loading the whole page already.



Edited 1 time(s). Last edit at 04/14/2015 08:14PM by siria.

Options: ReplyQuote
Re: Help with replacing default LMB action on links? With a macro
Posted by: Bziur
Date: April 14, 2015 09:31PM

OnOpenTab event is fired when the tab is created and youre still in the same tab, so it will always show previous $URL.

However hooking up to LButton seems to work, you can check if it is a link with
if($LinkURL) {...}
I need to find out how to revoke default action though. Because after hooking up to it, the default accelerator is overwritten.

Options: ReplyQuote
Re: Help with replacing default LMB action on links? With a macro
Posted by: JohnHell
Date: April 14, 2015 10:16PM

Just open($LinkURL)

In other words:

accel.cfg
LBUTTON = macros(openmyway)
openmyway{
if(index($LinkURL, whateverstringtocheck) != -1){
&usexmacrotodomywork;
open(whateveryouwant);
}
if(){ #another one
}
if(){ #another one
}
if(){ #another one
}
else{
open($LinkURL);
}
}

I have loads of macros like this but, instead for LBUTTON, I have for the context menu. I prefer to right click, choose my option and do the stuff of the macro or a combination of keys + LBUTTON. This way, left click is ever left click, without worries.

Actually, I never tested to hook LBUTTON, but nice to know it can be done. I wouldn't anyway.



Edited 1 time(s). Last edit at 04/14/2015 10:17PM by JohnHell.

Options: ReplyQuote
Re: Help with replacing default LMB action on links? With a macro
Posted by: Bziur
Date: April 14, 2015 11:02PM

open($LinkURL) kinda works, but only kinda. It doesn't trigger javascript events. I don't think it can be done with just macros, a plugin would have to be written.

Options: ReplyQuote
Re: Help with replacing default LMB action on links? With a macro
Posted by: JohnHell
Date: April 14, 2015 11:12PM

It doesn't mean that doesn't work with javascript. It happens this because Mozilla banned the "javascript:function();" type of URLs and when we use the K-meleon open macro function, is the same as input an URL in the address bar.

Mozilla left the "javascript:" URLs to be used only through bookmarklets.

It is not an issue with macros or K-meleon, but that decision made orphan the feature for K-meleon (and other gecko based browsers).

What you could try, after check is a Javascript URL, is to injectJS(thatfunction);. It will run, but you need javascript to be enabled or the script of the page won't run. Will run the injectJS, but not the call to the page function.

EDIT 2: Siria might known better what to do winking smiley



Edited 2 time(s). Last edit at 04/14/2015 11:15PM by JohnHell.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.